CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz] ARKANCE | CONTACT - CZ | SK | EN | DE
Over 1.096.000 registered users (EN+CZ). AutoCAD tips, Inventor tips, Revit tips. Try the new precise Engineering calculator and the updated Barcode generator. New AutoCAD 2026 commands and variables.
RSS channel - CAD tips RSS tips
RSS discussions

Discussion Discussion forum

?
CAD discussions, advices, exchange of experience

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.
This is a peer-to-peer forum. The forum doesn't replace the official direct technical support provided by ARKANCE for its customers.
How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Topic ClosedIf and Condition station with blocks

 Post Reply Post Reply
Author
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post Topic: If and Condition station with blocks
    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

Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post 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)
)
          
     
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post 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]


Edited by kameron1967 - 30.Jan.2011 at 19:04
Back to Top
CarlB View Drop Down
Senior Member
Senior Member


Joined: 16.Oct.2009
Location: United States
Status: Offline
Points: 321
Direct Link To This Post Posted: 31.Jan.2011 at 00:20
I assume the problem was with the "erase" command, ending the selection, try:
 
 (command "._erase" BASet "")
Back to Top
kameron1967 View Drop Down
Groupie
Groupie


Joined: 30.Jan.2011
Location: United States
Using: autocad 2018
Status: Offline
Points: 29
Direct Link To This Post 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!

Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,078 seconds.