CAD Forum ► EN ► AutoCAD ► If and Condition station with blocks
Display full version of the post: If and Condition station with blocks
kameron1967
30.01.2011, 02:23
Hi guys,
I wonder if someone could help explain how I could do the followings:I'd like to create an if or condition statement with BLOCKSA, B and C and perform the followings to those blocks - ERASE, RENAME and MOVE to ORIGIN from insertion point of blockc.
IF:BLOCKA block exists, then DELETE BLOCKABLOCKB block exists, rename BLOCKB TO BLOCK2BLOCKC block exists, move BLOCKC from the insertionpoint of BLOCKC to the origin (0,0)
Thank you. I hope that is clear.
Something like this lisp routine (untested):
[code](princ "\nStart with B2B")
(defun c:b2b ()
(setvar "qaflags" 1)
(if (setq BASet (ssget "x" '((0 . "INSERT")(2 . "BLOCKA"))))
(command "._explode" BASet)
)
(if (ssget "x" '((0 . "INSERT")(2 . "BLOCKB")))
(command "._-rename" "_B" "BLOCKB" "BLOCK2")
)
(if (setq B2Set (ssget "x" '((0 . "INSERT")(2 . "BLOCKC"))))
(progn
(setq ename1 (ssname B2Set 0))
(setq InsPt (cdr (assoc 10 (entget ename1))))
(command "._move" ename1 "" InsPt '(0.0 0.0))
)
)
(setvar "QAFLAGS" 0)
(princ)
)[/code]
kameron1967
30.01.2011, 09:21
Thank you, CarlB. This is wonderful.
Unfortunately, the routine works only once and I'm wondering why it's giving me this error:
*Invalid selection*Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle/SUbobject/Object
ERROR: Function cancelled
Please help. Here is the modified code. All block names exist.
[code](princ "\nStart with B2B")(defun c:b2b () (setvar "qaflags" 1) (if (setq BASet (ssget "x" '((0 . "INSERT")(2 . "disclaimer2")))) (command "._erase" BASet) ) (if (ssget "x" '((0 . "INSERT")(2 . "zi3042sht"))) (command "._-rename" "_B" "zi3042sht" "abcde") ) (if (setq B2Set (ssget "x" '((0 . "INSERT")(2 . "i3042sht")))) (progn (setq ename1 (ssname B2Set 0)) (setq InsPt (cdr (assoc 10 (entget ename1)))) (command "._move" ename1 "" InsPt '(0.0 0.0)) ) )
(setvar "QAFLAGS" 0)
(if (setq B2Set (ssget "x" '((0 . "INSERT")(2 . "abcde")))) (progn (setq ename1 (ssname B2Set 0)) (setq InsPt (cdr (assoc 10 (entget ename1)))) (command "._move" ename1 "" InsPt '(25.0 25.0)) ) )
(princ))[code]kameron19672011-01-30 19:04:28
I assume the problem was with the "erase" command, ending the selection, try:
(command "._erase" BASet "")
kameron1967
31.01.2011, 01:29
Thanks. That looks promising. I'll let you know once I have a chance to test it. Thanks again, CarlB!