Print Page | Close Window

Rename Layout tab to Attribute

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=13266
Printed Date: 31.May.2026 at 20:36


Topic: Rename Layout tab to Attribute
Posted By: SLING4
Subject: Rename Layout tab to Attribute
Date Posted: 19.Aug.2019 at 02:31
Hi all
I'm new here.
I have a modified LISP routine from V.Mich (which I love).
It's working intermittently. I found that when I manually change the layout tab name to something random, then switch to model space and back to layout, the tab name updates. REGENALL also doesn't update the tab name.

I use 3 attributes for the naming. i.e. _LOAattname "REV"; _LOAprefix "PREFIX"; _LOAsuffix "SUFFIX"
This gives me a result e.g. [A]

I'll really appreciate any comments!

Routine:

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

(setq _LOAblkname "AA_TITLEBLOCK") ; preset your title block name
(setq _LOAattname "REV") ; preset your att. tag for the attribute carrying the requested layout name
(setq _LOAprefix "PREFIX") ; sets prefix
(setq _LOAsuffix "SUFFIX") ; sets suffix
(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)
    )
 ) ;----
 (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))
(setq blk en)
  )
)
  )
  blk
 ) ;----

 (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)))
(setq blk (ssdynblk _LOAblkname)) ; dynblocks, slow...
 )
; (if blk (setq property (vl-getattributevalue blk _LOAattname)))
 (if blk (setq property (strcat (vl-getattributevalue blk _LOAprefix) (vl-getattributevalue blk _LOAattname) (vl-getattributevalue blk _LOAsuffix)))) ; adds prefix & suffix
 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 "\nLOA reactor loaded.")
(C:LOAon)
(princ)






Replies:
Posted By: Vladimir Michl
Date Posted: 19.Aug.2019 at 06:34
Please make sure the block and attribute names in the routine match the names used in your title block.

And where is the problem? Your tab name updates? Its should update.


-------------
Vladimir Michl (moderator)
ARKANCE - https://arkance.world" rel="nofollow - https://arkance.world - Autodesk Platinum Partner


Posted By: SLING4
Date Posted: 26.Aug.2019 at 07:11
Thanks for the replay!
Block names are correct and it does work. Problem is that it doesn't always update the layout tab when I change the attribute.
When I open the file, it does update, but not while it's open.

As mentioned:
"It's working intermittently. I found that when I manually change the layout tab name to something random, then switch to model space and back to layout, the tab name updates. REGENALL also doesn't update the tab name."


Posted By: Vladimir Michl
Date Posted: 26.Aug.2019 at 07:44
So you are saying the switching back and forth does update the tab name - as it should. Where is the intermittency?
 
Does it behave like in the video?
https://www.cadforum.cz/cadforum_en/how-to-rename-layouts-by-a-specific-attribute-of-the-title-block-tip11780" rel="nofollow - https://www.cadforum.cz/cadforum_en/how-to-rename-layouts-by-a-specific-attribute-of-the-title-block-tip11780


-------------
Vladimir Michl (moderator)
ARKANCE - https://arkance.world" rel="nofollow - https://arkance.world - Autodesk Platinum Partner



Print Page | Close Window