Civil 3D Object Explode Lisp

Civil 3D Object Explode Lisp

c.bergthold
Advocate Advocate
2,424 Views
7 Replies
Message 1 of 8

Civil 3D Object Explode Lisp

c.bergthold
Advocate
Advocate

I have written a lisp to explode civil 3D objects in a drawing before saving it back to a previous version. Part of this lisp explodes the surfaces in the drawing twice to leave just polylines and turns the linetype generation on for the polylines.

How do I format an if statement so that if a surface does not existing in the drawing it will continue?

 

(setq ssSURFACE (ssget "X" '((0 . "AECC_TIN_SURFACE"))))
(command "explode" ssSURFACE "")
(COMMAND "EXPLODE" "P" "")
(COMMAND "PEDIT" "M" "P" "" "L" "ON" "")

 

Thanks,

Cory

Cory
0 Likes
Accepted solutions (1)
2,425 Views
7 Replies
Replies (7)
Message 2 of 8

Jeff_M
Consultant
Consultant

 

(if (ssget....)
  (progn
     (setvar 'qaflags 5)
     (command "explode" .....)
     (command "explode" ......)
     (setvar 'qaflags 0)
  )
)

 The reason for the Qaflags is explode will only work on the first selected object if there are more than 1 in the selection set, unless Qaflags has been set to something other than 0 (I've always used 5, but I think most any of the options work).

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 8

c.bergthold
Advocate
Advocate

Jeff,

I guess I am still not quite understanding, I still can not get the lisp to work with the if. This is my full lisp without the if statement.

 

(defun c:tnt()
(COMMAND "MODEL")
(SETVAR "CMDECHO" 0)
(COMMAND "LAYON")
(COMMAND "LAYTHW")
(COMMAND "UNLOCKPOINTS" "A")
(COMMAND "REGEN")
(setq ssSURFLABELS (ssget "X" '((0 . "AECC_SURFACE_CONTOUR_LABEL_GROUP"))))
(setq ssAEC (ssget "X" '((0 . "AECC_*"))))
(setq ssSURFACE (ssget "X" '((0 . "AECC_TIN_SURFACE"))))
(setvar "qaflags" 1)
(command "explode" ssSURFLABELS "")
(command "explode" ssSURFACE "")
(COMMAND "EXPLODE" "P" "")
(COMMAND "PEDIT" "M" "P" "" "L" "ON" "")
(command "explode" ssAEC "")
(setvar "qaflags" 0)
(COMMAND "-PURGE" "A" "" "N")
(COMMAND "-PURGE" "A" "" "N")
(COMMAND "-PURGE" "R" "" "N")
(COMMAND "AUDIT" "Y")
(COMMAND "CHANGE" "ALL" "" "P" "C" "BYLAYER" "")
(COMMAND "REGEN")
(SETVAR "CMDECHO" 1)
(setq ssPSURFBLK nil)
(setq ssSURFACE nil)
(setq ssSURFACELABELS nil)
(setq ssAEC nil)
(princ)
)
)

 

 

Thanks,

Cory

Cory
0 Likes
Message 4 of 8

Jeff_M
Consultant
Consultant
Accepted solution

This sort of works. If you have Civil objects in the drawing that rely on the surfaces, then they may be broken by exploding the surface. Corridors which auto-rebuild come to mind. Doesn't ExporttoAutocad work for you? Anyway, I think this accomplishes what you want. 

 

 

(defun c:tnt (/ POLYS SSAEC SSSURFACE SSSURFLABELS)
  (COMMAND "MODEL")
  (SETVAR "CMDECHO" 0)
  (command "-layer" "t" "*" "on" "*" "u" "*" "")
  (COMMAND "UNLOCKPOINTS" "A")
  (COMMAND "REGEN")
  (setvar "qaflags" 1)
  (if (setq ssSURFACE (ssget "X" '((0 . "AECC_TIN_SURFACE"))))
    (progn
      (if (setq	ssSURFLABELS
		 (ssget	"X"
			'((0 . "AECC_SURFACE_CONTOUR_LABEL_GROUP"))
		 )
	  )
	(command "explode" ssSURFLABELS "")
      )
      (command "explode" ssSURFACE "")
      (COMMAND "EXPLODE" "P" "")
      (if (setq polys (ssget "x" '((0 . "LWPOLYLINE"))))
	(COMMAND "PEDIT" "M" "P" "" "L" "ON" "" "")
      )
    )
  )
  (if (setq ssAEC (ssget "X" '((0 . "AECC_*"))))
    (command "explode" ssAEC "")
  )
  (setvar "qaflags" 0)
  (COMMAND "-PURGE" "A" "" "N")
  (COMMAND "-PURGE" "A" "" "N")
  (COMMAND "-PURGE" "R" "" "N")
  (COMMAND "AUDIT" "Y")
  (COMMAND "CHANGE" "ALL" "" "P" "C" "BYLAYER" "")
  (COMMAND "REGEN")
  (SETVAR "CMDECHO" 1)
  (princ)
)

 

 

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 5 of 8

c.bergthold
Advocate
Advocate

Jeff,

Thanks for that help that works great. Export to autocad works but I am trying to simplify the number of steps it takes to clean up and make our drawings look right when we need to save them back. I typically do not set corridors or surfaces to automatic rebuild so this shouldn't be to big of an issue. I have also added a toggle background color routine to this lisp to toggle the color to 255,255,255 so when exploded any background masks will mask correctly.

 

Thanks,

Cory

Cory
0 Likes
Message 6 of 8

Anonymous
Not applicable

Cbess,

 

Would you be able to post your complete Lisp routine? I would be very interested in something like that, especially the part where it toggles the background color 255,255,255. It takes a long time to change the background masks manually.

 

Thanks

0 Likes
Message 7 of 8

c.bergthold
Advocate
Advocate

Here's my lisp the toogle background color portion i got from someone else if could remember where i would give him credit.

 

Cory

 

;DRAWING CLEANUP AND CIVIL 3D EXPLODE
(vl-load-com)
(DEFUN c:TNT ()
(initget "Y N  _Yes No")
(setq option (getkword "\nYou are about to explode all Civil3D Objects. Do you want to Continue? (Yes/No): "))
(if (= option "Yes")
  (progn
 (COMMAND "MODEL")
  (setq tm (getvar "tilemode"))
  (setq pref (vla-get-display
        (vla-get-Preferences
                  (vlax-get-acad-object)
               )
      )
  )
  (if (zerop tm)
    (setq cur (vla-get-graphicswinlayoutbackgrndcolor pref))
    (setq cur (vla-get-graphicswinmodelbackgrndcolor pref))
  )
  (setq col (vlax-variant-value
       (vlax-variant-change-type
         cur
         vlax-vblong
       )
     )
  )
  (if (not (or (eq col 0) (eq col 16777215)))
    (setq col 0)
  )
  (cond ((zerop tm)
  (vla-put-graphicswinlayoutbackgrndcolor
      pref
      (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
  )
  (vla-put-layoutcrosshaircolor
      pref
      (vlax-make-variant col vlax-vblong)
  )
 )
 (t
  (vla-put-graphicswinmodelbackgrndcolor
      pref
      (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
  )
  (vla-put-modelcrosshaircolor
      pref
      (vlax-make-variant col vlax-vblong)
  )
 )
  )
  (vlax-release-object pref)
  (COMMAND "MODEL")
  (SETVAR "CMDECHO" 0)
  (command "-layer" "t" "*" "on" "*" "u" "*" "")
  (COMMAND "CLAYER" "X-POINTS")
  (COMMAND "UNLOCKPOINTS" "A")
  (COMMAND "REGEN")
  (setvar "qaflags" 1)
  (if (setq ssSURFACE (ssget "X" '((0 . "AECC_TIN_SURFACE"))))
    (progn
      (if (setq    ssSURFLABELS
         (ssget    "X"
            '((0 . "AECC_SURFACE_CONTOUR_LABEL_GROUP"))
         )
      )
    (command "explode" ssSURFLABELS "")
      )
      (command "explode" ssSURFACE "")
      (COMMAND "EXPLODE" "P" "")
      (if (setq polys (ssget "x" '((0 . "LWPOLYLINE"))))
    (COMMAND "PEDIT" "M" "P" "" "L" "ON" "" "")
      )
    )
  )
  (if (setq ssAEC (ssget "X" '((0 . "AECC_*"))))
    (command "explode" ssAEC "")
  )
  (setvar "qaflags" 0)
  (COMMAND "-PURGE" "A" "" "N")
  (COMMAND "-PURGE" "A" "" "N")
  (COMMAND "-PURGE" "R" "" "N")
  (COMMAND "AUDIT" "Y")
  (COMMAND "CHANGE" "ALL" "" "P" "C" "BYLAYER" "")
  (COMMAND "REGEN")
  (SETVAR "CMDECHO" 1)
  (setq tm (getvar "tilemode"))
  (setq pref (vla-get-display
        (vla-get-Preferences
                  (vlax-get-acad-object)
               )
      )
  )
  (if (zerop tm)
    (setq cur (vla-get-graphicswinlayoutbackgrndcolor pref))
    (setq cur (vla-get-graphicswinmodelbackgrndcolor pref))
  )
  (setq col (vlax-variant-value
       (vlax-variant-change-type
         cur
         vlax-vblong
       )
     )
  )
  (if (not (or (eq col 0) (eq col 16777215)))
    (setq col 0)
  )
  (cond ((zerop tm)
  (vla-put-graphicswinlayoutbackgrndcolor
      pref
      (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
  )
  (vla-put-layoutcrosshaircolor
      pref
      (vlax-make-variant col vlax-vblong)
  )
 )
 (t
  (vla-put-graphicswinmodelbackgrndcolor
      pref
      (vlax-make-variant (abs (- col 16777215)) vlax-vblong)
  )
  (vla-put-modelcrosshaircolor
      pref
      (vlax-make-variant col vlax-vblong)
  )
 )
  )
  (vlax-release-object pref)
  )
)
(Alert "\nAll Civil 3D objects have been exploded. Do not overwrite original drawing file!!!")
(PRINC)
)

Cory
0 Likes
Message 8 of 8

Anonymous
Not applicable

Thanks a lot. This is perfect!!!!

0 Likes