CAD Forum - Database of tips, tricks and utilities for AutoCAD, Inventor and other Autodesk products [www.cadforum.cz]
Czech English Deutsch
Login/Register:
 Visitors: 3404 
RSS tips RSS channel - CAD tips
RSS discussion RSS channel - CAD discussion

Discussion Discussion forum

HelpCAD discussion

CAD Forum - Homepage CAD discussion forum - ask any CAD-related questions here, share your CAD knowledge on AutoCAD, Inventor, Revit and other Autodesk software with your peers from all over the world. To start a new topic, choose an appropriate forum.

Please abide by the rules of this forum.

How to post questions: register or login, go to the specific forum and click the NEW TOPIC button.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

The information that you provide in this form will make up your forum profile which can be viewed by other forum members. Your email address will only be visible by forum admin and moderators and will be used to send you Forum Notifications. To cancel your account, use the page Opt-out or contact webmaster@cadforum.cz.

Rename Layout tab to Attribute

 Post Reply Post Reply
Author
SLING4 View Drop Down
Newbie
Newbie


Joined: 19.May.2018
Location: Australia
Using: AutoCAD2016
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote SLING4 Quote  Post ReplyReply Direct Link To This Post Topic: Rename Layout tab to Attribute
    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)



Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

CAD Studio a.s.

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 1781
Post Options Post Options   Thanks (0) Thanks(0)   Quote Vladimir Michl Quote  Post ReplyReply Direct Link To This Post 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)
CAD Studio - www.cadstudio.cz - Autodesk reseller
Back to Top
SLING4 View Drop Down
Newbie
Newbie


Joined: 19.May.2018
Location: Australia
Using: AutoCAD2016
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote SLING4 Quote  Post ReplyReply Direct Link To This Post 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."
Back to Top
Vladimir Michl View Drop Down
Moderator Group
Moderator Group

CAD Studio a.s.

Joined: 26.Jul.2007
Location: Czech Republic
Using: Autodesk software
Status: Offline
Points: 1781
Post Options Post Options   Thanks (0) Thanks(0)   Quote Vladimir Michl Quote  Post ReplyReply Direct Link To This Post 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?
Vladimir Michl (moderator)
CAD Studio - www.cadstudio.cz - Autodesk reseller
Back to Top

Related CAD tips:


 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down



This page was generated in 0,094 seconds.