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

routine explode all blocks except one block

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
arunpdms
2264 Views, 16 Replies

routine explode all blocks except one block

Can you pls help the following

 

I want to explode all blocks except one block (for ex: -  block name “TTL”)

I have been tried like this way but its not working

 

(SSGET “_X” ((0 . “INSERT”) (-4 . “/=”) (2 . “TTL”)))

 

 

(i-e) select all block which name not equal to “TTL”

 

Regards,

arun

 

16 REPLIES 16
Message 2 of 17
Ajilal.Vijayan
in reply to: arunpdms

Quick select will do this.

Spoiler
Capture.JPG

 

Message 3 of 17
Gary_J_Orr
in reply to: arunpdms


@arunpdms wrote:

Can you pls help the following

 

I want to explode all blocks except one block (for ex: -  block name “TTL”)

I have been tried like this way but its not working

 

(SSGET “_X” ((0 . “INSERT”) (-4 . “/=”) (2 . “TTL”)))

 

 

(i-e) select all block which name not equal to “TTL”

 

Regards,

arun

 


(SSGET “_X” '((0 . “INSERT”) (-4 . “<NOT”) (2 . “TTL”) (-4 . “NOT>”) ))

 

Also notice the single quote ( ' ) at the beginning of the filter list to define the contents as a list.

But be aware, you are selecting all blocks in the database in every tab... if you are passing it to a command function this will be ok since the command will filter out objects not in the current space, but if you are doing the explode via other means then you could have unintended results...

 

whereas this will ensure that your selectionset only returns entities in your current layout tab (in this example I have replaced a direct quote of the list with the list function so I can pass in a variable):

(SSGET “_X” (list (0 . “INSERT”)  (410 . (getvar "ctab")) (-4 . “<NOT”) (2 . “TTL”) (-4 . “NOT>”) ))

-G

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 4 of 17
Kent1Cooper
in reply to: Gary_J_Orr


@Anonymous wrote:
.... 

whereas this will ensure that your selectionset only returns entities in your current layout tab ....:

(SSGET “_X” (list (0 . “INSERT”)  (410 . (getvar "ctab")) (-4 . “<NOT”) (2 . “TTL”) (-4 . “NOT>”) ))



I believe that needs to be:

 

(SSGET "_X" (list '(0 . "INSERT")  (cons 410 (getvar "ctab")) '(-4 . "<NOT") '(2 . "TTL") '(-4 . "NOT>") ))

Kent Cooper, AIA
Message 5 of 17
Gary_J_Orr
in reply to: Kent1Cooper

Thank you for the catch Kent... Guess I had not had enough coffee yet when I posted that 😉
I almost always use cons when building any filter list to keep my world dynamic but didn't include it here and, of course, forgot to quote all of the sublists... I simply wasn't paying enough attention to what I was doing... Thanks again for keeping me from passing bad advice since the OP has enough problems trying to learn without such...
-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 6 of 17
Kent1Cooper
in reply to: Gary_J_Orr


@Anonymous wrote:
Thank you for the catch Kent... ....

I have become sensitive to that little detail as a result of having made the same mistake myself several times.

The OP might also want to be aware of a peculiarity with Exploding using a (command) function.  Unless you take appropriate measures, it won't Explode a whole selection set at once, the way it will do all sorts of [maybe all?] other editing commands to a whole set together.  You need to either mess with the mysterious and undocumented QAFLAGS System Variable [do a Search] to allow it to do so, or step through the set and Explode each Block separately.  Either way, if they may exist in more than one drawing space [model space and/or possibly more than one paper-space layout], and you want to Explode them in all spaces, omitting the filtering with the 410 entry in the (ssget) filter, you will need to be in the space of each Block to Explode it/them with (command "_.explode" ...).  You can do that by stepping through and doing

 

(setvar 'ctab (cdr (assoc 410 GetTheBlockEntityDataList)))

 

for each before Exploding it.  There's probably also a (vl...) approach, too, that others will be able to describe right off but that I don't know well enough.

Kent Cooper, AIA
Message 7 of 17
Gary_J_Orr
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@Anonymous wrote:
Thank you for the catch Kent... ....

I have become sensitive to that little detail as a result of having made the same mistake myself several times.

The OP might also want to be aware of a peculiarity with Exploding using a (command) function.  Unless you take appropriate measures, it won't Explode a whole selection set at once, the way it will do all sorts of [maybe all?] other editing commands to a whole set together.  You need to either mess with the mysterious and undocumented QAFLAGS System Variable [do a Search] to allow it to do so, or step through the set and Explode each Block separately.  Either way, if they may exist in more than one drawing space [model space and/or possibly more than one paper-space layout], and you want to Explode them in all spaces, omitting the filtering with the 410 entry in the (ssget) filter, you will need to be in the space of each Block to Explode it/them with (command "_.explode" ...).  You can do that by stepping through and doing

 

(setvar 'ctab (cdr (assoc 410 GetTheBlockEntityDataList)))

 

for each before Exploding it.  There's probably also a (vl...) approach, too, that others will be able to describe right off but that I don't know well enough.


All good advice Kent. Although...

If you grab a selset without filtering for the current space it will return a sel set that may not have any "viable" entities in it (viable defined as within the current layout and passable to the command function), so, when stepping through the selset some command calls will fail... your suggestion to resolve that by switching to the space of the returned entity could end up with a lot of tab switching depending on the order of the return set...

 

If you truly want to perform a command (or some other function that is dependant on the entity being in the current space) on all entities on all tabs: It would be more efficient to switch to each tab, filter for entities on that tab, do the work, step to the next tab, repeat until no more tabs...

 

-G

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 8 of 17
Kent1Cooper
in reply to: Gary_J_Orr


Gary_J_Orr wrote
:.... your suggestion to resolve that by switching to the space of the returned entity could end up with a lot of tab switching depending on the order of the return set...

 

If you truly want to perform a command ... on all entities on all tabs: It would be more efficient to switch to each tab, filter for entities on that tab, do the work, step to the next tab, repeat until no more tabs...

....


Yes, although that approach has its own potential drawback, namely that it might have to work its way through a bunch of tabs that don't have any such Blocks in them.  I guess it depends on how many tabs there are, relative to how many are likely to contain things it needs to process, and how many such things there are likely to be.  If quantities of either or both objects and tabs are big enough, and if it takes a noticeably long time to make tab switches, it might be worth considering this, to avoid going into tabs it doesn't need to:  step through the selection and find the tab each object is in, making a list of just those tab names that do contain such objects, and then move in turn into each of those tabs only, and find and process the objects in each.  But that involves both an intial overall (ssget) and another in each tab, as well as the making of the list of tabs, so maybe not....

Kent Cooper, AIA
Message 9 of 17
Gary_J_Orr
in reply to: Kent1Cooper

Kent, as you noted, each, alone, has potential drawbacks... A large number of inserts in a drawing in multiple layout tabs, or a large number layouts potentially without any inserts...

Iterating an original selset of everything, then narrowing down the number of layouts to switch to has merit... one could create new selsets during the same loop that contain the entities within a given layout while it was creating the list of layouts that need to be activated and processed. your list could then be sub-lists, each containing the name of the tab and a pointer to the selset for that layout)...
-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 10 of 17
arunpdms
in reply to: Kent1Cooper

 

thanks for your response.

so how the routine need to be instead of this following code:

i am a learner.

 

(defun c:sdf()

 (SETQ fgh (SSGET "_X" (list '(0 . "INSERT")  (cons 410 (getvar "ctab")) '(-4 . "<NOT") '(2 . "TTL") '(-4 . "NOT>") ))    )     

 

   (Command "EXPLODE" fgh ) )

Message 11 of 17
Gary_J_Orr
in reply to: arunpdms


@arunpdms wrote:

 

thanks for your response.

so how the routine need to be instead of this following code:

i am a learner.

 

(defun c:sdf()

 (SETQ fgh (SSGET "_X" (list '(0 . "INSERT")  (cons 410 (getvar "ctab")) '(-4 . "<NOT") '(2 . "TTL") '(-4 . "NOT>") ))    )     

 

   (Command "EXPLODE" fgh ) )


something like this (and just keeping it simple and ignoring the discussion that we have fired off about process):

  (defun c:sdf()
    (if (SETQ fgh (SSGET "_X" (list
			    '(0 . "INSERT")
			    (cons 410 (getvar "ctab"))
			    '(-4 . "<NOT")
			    '(2 . "TTL")
			    '(-4 . "NOT>")
			    )))
      (progn
	(setq cntr 0)
	(while (< cntr (sslength fgh))
	  (command "_.Explode" (ssname fgh cntr))
	  ;catch the possibility of it being an xref or 
	  ;non explodable block which would leave the cmd active
	  (if (> (getvar "cmdactive") 0)
	    (command "")
	    );if not explodable
	  (setq cntr (1+ cntr))
	  );while
	);progn have selset True
      );If selset is created
    );defun

 -Gary

 

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 12 of 17
arunpdms
in reply to: Gary_J_Orr

dear gary,

 

Thanks a lot.

This works great.

 

 

 

 

Message 13 of 17
Gary_J_Orr
in reply to: arunpdms

No problem...
Remember: when it stops being fun you either need some help or a different job 😉

-G
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 14 of 17
hmsilva
in reply to: arunpdms

Just to share another way to filter the block name, and another way to use the Explode command with a selection set, without modifying the QAFLAGS SysVar

 

(defun c:sdf( / fgh)
  (if (setq fgh	(ssget "_X" (list '(0 . "INSERT") (cons 410 (getvar "ctab"))'(2 . "~TTL"))))
      (progn
	(initcommandversion)
	(command "_.explode" fgh "")
	)
    )
  (princ)
  )

 

Henrique

EESignature

Message 15 of 17
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

Just to share another way to filter the block name, and another way to use the Explode command with a selection set, without modifying the QAFLAGS SysVar

 

....
	(initcommandversion)
	(command "_.explode" fgh "")
....

Nice to know it's possible without dealing with QAFLAGS, but (initcommandversion) is a function that must have come along in a more recent version than the ol' 2004 I'm stuck with here [I have access to a newer one elsewhere].  So anyone with an old-enough version would be limited to the other approaches already discussed, unless there's yet another way with something like (vl-something-or-other...).

Kent Cooper, AIA
Message 16 of 17
Gary_J_Orr
in reply to: hmsilva

Even if you go the route of initcommandversion you should probably still guard against the dreaded "nothing selected" and a command awaiting completion just in case there is nothing in the selset that passes the command's filter (IE Inserts that can't be exploded or xrefs are the only returns)...
follow the command call with something like:
(if (> (getvar "cmdactive") 0)
(command "")
)
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)
Message 17 of 17
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:
Nice to know it's possible without dealing with QAFLAGS, but (initcommandversion) is a function that must have come along in a more recent version than the ol' 2004 I'm stuck with here [I have access to a newer one elsewhere].  So anyone with an old-enough version would be limited to the other approaches already discussed, unless there's yet another way with something like (vl-something-or-other...).

True, initcommandversion function start in AC2010...

And another way would be using vla-explode...

 

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