layer name explode ?

layer name explode ?

jaimuthu
Advocate Advocate
561 Views
13 Replies
Message 1 of 14

layer name explode ?

jaimuthu
Advocate
Advocate

i have layer name floor1 its a closed polyline  i want i explode the layer name of "floor1" object

(defun c:ExplodeFloor1Layer ()
  (setq layerName "floor1")
  (setq ss (ssget "_X" (list (cons 8 layerName))))
  (setq objCount 0)
  
  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (ssname ss i))
        (command "EXPLODE" ent "")
        (setq objCount (1+ objCount))
        (setq i (1+ i))
      )
      (prompt (strcat "Exploded " (itoa objCount) " objects on layer '" layerName "'."))
    )
    (prompt (strcat "No objects found on layer '" layerName "'."))
  )
  (princ)
)
0 Likes
Accepted solutions (1)
562 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

And whats your question?

0 Likes
Message 3 of 14

jaimuthu
Advocate
Advocate

i want explode the object using layer name

0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

So it seems that you have a code that does so...

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant

If the issue is that something about the routine is not working as you expect, I have a likely cause.

 

The EXPLODE command works oddly when in an AutoLisp (command) function.  It will Explode only one thing.  If you give it a multiple-object selection set, only one thing in it will be Exploded.  And if you give it a single one, it does not require you to complete the selection, since it can't accept additional objects.  That means that you should not provide that "" at the end of the function, as you would for any other editing command involving object selection.

 

(command "EXPLODE" ent)

 

[There are other ways to get around that behavior, but this is easier.]

Kent Cooper, AIA
0 Likes
Message 6 of 14

stev98312
Enthusiast
Enthusiast

I found if I set QAFLAGS to 1, I can change all selected items. If QAFLAGS is 0, only one item is manipulated.

It's a poor example, but this changes all selected Leaders to the TEXT layer and explodes them(because changing drawing scale does not scale leaders):

 

(defun c:TTLX (/ ss1) 
  (setvar "QAFLAGS" 1)
  (if (setq ss1 (ssget)) 
    (progn 
      (command "_.chprop" ss1 "" "LAYER" "TEXT" "")
      (command "_.explode" ss1 "")
    )
    (setvar "QAFLAGS" 0)
  )
  (setvar "QAFLAGS" 0)
(princ)
)

 

 

Steve

 

 

 

0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant

@stev98312 wrote:

.... set QAFLAGS to 1....


That's one of the "other ways" I mentioned.  But if you use it, it's a good idea to build in *error* handling to ensure that it gets reset.  If something causes an error and it doesn't get reset, it can cause problems with other things.

Kent Cooper, AIA
0 Likes
Message 8 of 14

Sea-Haven
Mentor
Mentor

Maybe a manual way also,

LAYISO select an object on desired layer,

select objects or select all

Explode

Layuniso

 

I have the Layiso & layuniso toolbar displayed.

 

 

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

.... UnLayiso ....


[That's LAYUNISO.]

Kent Cooper, AIA
0 Likes
Message 10 of 14

komondormrex
Mentor
Mentor

using vla-explode

(defun c:ExplodeFloor1Layer ()
	(setq layerName "floor1")
	(setq ss (ssget "_X" (list (cons 8 layerName))))
	(setq objCount 0)
	(if ss
		(progn
		  	(setq i 0)
		  	(while (< i (sslength ss))
		  	  	(setq ent (ssname ss i))
;		  	  	(command "EXPLODE" ent "")
				(if (null (vl-catch-all-error-p (vl-catch-all-apply 'vla-explode (list (vlax-ename->vla-object ent)))))
					(progn
						(setq objCount (1+ objCount))
						(entdel ent) 
					)
				)
		  	  	(setq i (1+ i))
		  	)
		  	(prompt (strcat "Exploded " (itoa objCount) " objects on layer '" layerName "'."))
		)
		(prompt (strcat "No objects found on layer '" layerName "'."))
	)
	(princ)
)
0 Likes
Message 11 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

Just using the built-in command... with its default report.

 

(defun c:ExplodeFloor1Layer ( / s)

  (if (setq l "Floor1"
	    s (ssget "_X" (list (cons 8 l))))
    (progn
      (initcommandversion)
      (command "_.explode" s ""))
    (princ (strcat "\nError: No objects found on '" l "' layer.")))
  (princ)
  )
0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

Since the Layer name is actually part of the command name, it seems pointless to put it into a variable -- just use it directly.  And since you talk about Polylines specifically, restrict selection to those, and you can just report how many there were, instead of needing to use a counter variable and check each Explode for whether it worked [whether it was an Explodable object].

 

This uses the other "other way" I had in mind to get around the issue of EXPLODE in a command function, already suggested by @ВeekeeCZ :

 

(defun C:ExplodeFloor1Layer (/ ss)
  (if (setq ss (ssget "_X" '((0 . "*POLYLINE") (8 . "floor1"))))
    (progn ; then
      (initcommandversion)
      (command "_.explode" ss "")
      (prompt (strcat "Exploded " (itoa (sslength ss)) " Polylines on layer 'floor1'."))
    ); progn
    (prompt (strcat "No Polylines found on layer 'floor1'.")); else
  ); if
  (prin1)
)

 

Consider whether to force the Layer to be unlocked, within the routine.

 

Kent Cooper, AIA
0 Likes
Message 13 of 14

jaimuthu
Advocate
Advocate

thanks its work fine

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

Thanks Kent, corrected above.

 

A more global rather than 1 layer.

(setq lay (cdr (assoc 8 (entget (car (entsel "\nPlease select object for layer "))))))
(if (setq ss (ssget "_X" '((0 . "*POLYLINE") (cons 8 lay))))

 

0 Likes