HELP with a script to rename layout tabs

HELP with a script to rename layout tabs

tetenteten
Observer Observer
357 Views
3 Replies
Message 1 of 4

HELP with a script to rename layout tabs

tetenteten
Observer
Observer

I use Autocad LT every day for work and have created a template with a number of layouts with a standard title.

I would like to create a script that can rename the title of the layout tab so that I don't have to do this manually.

I have already had a script created by 'ChatGPT', but this does not work.

can anyone help me to create a script to rename the layout tabs?

this was the script:

(defun c:RenameLayouts ()

(vl-load-com) ; Load the Visual LISP functions

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ; Get the active document

(setq layouts (vla-get-Layouts doc)) ; Get the layout collection

(vlax-for layout layouts

(setq layoutName (vla-get-Name layout))

(cond

((= layoutName "L_V_XXXX")

(vla-put-Name layout "L_V_1111")) ; Rename 'L_V_XXXX' to 'L_V_1111'

((= layoutName "L_B_XXXX")

(vla-put-Name layout "L_B_1111")) ; Rename 'L_B_XXXX' to 'L_B_1111'

)

)

(princ) ; End function

)

thank you

0 Likes
Accepted solutions (1)
358 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor
Accepted solution

@tetenteten hi,

 

Check this corrected version.

 

enjoy

Moshe

 

 

(vl-load-com) ; Load the Visual LISP support

(defun c:RenameLayouts (/ doc layouts layout layoutName)
 (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ; Get the active document
 (setq layouts (vla-get-Layouts doc)) ; Get the layout collection

 (vlax-for layout layouts
  (setq layoutName (vla-get-Name layout))

  (cond
   ((= layoutName "L_V_XXXX")
    (vla-put-Name layout "L_V_1111") ; Rename 'L_V_XXXX' to 'L_V_1111'
   ); case
   ((= layoutName "L_B_XXXX")
    (vla-put-Name layout "L_B_1111") ; Rename 'L_B_XXXX' to 'L_B_1111'
   )
  ); cond
  (vlax-release-object layout)
 ); vlax-for


 (vlax-release-object layouts)
 (vlax-release-object doc)
  
 (princ) ; quiet exit
  
); c:RenameLayouts

 

 

 

Message 3 of 4

-didier-
Advisor
Advisor

Bonjour @tetenteten 

 

Usually I don’t give an answer referring to ChatGPT.
We are not here to solve the problems generated by AI.

We are humans who talk to humans.
I make an exception and I tested the code, and it works,
you say that it does not work, let’s admit!

 

What is the error message?
What version of LT do you use?

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 4 of 4

tetenteten
Observer
Observer

wauw, thanks @Moshe-A .

 

this works really great.

thank you very much

0 Likes