View Full Version : Creating a cleaner "fix block" routine?
Hey AutoLisp Gurus..
I wrote a routine to help someone go in to a bunch of drawings (block library) and fix them. We got these blocks from various places and are all in different stages of "cleanliness".
Some are nested blocks, some are blocks that "reference themselves" (blocks in a drawing with the same name), some have different colors assigned to entities other than ByLayer, and some have various insertion base points.
The result I'm looking for is to have them as "raw blocks" (some with attributes) with the insertion base point at 0,0,0. This one works pretty well, it askes you to select the basepoint and it does the rest. The only problem I'm having is if it's a nested block (more than one block deep) a block still remains when done. I added more "explode" functions, but some donuts and polylines with widths get exploded (which I don't want).
Here's what I have and I works pretty well, but I'm sure there's a better way (beyond my abilities).
;;;;fblock
(defun c:fb (/ pt1 pt2 ss oldvar1 oldvar2)
(command "tilemode" "1")
(command "zoom" "e" "zoom" ".9x")
(setq pt1 (getpoint "\nOk, Pick the base point!"))
(setq pt2 (list 0.0 0.0 0.0))
(setq ss (ssget))
(setvar "ucsicon" 1)
(setvar "insbase" (list 0.0 0.0 0.0))
(command "_move" ss "" pt1 pt2)
(setq oldvar1 (getvar "CMDECHO"))
(setq oldvar2 (getvar "OSMODE"))
(setvar "CMDECHO" 1)
(setvar "OSMODE" 63)
(command "explode" "all" "")
(command "change" "all" "" "properties" "layer" "0" "")
(command "change" "all" "" "properties" "color" "bylayer" "")
(setvar "CMDECHO" oldvar1)
(setvar "OSMODE" oldvar2)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x")
(command "purge" "a" "" "n")
(command "purge" "a" "" "n")
(command "_qsave")
)
(princ " FBLOCK loaded.")
(princ "\nCommand: FB - asks for insertion point")
(princ)
Any takers?
Thanks in advance.
T.Willey
2007-03-02, 09:53 PM
If you only want to explode blocks, then I would look with a selection set setup to only select blocks until it didn't find any blocks. Something like
(while (setq ss "x" '((0 . "INSERT")))
(command "_.explode" ss)
)
If you only want to explode blocks, then I would look with a selection set setup to only select blocks until it didn't find any blocks. Something like
(while (setq ss "x" '((0 . "INSERT")))
(command "_.explode" ss)
)
Thanks, I'll give it a whirl!
I may have questions, I'll keep you posted.
If you only want to explode blocks, then I would look with a selection set setup to only select blocks until it didn't find any blocks. Something like
(while (setq ss "x" '((0 . "INSERT")))
(command "_.explode" ss)
)
Hey T.Willey, thanks for the advice.
I can't seem to make this work. I'm a little shakey when it comes to "while" statements.
Can you look at what I have now and point me in the right direction?
This still kind of works but doesn't explode all the blocks. Probably something I did wrong, like something's missing or in the wrong place.
;;;;fblock
(defun c:fb (/ pt1 pt2 ss oldvar1 oldvar2)
(setq oldvar1 (getvar "CMDECHO"))
(setq oldvar2 (getvar "OSMODE"))
(setvar "CMDECHO" 1)
(setvar "OSMODE" 63)
(setvar "ucsicon" 1)
(setvar "insbase" (list 0.0 0.0 0.0))
(setq pt1 (getpoint "\nOk, Pick the base point!"))
(setq pt2 (list 0.0 0.0 0.0))
(setq ss (ssget))
(command "tilemode" "1")
(command "zoom" "e" "zoom" ".9x")
(command "_move" ss "" pt1 pt2)
(while (setq ss "x" '((0 . "INSERT")))
(command "_.explode" ss))
(command "change" "all" "" "properties" "layer" "0" "")
(command "change" "all" "" "properties" "color" "bylayer" "")
(setvar "CMDECHO" oldvar1)
(setvar "OSMODE" oldvar2)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x")
(command "purge" "a" "" "n")
(command "purge" "a" "" "n")
(command "_qsave")
)
(princ " FBLOCK loaded.")
(princ "\nCommand: FB - asks for insertion point")
(princ)
Thanks again, hope to hear from you soon.
Ted,
See if this, "RE: Explode in LISP Does Not Explode Selection Set", helps you on the exploding of objects in a selection set.
abdulhuck
2007-03-06, 07:53 PM
Oops! It's a typo error. He forgot to add ssget. Try this:
(while (setq ss (ssget "x" '((0 . "INSERT"))))
(command "_.explode" ss)
)
I would suggest
(repeat 2 (command "purge" "a" "" "n"))
instead of repeating the same line a number of times.
Regards
Abdul Huck
Oops! It's a typo error. He forgot to add ssget. Try this:
(while (setq ss (ssget "x" '((0 . "INSERT"))))
(command "_.explode" ss)
)
I would suggest
(repeat 2 (command "purge" "a" "" "n"))
instead of repeating the same line a number of times.
Regards
Abdul HuckOk, I'm getting close!
At least this one explodes all the blocks in the drawing, but it still is exploding other stuff, polylines, etc. I couldn't use your "while" statement as you posted, It didn't pompt me to "select objects". Unless I missed something (?) I added a "" after <"_.explode" ss> and that seemed to work.
;;;;fblock
(defun c:fb (/ pt1 pt2 ss oldvar1 oldvar2)
(setq oldvar1 (getvar "CMDECHO"))
(setq oldvar2 (getvar "OSMODE"))
(setvar "CMDECHO" 1)
(setvar "OSMODE" 63)
(setvar "tilemode" 1)
(setvar "ucsicon" 1)
(setvar "insbase" (list 0.0 0.0 0.0))
(setq pt1 (getpoint "\nOk, Pick the base point!"))
(setq pt2 (list 0.0 0.0 0.0))
(setq ss (ssget))
(command "zoom" "e" "zoom" ".9x")
(command "_move" ss "" pt1 pt2)
(while (ssget "x" '((0 . "INSERT")))
(command "_.explode" ss ""))
(command "change" "all" "" "properties" "layer" "0" "")
(command "change" "all" "" "properties" "color" "bylayer" "")
(setvar "CMDECHO" oldvar1)
(setvar "OSMODE" oldvar2)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x")
(repeat 2 (command "purge" "a" "" "n"))
(command "_qsave")
)
This second one only explodes the blocks and does nothing else.
I delved into the "qaflags" as suggested, but it didn't seem to help, so I abondoned it.
(defun c:fb (/ pt1 pt2 ss oldvar1 oldvar2 flag)
(setq oldvar1 (getvar "CMDECHO"))
(setq oldvar2 (getvar "OSMODE"))
(setvar "CMDECHO" 1)
(setvar "OSMODE" 63)
(setvar "ucsicon" 1)
(setq flag (getvar "qaflags"))
(setvar "insbase" (list 0.0 0.0 0.0))
(setq pt1 (getpoint "\nOk, Pick the base point!"))
(setq pt2 (list 0.0 0.0 0.0))
(setvar "qaflags" 5)
(while (setq ss (ssget "x" '((0 . "INSERT"))))
(command "_.explode" ss ""))
(command "zoom" "e" "zoom" ".9x")
(command "_move" ss "" pt1 pt2)
(command "change" "all" "" "properties" "layer" "0" "")
(command "change" "all" "" "properties" "color" "bylayer" "")
(setvar "CMDECHO" oldvar1)
(setvar "OSMODE" oldvar2)
(setvar "qaflags" flag)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x")
(repeat 2 (command "purge" "a" "" "n"))
(command "_qsave")
)
To recap, the top routine is working better (exploding all the blocks) but still exploding everything else.
I test it by bringing in all kinds of blocks and run it and it is exploding all of them.
Any more suggestions?
kennet.sjoberg
2007-03-08, 08:48 PM
. . . It didn't pompt me to "select objects". . .
It should not, the "x" in (ssget "x" '((0 . "INSERT"))) tell AutoCAD to select everything,
but in this case only (0 . "INSERT") equal to all blocks.
: ) Happy Computing !
kennet
It should not, the "x" in (ssget "x" '((0 . "INSERT"))) tell AutoCAD to select everything,
but in this case only (0 . "INSERT") equal to all blocks.
: ) Happy Computing !
kennetThanks Kennet,
But how can I select a bunch of entites (some are blocks and some are not) and move them all to my insertion point and explode only the blocks?
On the first routine I needed to add the "ssget" funtion seperately so I could select everything, but then it explodes everything.
The second routine, it just selected the blocks automatically (as you stated) and moved and exploded them, leaving other things where they were on and what layer they were on.
Any more ideas?
Thanks Kennet,
But how can I select a bunch of entites (some are blocks and some are not) and move them all to my insertion point and explode only the blocks?
On the first routine I needed to add the "ssget" funtion seperately so I could select everything, but then it explodes everything.
The second routine, it just selected the blocks automatically (as you stated) and moved and exploded them, leaving other things where they were on and what layer they were on.
Any more ideas?
Select everything so you can move them, then select only the blocks to explode. It will require at least two selection sets or you will need to remove everything that is not a block from the first selection set.
kennet.sjoberg
2007-03-08, 10:50 PM
. . .and objects that you explode, you will find in previous "P"
so you can move all blocks and objects (ssget "x" )
then explode only blocks (ssget "x" '((0 . "INSERT")))
then move those objects "P"
or all (ssget "x" )
or all minus "R" remove Previous exploded
(ssget "x" ) "R" "P"
: ) Happy Computing !
kennet
. . .and objects that you explode, you will find in previous "P"
so you can move all blocks and objects (ssget "x" )
then explode only blocks (ssget "x" '((0 . "INSERT")))
then move those objects "P"
or all (ssget "x" )
or all minus "R" remove Previous exploded
(ssget "x" ) "R" "P"
: ) Happy Computing !
kennetThanks Opie, Kennet and everyone else, I finally got it to work the way I wanted thanks to that last "nugget of information" from Kennet.
Here's the final code that does the trick:
;;;;fblock
(defun c:fb (/ pt1 pt2 ss oldvar1 oldvar2)
(setq oldvar1 (getvar "CMDECHO"))
(setq oldvar2 (getvar "OSMODE"))
(setvar "CMDECHO" 1)
(setvar "OSMODE" 63)
(setvar "ucsicon" 1)
(setvar "insbase" (list 0.0 0.0 0.0))
(setq pt1 (getpoint "\nOk, Pick the base point!"))
(setq pt2 (list 0.0 0.0 0.0))
(setq ss (ssget))
(command "_move" ss "" pt1 pt2)
(while (setq ss (ssget "x" '((0 . "INSERT"))))
(command "_.explode" "p"""))
(command "zoom" "e" "zoom" ".9x")
(command "change" "all" "" "properties" "layer" "0" "")
(command "change" "all" "" "properties" "color" "bylayer" "")
(setvar "CMDECHO" oldvar1)
(setvar "OSMODE" oldvar2)
(command "layer" "s" "0" "")
(command "zoom" "e" "zoom" ".9x")
(repeat 2 (command "purge" "a" "" "n"))
(command "_qsave")
)
(princ " FBLOCK_workloaded.")
(princ "\nCommand: FB - asks for insertion point")
(princ)
Thanks again everyone for your help.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.