Lisp for disconnecting all structures from all pipes in one time

Lisp for disconnecting all structures from all pipes in one time

yu85.info
Collaborator Collaborator
439 Views
2 Replies
Message 1 of 3

Lisp for disconnecting all structures from all pipes in one time

yu85.info
Collaborator
Collaborator

Hi, I would be very grateful if anyone can help me with a lisp that disconnects all the structures from their pipes in one time in the drawing
I have this thing but it does not work

Thanks in advance
(defun c:DISCONNECTSTRUCTURES (/ ss i ent)
;; Try to select all pipe structure objects
(command "._SELECTSIMILAR" "SI" "ALL")
(setq ss (ssget "P" '((0 . "AeccDbPipeStructure"))))

(if ss
(progn
(setq i 0)
(repeat (sslength ss)
(setq ent (ssname ss i))
;; Use the Civil 3D command to disconnect the structure
(command "._AeccStructureDisconnect" ent "")
(setq i (1+ i))
)
(princ (strcat "\nDisconnected " (itoa (sslength ss)) " structures."))
)
(princ "\nNo pipe structures found in drawing.")
)
(princ)
)

0 Likes
Accepted solutions (1)
440 Views
2 Replies
Replies (2)
Message 2 of 3

Jeff_M
Consultant
Consultant
Accepted solution

@yu85.info here is a lisp that will do this. I did have it error with an "Access is denied" message, but running it again allowed it to complete. It was somehow finding a non-existent structure that had been erased. 

(defun c:DISCONNECTSTRUCTURES (/ ss sspipes i ent pipe pipes pipelist)
  (vl-load-com)
  ;; Try to select all pipe structure objects
  (setq ss (ssget "x" '((0 . "Aecc_Structure"))))
  (setq sspipes (ssget "x" '((0 . "Aecc_Pipe"))))
  (if (and ss sspipes)
    (progn
      (setq i 0)
      (repeat (sslength sspipes)
	(setq pipe (vlax-ename->vla-object (ssname sspipes i)))
	(setq
	  pipelist (cons (cons (vlax-get pipe 'name) pipe) pipelist)
	)
	(setq i (1+ i))
      )
      (setq i 0
	    counter 0)
      (repeat (sslength ss)
	(setq ent (vlax-ename->vla-object (ssname ss i)))
;;;	(setq strc ent)
;;;	(setq strcname (vlax-get ent 'name))
	(if (> (vlax-get ent 'connectedpipescount) 0)
	  (progn
	    (setq
	      pipes (str2list (vlax-get ent 'connectedpipenames) ",")
	      counter (1+ counter)
	      )
	    (foreach name pipes
	      (setq name (vl-string-left-trim " " name))
	      (vlax-invoke-method
		ent
		'disconnect
		(cdr (assoc name pipelist))
	      )
	    )
	  )
	)
	(setq i (1+ i))
      )
      (princ (strcat "\nDisconnected "
		     (itoa counter)
		     " structures."
	     )
      )
    )
    (princ "\nNo pipe structures found in drawing.")
  )
  (princ)
)
;;;str2list by John Uhden, as posted to the adesk customization newsgroup
(defun Str2List (str pat / i j n lst)
  (cond
    ((/= (type str)(type pat) 'STR))
    ((= str pat)'(""))
    (T
      (setq i 0 n (strlen pat))
      (while (setq j (vl-string-search pat str i))
        (setq lst (cons (substr str (1+ i)(- j i)) lst)
              i (+ j n)
        )
      )
      (reverse (cons (substr str (1+ i)) lst))
    )
  )
)

Edited to add str2list routine

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 3

yu85.info
Collaborator
Collaborator

Thank you very much!

Works great 

0 Likes