CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
Cesky English Deutsch
Login/Register:
 Visitors: 4333 

CAD tip CAD tip # 11780:

Question CAD 
 %  platform  category 
Q - question

How to rename layouts by a specific attribute of the title block?

A - answer With the following LISP reactor - RenameLOA - you can make the layout tab name match an attribute in the title block (frame). The RenameLOA.lsp freeware utility can be downloaded from www.cadstudio.cz/download.

Just set the two parameters - block- and attribute-name of your title block in the LISP file and load it with APPLOAD (drag to the briefcase icon) to every AutoCAD session. You can also optionally comment out the CommandEnded reactor and so check the attribute only on a layout switch. Use the LOAon and LOAoff commands to switch reactor(s) ON and OFF.

See example of the setting:

(setq _LOAblkname "TitleBlock") ; preset your title block name
(setq _LOAattname "LayoutName") ; preset your att. tag for the attribute
                                ; carrying the requested layout name

The layout is then automatically renamed to the current value of the specified attribute in the title block (if any) inserted in the respective layout.

See sample video:

Updated version on www.cadstudio.cz/download

Source code:

;Change layout name dynamically by attribute value
;V.Michl - www.cadstudio.cz - www.cadforum.cz

(setq _LOAblkname "TitleBlock") ; preset your title block name
(setq _LOAattname "LayoutName") ; preset your att. tag for the attribute carrying the requested layout name

(vl-load-com)

(setq _LOAdoc (vla-get-activedocument (vlax-get-acad-object)))

(defun _LOAgetAttVal (lname / ss blk property)
 (defun vl-getattributevalue ( blk tag )
    (setq tag (strcase tag))
    (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
        (vlax-invoke blk 'getattributes)
    )
 )
 (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 _LOAblkname)(cons 410 lname))))
 (if ss (setq blk (vlax-ename->vla-object (ssname ss 0))))
 (if blk (setq property (vl-getattributevalue blk _LOAattname)))
 property
)

(defun _LOAchangedLayout (reactor layout / actl lname aname)
 (setq lname (getvar "CTAB")); (car layout) ; act.layout
 (setq actl (vla-get-activelayout _LOAdoc)) ; vla-get-name
 (if (/= lname "Model")(progn
  (setq aname (_LOAgetAttVal lname)) ; get attribute
  (if (and aname (/= lname aname)) (progn (vla-put-name actl aname)(princ " * LOA renamed * "))) ; rename
 ))
)

(defun C:LOAoff ( )
 (if #LayoutSwitcher# (progn (vlr-remove #LayoutSwitcher#)(setq #LayoutSwitcher# nil)))
 (if #CommandEnded# (progn (vlr-remove #CommandEnded#)(setq #CommandEnded# nil)))
 (princ "\nNow OFF")
 (princ)
)
(defun C:LOAon ( )
 (if(not #LayoutSwitcher#) (setq #LayoutSwitcher# (VLR-Miscellaneous-Reactor nil '((:VLR-layoutSwitched . _LOAchangedLayout))))) ; on layout change
 (if(not #CommandEnded#) (setq #CommandEnded# (VLR-Command-Reactor nil '((:VLR-commandEnded . _LOAchangedLayout))))) ; also on any command
 (_LOAchangedLayout nil nil)
 (princ "\nNow ON")
 (princ)
)

(princ "\nLOA reactor loaded.")
(C:LOAon)
(princ)

Since June 2018, the reactor also supports dynamic blocks.

ACAD
100% *  CAD 
31.1.2018    1886×  
Comments   Tell a friend
applies to: AutoCAD ·

See also:
Tip 11821:How to publish PDF sheets (pages) under the plain layout name?
Tip 11542:How to reset the top browser node name back to the file name?
Tip 11171:Total number of layouts as a field.
Tip 10759:How to publish a DWG to a PDF file without attaching "-Model" to its name?
Tip 9870:Xref NAME has multiple references. Not detached.


Back   All CAD Tips All CAD tips&tricks

Invalid number or bad continuation - when creating a linetype. « | » Export XYZ coordinates of DWG objects from AutoCAD LT.

Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
Track your time spent working on AutoCAD or Revit jobs - automatically with
CADstudio JobTime More info


Please use these tips at your own risk.
CAD Studio (Xanadu) is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist