Print Page | Close Window

If and Condition station with blocks

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DXF formats, Design Review, AutoCAD web, Drive, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=5218
Printed Date: 10.Jul.2026 at 21:27


Topic: If and Condition station with blocks
Posted By: kameron1967
Subject: If and Condition station with blocks
Date Posted: 30.Jan.2011 at 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 BLOCKA
BLOCKB block exists, rename BLOCKB TO BLOCK2
BLOCKC block exists, move BLOCKC from the insertionpoint of BLOCKC to the origin (0,0)

Thank you.  I hope that is clear. Smile




Replies:
Posted By: CarlB
Date Posted: 30.Jan.2011 at 09:04
Something like this lisp routine (untested):
 
(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)
)
          
     


Posted By: kameron1967
Date Posted: 30.Jan.2011 at 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/P
revious/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]


Posted By: CarlB
Date Posted: 31.Jan.2011 at 00:20
I assume the problem was with the "erase" command, ending the selection, try:
 
 (command "._erase" BASet "")


Posted By: kameron1967
Date Posted: 31.Jan.2011 at 01:29

Thanks.  That looks promising.  I'll let you know once I have a chance to test it.  Thanks again, CarlB!




Print Page | Close Window