CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 6287

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 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, or you can run the renaming process only on open/save (the 3rd reactor). 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 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.

Download the latest version from Download which includes also an optional onOpen/onSave reactor (instead of onAnyCommand).

ACAD
100% *  CAD 
31.1.2018    23157×  
Prices - CAD eShop:
applies to: AutoCAD ·

See also:
Tip 13468:How to change the drawing background color in AutoCAD Web? (black drawing)
Tip 13288:LayoutLF - automatic switching of group layer filters.
Tip 12837:RenameCSV - rename layers, blocks, layouts, views, linetypes using Excel tables
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?


Back   All CAD Tips



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:
Increase your productivity with our set of BIM add-on functions for Autodesk Revit
CADstudio Revit Tools More info


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist