Author Topic: Insert block macro help needed.  (Read 2355 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Insert block macro help needed.
« on: April 27, 2005, 06:06:19 AM »
I need help with this macro for my in house menu.

I'm inserting a title sheet into a drawing based on which office, but I also need it to check wether it was previously loaded and replace it if it was.

This is what I have
Code: [Select]
[A0 Sheet]^C^C(SETQ ATT (GETVAR "ATTREQ"));ATTREQ;0;tilemode;0;-insert;"A0_SHEET=X:/Aids/Blocks/Rybka_Blocks/Inv_sheets/A0_SHEET";0,0;1;1;0;
But all this does is redefine the block, but then I have two sheets rather than one.

How do I check if it was previously loaded and then erase the old one if it is.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

StarGazer

  • Guest
Insert block macro help needed.
« Reply #1 on: April 29, 2005, 10:16:31 AM »
Hey Hudster,
 Not sure what you need, change the existing sheet or insert a new one? Do you have attributes in the sheet? If so the just redefine the block and the attributes stay as they are. If no attributes then just erase the old one and insert the new. I've found that is you erase a block and purge the definition in the drawing, your insert of the block will be the new one in your library directory.

Thomas

hudster

  • Gator
  • Posts: 2848
Insert block macro help needed.
« Reply #2 on: April 29, 2005, 10:36:31 AM »
I want it to check wether the sheet is there, if it is redefine the block, if it isn't then insert one.

The macro I'm using does redefine the block but then inserts a new one, so if the sheet is already there I get two.

I could erase the previous entity, but if it isn't it erases the sheet I wanted to insert.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

craigr

  • Guest
Insert block macro help needed.
« Reply #3 on: April 29, 2005, 02:15:43 PM »
Not sure if this helps, but....

I have a similar macro that I use to insert text / replace one if already there.

Here it is..

^C^C_osnap;off;zoom;11.85,1.775;16.025,-.3;_-insert;tmp;15.4,.15;;;;explode;L;erase;13.03,1.192;15.75,1.6;15.55,.2;15.25,.05;;_-PURGE;a;;n;-insert;asbuilt;13.35,1.25;;;;explode;L;

Basically all it does is insert a temporary 'tmp' block, then erase it and insert the NEW one.

This way the macro doesn't error out when you want to erase something that isn't there.

Hope this helps.

craigr

ronjonp

  • Needs a day job
  • Posts: 7533
Insert block macro help needed.
« Reply #4 on: April 29, 2005, 02:54:58 PM »
Are you using LT and can't use lisp?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
Insert block macro help needed.
« Reply #5 on: April 29, 2005, 04:05:32 PM »
no i'm using 2000 full edition
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

ronjonp

  • Needs a day job
  • Posts: 7533
Insert block macro help needed.
« Reply #6 on: April 29, 2005, 04:58:34 PM »
Try this: The titleblock has to be in your search paths.


Code: [Select]
(defun C:titleb (/ *error* u-attdia u-clayer u-cmdecho pt P)
;_____________________________
;Error function
;_____________________________

(defun *error* (msg)
   (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    ) ; if
(setvar 'attdia u-attdia)
(setvar 'clayer u-clayer)
(setvar 'cmdecho u-cmdecho)
    (princ)
  ) ;end error function

;_____________________________
;Get User Variables
;_____________________________


(setq u-cmdecho  (getvar 'cmdecho)
u-attdia  (getvar 'attdia)
u-clayer (getvar 'clayer)
)

;_____________________________
;Start Program
;_____________________________

(command ".undo" "begin")
(setvar 'tilemode 0)
(setvar 'cmdecho 0)
(setvar 'attdia 1)

(if (tblsearch "layer" "titleblock")
(command "-layer" "thaw" "titleblock" "on" "titleblock" "")
(princ "\n Layer 'titleblock' Created")
)
 
(initget 0 "A")
  (setq P (cond ((getkword
       "\nEnter Titleblock Size: (A)0,.....: <<Hit Enter for A0>>: "))
   ("A")
  )
)
(cond ((= P "A")
       (setq titleblock "A0_SHEET=A0_SHEET.dwg")
)
;((= P "x")
;       (setq titleblock "your other titleblocks")
;)
;((= P "x")
;       (setq titleblock "your other titleblocks")
)

(progn
  (setq pt (getpoint "\nSpecify insertion point or hit enter for [0,0,0]: "))
  (if (null pt) (setq pt '(0 0 0)))
(if (ssget "x"'((2 . "A0_SHEET")))
  (command ".-layer" "m" "titleblock" "" ".-INSERT" titleblock pt "1" "1" "0" ".erase" "last" "")
)

(if (not (ssget "x"'((2 . "A0_SHEET"))))
  (command ".-layer" "m" "titleblock" "" ".-INSERT" titleblock pt "1" "1" "0")
)
  (command ".zoom" "extents")
  (command ".undo" "end")
  (setvar "cmdecho" u-cmdecho)
  (setvar "attdia" u-attdia)
  (setvar "clayer" u-clayer)
  (princ)
)
(*error* "")
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hudster

  • Gator
  • Posts: 2848
Insert block macro help needed.
« Reply #7 on: April 30, 2005, 10:19:52 AM »
thanks man, I can change this to do what I want it to.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue