LISP to make the layout tab name match an attribute in the title frame

LISP to make the layout tab name match an attribute in the title frame

Anonymous
Not applicable
7,058 Views
20 Replies
Message 1 of 21

LISP to make the layout tab name match an attribute in the title frame

Anonymous
Not applicable

Afternoon All,

 

I was hoping someone could help. I am looking to get the layout tab to automatically match that of an attribute in the title block. I have the LISP (attached) and I have the website to show you how to do it (below) but I am looking to have this done automatically for the "Revision" attribute of our title block. Thanks to James Sturgess on http://cadtips.cadalyst.com/file-options/rename-layouts for this

 

This link shows exactly what I am looking to do (and works with the attached lisp so just looking to change that to be automatic and to read the "Revision" attribute rather than selecting https://autocadtips1.com/2012/02/16/autolisp-select-text-rename-layout-tab/

 

Is there anyway this can be done? Ideally, I would like the lisp to run this automatically so everytime I open a drawing, the layout name updates to match the revision attribute 

 

Please note the way I am looking for this to be done and not the common way of having a field in the title block to look at CTAB etc.

 

Thanks in advance

 

Brian

0 Likes
Accepted solutions (3)
7,059 Views
20 Replies
Replies (20)
Message 2 of 21

vmichl_cs
Enthusiast
Enthusiast

Try the following reactor:

 

;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)

(if(not #LayoutSwitcher#) (setq #LayoutSwitcher# (VLR-Miscellaneous-Reactor nil '((:VLR-layoutSwitched . _LOAchangedLayout)))))
(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 (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)) (vla-put-name actl aname)) ; rename
 ))
)
(princ "\nLOA reactor loaded.")(princ)

Message 3 of 21

vladimir_michl
Advisor
Advisor
Accepted solution

(posted the previous under a wrong user profile)

 

Here is a sample procedure - autorenaming the layouts:

 

LOA.gif

 

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 4 of 21

Anonymous
Not applicable

Vmichl

 

Thank you for your reply. This works great and has helped me out a lot. Thank you.

 

Is there any way that the update can happen without clicking on model / another tab and back to the layout? The reason I ask (and the reason for the lsp in the 1st place) is because I run a .csv and .lsp to update the attribute in our title blocks through a spreadsheet. If I can get the layout tab to update to match the attribute automatically (when the drawing is loaded up for example) then I can update the revisions through the spreadsheet, run the lsp to use the csv, then run the lsp you provided and then do a batch plot of several drawings at once. Ideally all without having any manual input in the drawings.

 

Maybe there is a separate lsp that could switch between paper to model back to paper and that lsp could run after the one you provided?

 

Sorry if that sounds abit complex. Its not meant to be but cant think of another way to write it.

 

Thanks in advance

Brian

0 Likes
Message 5 of 21

vladimir_michl
Advisor
Advisor

You can perform the update anytime you call the "changed layout" handler - either manually, or on DWG open (through ACADDOC.lSP), or on any other automatic reacor.

 

E.g.:

 

(_LOAchangedLayout (reactor (list (getvar "CTAB"))))

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 6 of 21

vladimir_michl
Advisor
Advisor
Accepted solution

The enhanced version of RenameLOA now tries to update the layout name on any AutoCAD command. See:

http://www.cadforum.cz/cadforum_en/how-to-rename-layouts-by-a-specific-attribute-of-the-title-block-...

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

Message 7 of 21

Anonymous
Not applicable

Thank you for all your help

0 Likes
Message 8 of 21

jorge831
Explorer
Explorer

I have a question for you.

 

In my company, the title block is a dynamic block, so anytime a parameter is changed, the block becomes anonymous. This renders your LISP file unusable. So when presetting the "LOAblkname", I get a null response.

 

Do you have a work around or other solution?

0 Likes
Message 9 of 21

vladimir_michl
Advisor
Advisor

You are right. Processing dynamic blocks can be potentially slower but it works now also for dynamic blocks. See updated version of RenameLOA on www.cadstudio.cz/freeware

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 10 of 21

Engeny_Civil
Contributor
Contributor

Hi Vladimir,

 

I appreciate your work on this LISP, it has saved us many hours.

If we wanted the Lisp to only work when a Drawing is opened and saved which line would change?

I assume it's this one

(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

 

However my LISP knowledge is limited and I'm unsure how to change those lines correctly.

 

Thank-you

0 Likes
Message 11 of 21

vladimir_michl
Advisor
Advisor

Hi, acting "onOpen" and "onSave" would require a different approach. The existing reactors do process the current layout only (handling any potential changes immediately), while open/save would require to browse and update all layouts in one go.

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 12 of 21

Engeny_Civil
Contributor
Contributor

Multiple Layout Tab's wouldn't be an issue. We only have 1 Layout Tab per a Autocad File.

It's more so the reactor is only working when the file is open or saved.

 

Would it still be possible to change?

 

Thankyou

0 Likes
Message 13 of 21

vladimir_michl
Advisor
Advisor

This would be a too strict assumption, I prefer to have a more general routines - but it can be done. Please download the latest version of RenameLOA from www.cadstudio.cz/freeware - and uncomment (remove the leading semicolon) the requested reactors - onLayoutChange, onAnyCommand or just on OnOpen/onSave/onDxfOut.

 

Vladimir Michl, www.cadstudio.cz  www.cadforum.cz

 

0 Likes
Message 14 of 21

Engeny_Civil
Contributor
Contributor

Hi Vladimir,

 

Thank you for the updated lisp, it's functions really well. 

 

I've rolled it out to our team with minimal issues. One Designer mentioned when you try to select another object and drag it, it actually moves the attribute block instead. (This will occur in model or paperspace)

It's hard to pinpoint what might cause this, as when you click and drag objects in autocad it doesn't register a command. The command line does show "; error: no function definition: =OL" 

 

using "M" for move is fine and the lisp behaves as expected. However click and drag objects affects the main attribute block that the lisp is drawing from.

 

We've tried unloading other lisps and customization. Appears to be a isolated issue.

 

Thanks for your assistance

0 Likes
Message 15 of 21

vladimir_michl
Advisor
Advisor

The mention of "=OL" looks familiar. Please try to update the line with "=ol" to:

 

 

(if (and aname (/= lay aname)) (progn (vla-put-name actl aname)(if (= ol lay)(setq ol aname))(princ " * LOA renamed * "))) ; rename

but it works fine in both variants on my side.

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz 

 

0 Likes
Message 16 of 21

Anonymous
Not applicable

Thank you Vladimir,

 

Is there any way for this Lisp to read TWO attributes rather than one and place a dash between them? Ideally I would like the lisp to read and display the attributes "STATUS"-"REVISION" in the layout tab name.

 

Any help would be greatly appreciated. The Lisp works great with one attribute and updates great. This would just make life a little easier if its possible. 

 

If it is not possible through this Lisp, do you know of a way to create a new attribute (in the same titleframe block) that merges TWO attributes together and put a dash between them?

 

Thank you in advance. 

Regards

Brian

0 Likes
Message 17 of 21

vladimir_michl
Advisor
Advisor
Accepted solution

It should be quite easy - but it breaks the universal character of the tool, so just as an option to modify the tool for your preference.

Change the 'getattributevalue' line to (assuming "Revision" is the name of the secondary attribute):

 

(if blk (setq property (strcat (vl-getattributevalue blk _LOAattname) "-" (vl-getattributevalue blk "Revision"))))

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

Message 18 of 21

Anonymous
Not applicable

Works perfect. Thank you so much

 

Regards

Brian

0 Likes
Message 19 of 21

Engeny_Civil
Contributor
Contributor

Hi Vladimir,

 

Unfortunately the bug seems to persist.

 

I've attached a example drawing that contains some text and blocks. If you attempt click and drag the scale bar or the north arrow it will move the attribute block instead.

Also I've noticed when copying objects (Example the text in model space) it will flicker back to paperspace and then back to model.

 

Just to make sure I didnt break your lisp I've also attached the amended version.

 

Thank for all your help 🙂

0 Likes
Message 20 of 21

vladimir_michl
Advisor
Advisor

Hi, I have tested this in AutoCAD 2019 (with your version of the LISP, looks fine) and it behaves normally here, no co-dragging. Are there any other add-on tools running? Are you using a plain AutoCAD?

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

 

0 Likes