Visual LISP, AutoLISP and General Customization

Reply
Mentor
smaher12
Posts: 173
Registered: ‎11-20-2011
Message 1 of 22 (352 Views)
Accepted Solution

Repeat Explode - Plines within blocks

352 Views, 21 Replies
02-22-2013 08:52 AM

I have multiple floor plans in a drawing one of which I need to explode 3-4 times to change the lineweight to 9mm. I have tried to put something that will repeat explode but I am having problems with plines within the blocks not exploding.

 

(defun c:tmp (ss)

  (setq ss (ssget))
  (setvar 'qaflags 1)
  (repeat 3 (vl-cmdf "._explode" ss ""))
  (setvar 'qaflags 0)
  (vl-cmdf "chprop" ss "" "lw" "0.09" "")

)

*Expert Elite*
Kent1Cooper
Posts: 5,243
Registered: ‎09-13-2004
Message 2 of 22 (348 Views)

Re: Repeat Explode - Plines within blocks

02-22-2013 09:24 AM in reply to: smaher12

smaher12 wrote:

I have multiple floor plans in a drawing one of which I need to explode 3-4 times to change the lineweight to 9mm. I have tried to put something that will repeat explode but I am having problems with plines within the blocks not exploding.

 

(defun c:tmp (ss)

  (setq ss (ssget))
  (setvar 'qaflags 1)
  (repeat 3 (vl-cmdf "._explode" ss ""))
  (setvar 'qaflags 0)
  (vl-cmdf "chprop" ss "" "lw" "0.09" "")

)


That's probably because after the first Explode, 'ss' is no longer there.  But since the results of an Explode get categorized as the Previous selection, you should be able to do something like this [untested]:

....

  (setvar 'qaflags 1)
  (vl-cmdf "._explode" ss "")

  (repeat 2 (vl-cmdf "._explode" "_p" ""))
  (setvar 'qaflags 0)

....

Kent Cooper
*Expert Elite*
hmsilva
Posts: 2,649
Registered: ‎12-17-2004
Message 3 of 22 (345 Views)

Re: Repeat Explode - Plines within blocks

02-22-2013 09:33 AM in reply to: smaher12

smaher12,
a different approach,

 

(defun c:test (/ ss old-echo item ss1 item1)
  (setq old-echo (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (foreach item (mapcar 'cadr (ssnamex ss))
      (vl-cmdf "Explode" item)
      (while
	(setq ss1 (ssget "_P" '((0 . "INSERT"))))
	 (foreach item1	(mapcar 'cadr (ssnamex ss1))
	   (vl-cmdf "Explode" item1)
	   (if (setq ss (ssget "_P" '((0 . "LWPOLYLINE"))))
	     (vl-cmdf "chprop" ss "" "lw" "0.09" "")
	   )
	 )
      )
    )
  )
  (setvar "CMDECHO" old-echo)
  (princ)
)

 

Hope that helps

Henrique

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 4 of 22 (318 Views)

Re: Repeat Explode - Plines within blocks

02-22-2013 10:35 PM in reply to: smaher12

smaher12 wrote:

I have multiple floor plans in a drawing one of which I need to explode 3-4 times to change the lineweight to 9mm. I have tried to put something that will repeat explode but I am having problems with plines within the blocks not exploding.

 


Problem with that approach is you may inaverdently "explode" other exploadable objects .e.g. Annotative objects, Mtext and such.

 

You may have to add a filter with "_P" 

(ssget "_P" '((0 . "INSERT,*LINE")))

 

(setq ss (ssget))
  (vl-cmdf "._explode" ss "")
	(while (setq ss (ssget "_P" '((0 . "INSERT,LWPOLYLINE"))))
 		(vl-cmdf "._explode" ss ""))

 

 

 

Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 5 of 22 (294 Views)

Re: Repeat Explode - Plines within blocks

02-24-2013 06:29 AM in reply to: smaher12

Please could you upload a sample dwg 2007 to 2013.?

 

Mentor
smaher12
Posts: 173
Registered: ‎11-20-2011
Message 6 of 22 (260 Views)

Re: Repeat Explode - Plines within blocks

02-25-2013 12:46 PM in reply to: smaher12

devitg,

Example drawing attached.

 

hmsilva,

For whatever reason your code crashes my AutoCAD.

 

Kent1Cooper & pbejse,

I have tried your suggestions with the following and now I am have some troubles with changing the lineweights to 0.09mm.

 

(defun c:test ()
  (vl-cmdf "LAYER" "F" "S-ANNO-TEXT" "")
  (setq ss (ssget))
  (setvar 'qaflags 1)
  (vl-cmdf "._explode" ss "")
  (vl-cmdf "CHPROP" "_p" "" "LW" "0.09" "")
	(while (setq ss (ssget "_P" '((0 . "INSERT,LWPOLYLINE"))))
 		(vl-cmdf "._explode" ss "")
                (vl-cmdf "CHPROP" SS "" "LW" "0.09" ""))
  (setvar 'qaflags 0)
  (vl-cmdf "LAYER" "T" "S-ANNO-TEXT" "")
)

 

*Expert Elite*
hmsilva
Posts: 2,649
Registered: ‎12-17-2004
Message 7 of 22 (250 Views)

Re: Repeat Explode - Plines within blocks

02-25-2013 01:35 PM in reply to: smaher12

smaher12
revised code

 

(defun c:test (/ ss old-echo item ss1 item1)
  (setq old-echo (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (progn
      (foreach item (mapcar 'cadr (ssnamex ss))
	(command "Explode" item)
	(while
	  (setq ss1 (ssget "_P" '((0 . "INSERT"))))
	   (foreach item1 (mapcar 'cadr (ssnamex ss1))
	     (command "Explode" item1)
	   )
	)
	(if (setq ss (ssget "_P" '((0 . "LWPOLYLINE"))));if all previus, remove list
	  (command "chprop" ss "" "lw" "0.09" "")
	)
      )
    )
  )
  (setvar "CMDECHO" old-echo)
  (princ)
)

 I understood that you only wanted to modify the "lw" in the lwpolylines, if you want to change all entities, just remove the last filter list

 

Henrique

Mentor
smaher12
Posts: 173
Registered: ‎11-20-2011
Message 8 of 22 (241 Views)

Re: Repeat Explode - Plines within blocks

02-25-2013 02:09 PM in reply to: hmsilva

I was thinking working like the following. Except I only want to select the plan one time, explode everything (mlines, plines, and blocks) until it's just lines and change all of it's lineweights to 0.09.

 

(defun c:test ()
  (vl-cmdf "layer" "F" "S-ANNO-TEXT" "")
  (setq ss (ssget))
  (setvar 'qaflags 1)
  (vl-cmdf "._explode" "ss" "")
	(while (setq ss (ssget "_P" '((0 . "INSERT,LWPOLYLINE"))))
 		(vl-cmdf "._explode" ss ""))
  (setvar 'qaflags 0)

  (setq ss1 (ssget))
  (vl-cmdf "chprop" ss1 "" "lw" "0.09" "")
  (vl-cmdf "layer" "T" "S-ANNO-TEXT" "")
)

 

*Expert Elite*
hmsilva
Posts: 2,649
Registered: ‎12-17-2004
Message 9 of 22 (238 Views)

Re: Repeat Explode - Plines within blocks

02-25-2013 02:14 PM in reply to: smaher12

 smaher12
sorry I responded too quickly, after seeing your code, I realized that you want to explode everything that is possible
and applying a lineweight of 0.09 to all objects.
I think this code does what you seek

 

(defun c:test (/ ss old-echo item ss1 item1 ss2)
  (setq old-echo (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (command "LAYER" "F" "S-ANNO-TEXT" "")
  (if (setq ss (ssget))
    (progn
      (command "chprop" ss "" "lw" "0.09" "")
      (if (setq ss1 (ssget "_P" '((0 . "INSERT,*POLYLINE,MLINE"))))
	(foreach item (mapcar 'cadr (ssnamex ss1))
	  (command "Explode" item)
	  (while
	    (setq ss2 (ssget "_P" '((0 . "INSERT,*POLYLINE;MLINE"))))
	     (foreach item1 (mapcar 'cadr (ssnamex ss2))
	       (command "Explode" item1)
	     )
	  )
	  (if (setq ss (ssget "_P"))
	    (command "chprop" ss "" "lw" "0.09" "")
	  )
	)
      )
    )
  )
  (command "LAYER" "T" "S-ANNO-TEXT" "")
  (setvar "CMDECHO" old-echo)
  (princ)
)

 

 

EDITED

added MLINE

all types of polylines *POLYLINES

 

Henrique

 

 

Mentor
devitg
Posts: 1,692
Registered: ‎03-14-2004
Message 10 of 22 (237 Views)

Re: Repeat Explode - Plines within blocks

02-25-2013 02:27 PM in reply to: smaher12

Please find attached the dwg , as I understand what do you want to do.

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community