Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Repeat Explode - Plines within blocks

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
smaher12
770 Views, 21 Replies

Repeat Explode - Plines within blocks

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" "")

)

21 REPLIES 21
Message 2 of 22
Kent1Cooper
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, AIA
Message 3 of 22
hmsilva
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

EESignature

Message 4 of 22
pbejse
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 ""))

 

 

 

Message 5 of 22
devitg
in reply to: smaher12

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

 

Message 6 of 22
smaher12
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" "")
)

 

Message 7 of 22
hmsilva
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

EESignature

Message 8 of 22
smaher12
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" "")
)

 

Message 9 of 22
hmsilva
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

 

 

EESignature

Message 10 of 22
devitg
in reply to: smaher12

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

 

Message 11 of 22
hmsilva
in reply to: smaher12

smaher12
there was a typo in my last code, *POLYLINE;MLINE, try this

 

(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)
)

 

Henrique

EESignature

Message 12 of 22
devitg
in reply to: devitg

 smaher12    , here is the lisp I use, with  your sample , I have nothing  to guess 

 

 

 

(defun c:change-lw-in-blk ()
(vl-load-com)
(setq blk-ss (ssget "x" '( ( 0 . "INSERT"))));_add filter as need 

(setq blk-obj-act-ss (vla-get-ActiveSelectionSet adoc))
(vlax-for  blk-obj   blk-obj-act-ss
   
(if (vlax-property-available-p blk-obj 'LINEWEIGHT t)
  (VLA-PUT-LINEWEIGHT blk-obj acLnWt009);_change weight as need 
  ) 
)
;|
acLnWtByLayer 
acLnWtByBlock 
acLnWtByLwDefault 
acLnWt000  
acLnWt005 
acLnWt009 
acLnWt013 
acLnWt015 
acLnWt018 
acLnWt020 
acLnWt025 
acLnWt030 
acLnWt035 
acLnWt040 
acLnWt050 
acLnWt053 
acLnWt060 
acLnWt070 
acLnWt080 
acLnWt090 
acLnWt100 
acLnWt106 
acLnWt120 
acLnWt140 
acLnWt158 
acLnWt200 
acLnWt211 
|;


);_ end main defun 

 

Message 13 of 22
hmsilva
in reply to: smaher12

smaher12,
tested with your dwg, and works as expected.

 

(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)
	  (if (setq ss (ssget "_P"))
	    (command "chprop" ss "" "lw" "0.09" "")
	  )
	  (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)
)

 Henrique

EESignature

Message 14 of 22
smaher12
in reply to: hmsilva

hmsila,

Fantastic! Thank you very much. I was playing around with your code last night. I only made a minor tweek and added a filter to the initial ssget. I found that the filter worked better than freezeing or locking the text layer with blocks that contained text. The only buggy thing I found was if you have a block that was created multiple blocks. Not really a problem for me as I only have one block that is created with multiple blocks. I will simply redefine the block.

 

Now that I have a little better understanding of how filters work. As I look at the filter, something is already telling me instead of listing ("INSERT,LINE,*POLYLINE,MLINE,SPLINE etc...) why not include everything and just exclude TEXT,MTEXT. Something like if not a member "text" "mtext". What do you think?

 

(defun c:test (/ ss old-echo item ss1 item1 ss2)
  (setq old-echo (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (if (setq ss (ssget '((0 . "INSERT,LINE,*POLYLINE,MLINE,SPLINE,ARC,CIRCLE"))))
    (progn
      (command "chprop" ss "" "lw" "0.09" "")
      (if (setq ss1 (ssget "_P" '((0 . "INSERT"))))
	(foreach item (mapcar 'cadr (ssnamex ss1))
	  (command "Explode" item)
	  (if (setq ss (ssget "_P"))
	    (command "chprop" ss "" "lw" "0.09" "")
	  )
	  (while
	    (setq ss2 (ssget "_P" '((0 . "INSERT"))))
	     (foreach item1 (mapcar 'cadr (ssnamex ss2))
	       (command "Explode" item1)
	     )
	  )
	  (if (setq ss (ssget "_P"))
	    (command "chprop" ss "" "lw" "0.09" "")
	  )
	)
      )
    )
  )
  (setvar "CMDECHO" old-echo)
  (princ)
)

 

 you think? 

Message 15 of 22
hmsilva
in reply to: smaher12

You're welcome, smaher12
glad you got a solution, to not select TEXT and MTEXT, change

 

(if (setq ss (ssget '((0 . "INSERT,LINE,*POLYLINE,MLINE,SPLINE,ARC,CIRCLE"))))

;; to

(if (setq ss (ssget '((0 . "~*TEXT"))))

 

Hope that helps, good luck

Henrique

EESignature

Message 16 of 22
smaher12
in reply to: hmsilva

Henrique, Perfect!

 

~ (bitwise NOT) I have to pick up and read my release 13 Customization Guide more often. The days when you recieved a book(s) with AutoCAD. 🙂 Thanks again!

Message 17 of 22
hmsilva
in reply to: smaher12

You're welcome, smaher12
Glad I could help    Smiley Wink

 

Henrique

EESignature

Message 18 of 22
smaher12
in reply to: hmsilva


@hmsilva wrote:

You're welcome, smaher12
Glad I could help    Smiley Wink

 

Henrique


Do you know how I can incorporate this in somehow?

      (if (setq ss3 (ssget "_P" '((8 . "S-FL-TILE"))))
        (command "erase" ss3 "")
      )

Message 19 of 22
hmsilva
in reply to: smaher12

smaher12 wrote:

Do you know how I can incorporate this in somehow?

...

 

incorporate into the above solution will be difficult, because using the command erase, we will lose part of the selection that does not belong to the S-FL-TILE layer, and we need to continuing to explode.

I have to think of a different approach...

 

Henrique

 

EESignature

Message 20 of 22
hmsilva
in reply to: smaher12

smaher12 wrote:

Do you know how I can incorporate this in somehow?

...

 

maybe something like

 

(defun c:test (/ ss old-echo item ss1 item1 ss2 ss3)
  (setq old-echo (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (if (setq ss (ssget '((0 . "~*TEXT"))))
    (progn
       (if (setq ss3 (ssget "_P" '((8 . "S-FL-TILE"))))
	 (progn
	   (command "select" ss "_r" ss3 "")
	   (setq ss nil)
	   (setq ss (ssget "_P"))
	   (command "erase" ss3 "")
	 )
       )
      (command "chprop" ss "" "lw" "0.09" "")
      (if (setq ss1 (ssget "_P" '((0 . "INSERT,*POLYLINE,MLINE"))))
	(foreach item (mapcar 'cadr (ssnamex ss1))
	  (command "Explode" item)
	  (if (setq ss (ssget "_P"))
	    (command "chprop" ss "" "lw" "0.09" "")
	  )
	  (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" "")
	  )
	)
      )
    )
  )
  (setvar "CMDECHO" old-echo)
  (princ)
)

 

I think that is what you want, try it, is minimally tested...

 

hope that helps

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost