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.092.000 registered users (EN+CZ). AutoCAD tips, Inventor tips, Revit tips. Try the new precise Engineering calculator. New AutoCAD 2026 commands and variables.

CAD tip CAD tip # 11780:

Question

CAD 
 %  platform  category 
A
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 by ARKANCE can be downloaded from DL 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 _LOAblknameList "TitleBlock*") ; preset your title block name
(setq _LOAattnameList "LayoutName,LName") ; 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 DL Download

Source code:

;RenameLOA - change layout name dynamically by attribute value
;9/2024, V.Michl - www.arkance.world - www.cadforum.cz

(setq _LOAblknameList "TitleBlock,AltBlock1,AllOther*") ; preset your title block name(s) - a list or wildcard ; mod 9/24
(setq _LOAattnameList "LayoutName,MyLayout") ; preset your att. tag for the attribute carrying the requested layout name - a list or wildcard ; mod 9/24

(vl-load-com)

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

(defun _LOAgetAttVal (lname / ss blk property props i) ; get attr value in layout 
 (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)
    )
 ) ;----
 (defun getAttValues ( blk )
    (setq blk (vlax-ename->vla-object blk))
    (mapcar '(lambda ( att ) (cons (vla-get-tagstring att) (vla-get-textstring att))) (vlax-invoke blk 'getattributes))
 ) ;----
 (defun ssdynblk (effname / ssx c en blk) ;--------- *U modified dynblk
  (setq ssx (ssget "_X" (list (cons 0 "INSERT")(cons 2 "`*U*")(cons 410 lname))))
  (setq	c 0)
  (if ssx
	(repeat	(sslength ssx)
	  (setq	en (vlax-ename->vla-object (ssname ssx c))  c (1+ c))
;	  (if (= (strcase (vla-get-effectivename en)) (strcase effname))
	  (if (wcmatch (strcase (vla-get-effectivename en)) (strcase effname)) ; mod 9/24
		(setq blk en)
	  )
	)
  )
  blk
 ) ;----

 (setq ss (ssget "_X" (list (cons 0 "INSERT")(cons 2 _LOAblknameList)(cons 410 lname)))) ; all titles in this layout
 (if (not ss)(progn (setq blk (ssdynblk _LOAblknameList))(if blk (ssadd blk ss)))) ; dynblock?
 ;(if ss
	;(setq blk (vlax-ename->vla-object (ssname ss 0)))
	;(setq blk (ssdynblk _LOAblknameList)) ; dynblocks, slow...
 ;)
 (if ss (repeat (setq i (sslength ss))
  (setq blk (ssname ss (setq i (1- i))))
  (setq props (getAttValues blk))
  (foreach a props
   (if (wcmatch (strcase (car a)) (strcase _LOAattnameList))(setq property (cdr a)))
  )
 ))
; (if blk (setq property (vl-getattributevalue blk _LOAattname)))
; (if blk (setq property (strcat (vl-getattributevalue blk _LOAattname) "-" (vl-getattributevalue blk "Revision") "/" (vl-getattributevalue blk "Drawing")))) ; triple atts, eg. NAME-REVISION/DRAWING
 property
)

(defun _LOAchangedLayout (reactor layout / actl lname aname) ; single layout
 (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 _LOAprocess (reactor layout / ol actl lname aname) ; all layouts
 (setq ol (getvar "CTAB")); (car layout) ; act.layout
 (foreach lay (layoutlist)
  (setvar "CTAB" lay)
  (setq actl (vla-get-activelayout _LOAdoc))
  (setq aname (_LOAgetAttVal lay)) ; get attribute
  (if (and aname (/= lay aname)) (progn (vla-put-name actl aname)(if (= ol lay)(setq ol aname))(princ " * LOA renamed * "))) ; rename
  (setvar "CTAB" ol)
 )
)

(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))))) ; and on any command (UNCOMMENT)
 ;(if(not #CommandEnded#) (setq #CommandEnded# (vlr-editor-reactor nil '((:vlr-endDwgOpen . _LOAprocess)(:vlr-beginSave . _LOAprocess)(:vlr-beginDxfOut . _LOAprocess))))) ; and on open/save (UNCOMMENT)
 (_LOAchangedLayout nil nil)
 (princ "\nNow ON")
 (princ)
)

(princ "\nARKANCE LOA reactor loaded.")
(C:LOAon)
(princ)

Since June 2018, the reactor also supports dynamic blocks. Since September 2024, you can specify the block name and attribute name by a list or wildcard.

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

ACAD
100% *CAD
31.1.2018    24857×  
Share the tip:
Digg it! Del.icio.us Facebook Twitter Google bookmark Technorati StumbleUpon
applies to: AutoCAD ·

See also:
Tip 14537:Automation of AutoCAD drawing texts using fields.
Tip 14481:How to bulk publish a folder of DWG/DXF files to PDF?
Tip 14446:Undocumented options in AutoCAD FIELDs - hyperlinks, hexadecimal or binary format
Tip 14361:Extended ATTOUT/ATTIN for block attribute management in Excel (also for LT).
Tip 14223:Arithmetic operations for renaming blocks, levels, layouts...


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
  



Featuring:
Save your floating licenses (NLS) consumed by inactive users - free unused licenses with
LogOff 2006 More info


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