Batch layout rename

Batch layout rename

marymAGTL5
Advocate Advocate
663 Views
10 Replies
Message 1 of 11

Batch layout rename

marymAGTL5
Advocate
Advocate

Is there a way to rename ALL layout tabs in ALL the files that are open to be the name of the file? 

I found this post Rename Lisp  but it only does the layout tab in the file that you have open. 

I have 1 layout tab per file.  Any help is appreciated. 

0 Likes
Accepted solutions (1)
664 Views
10 Replies
Replies (10)
Message 2 of 11

paullimapa
Mentor
Mentor

You may also want to take a look at this thread on renaming layouts:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-routine-to-rename-and-delete-au...

 

I don't know of a method to rename layouts in all currently opened drawings. But you can always use something like Lee Mac's Script Writer to have the rename applied to all drawings in a given folder: http://www.lee-mac.com/scriptwriter.html

 

Also keep in mind that Windows OS file name acceptable characters are more than acceptable characters in AutoCAD's Layout names ie:

Windows OS file name characters limitations contain only the following:

paullimapa_0-1741381919946.png

But AutoCAD Layout name character restrictions contain more ("," ";" "=" "`"):

paullimapa_1-1741381957496.png

So as long as you're not currently using any of those characters in your drawing file name then the Layout rename can succeed.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 11

Sea-Haven
Mentor
Mentor

Will try to find some time and see if OBDX supports rename layouts. As you can get the list of dwg's open. 

 

(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq howmany (vlax-get acDocs 'count)) ; 1st dwg is 0
; the dwgs are as you see them in the dwg name list
(vlax-get (vla-item acdocs x) 'name)

SeaHaven_0-1741388899560.png

So if x=0 "TEST5"

0 Likes
Message 5 of 11

paullimapa
Mentor
Mentor

probably do something like this which you responded on deleting layouts in multiple drawings:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/delete-odbx-layout-delete-layout-of-...


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 11

daniel_cadext
Advisor
Advisor

If you can’t find a way in AutoLISP, you can try using python

https://github.com/CEXT-Dan/PyRx

 

import traceback
from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed


@Ap.Command("doit", Ap.CmdFlags.SESSION)
def rename_layouts():
    try:
        docman = Ap.DocManager()
        for doc in docman.documents():
            db = doc.database()
            docman.lockDocument(doc)
            token = Db.LayoutManager.setupForLayouts(db)
            try:
                lm = Db.HostApplicationServices().LayoutManager()
                for name in lm.getLayouts(db).keys():
                    if "Model".casefold() == name.casefold():
                        continue
                    lm.renameLayout(name, name + "-WOOHOO",db)
            finally:
                docman.unlockDocument(doc)
                Db.LayoutManager.clearSetupForLayouts(token)
    except Exception as err:
        traceback.print_exception(err)

 

 

 

 

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 7 of 11

daniel_cadext
Advisor
Advisor

if the drawing is closed, you can use readDwgFile, I.e.

 

import traceback
from pyrx_imp import Rx, Ge, Gi, Db, Ap, Ed

def rename_layouts_in_db(db: Db.Database):
    token = Db.LayoutManager.setupForLayouts(db)
    try:
        lm = Db.HostApplicationServices().LayoutManager()
        for name in lm.getLayouts(db).keys():
            if "Model".casefold() == name.casefold():
                continue
            lm.renameLayout(name, name + "-WOOHOO",db)
    finally:
        Db.LayoutManager.clearSetupForLayouts(token)


@Ap.Command("doit", Ap.CmdFlags.SESSION)
def rename_layouts():
    try:
        path = "E:\\06457Submittal.dwg"
        db = Db.Database(False, True)
        db.readDwgFile(path)
        db.closeInput(True)
        rename_layouts_in_db(db)
        db.saveAs(path)

    except Exception as err:
        traceback.print_exception(err)

 

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 8 of 11

Sea-Haven
Mentor
Mentor

I am testing a script method which seems to work involves 2 files a script and a lisp, the lisp does the rename bit. Needs amending as no idea what layout name is to be.

The script need to know for how many dwgs open, so will write each time ran. This is 3 dwgs open. Another lisp to make script, maybe a defun in renumlayouts.lsp, last line is (command "script" "renumlayouts.scr")

 

 

 

(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq howmany (vlax-get acDocs 'count))
(vla-activate (vla-item acdocs 0))
(load "renumlayouts")
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq howmany (vlax-get acDocs 'count))
(vla-activate (vla-item acdocs 1))
(load "renumlayouts")
(setq acDocs (vla-get-documents (vlax-get-acad-object)))
(setq howmany (vlax-get acDocs 'count))
(vla-activate (vla-item acdocs 2))
(load "renumlayouts")

 

 

 

The lisp

 

 

 

(defun renlays ( / laylst lays lay )
  (setq laylst '())
  (setq dname (cadr (fnsplitl (getvar 'dwgname ))))
  (setq lays (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))
  (vlax-for lay lays
  (setq laylst (cons (list (vla-get-taborder lay) (vla-get-name lay)) laylst))
)

(foreach lay laylst
  (if (= (car lay) 0)
   (princ)
   (command "layout" "R" (cadr lay) (strcat dname "D-" (rtos (car lay) 2 0)))
  )
)
(princ)
)
(renlays)

 

 

 

  Happy to finish it off adding write script if useful. Else copy past script to suit.

0 Likes
Message 9 of 11

baksconstructor
Advocate
Advocate

If you find it difficult to understand Lisp, you can use a ready-made solution.
Click the "Additional functions" button, then enter (insert) new tab names, click the Change button in all.

 

rename.PNG

0 Likes
Message 10 of 11

marymAGTL5
Advocate
Advocate

how do you get this image? it looks super helpful, not just for renaming layout tabs

0 Likes
Message 11 of 11

cadffm
Consultant
Consultant
Accepted solution

Hi 

 

look at the title: Revers <click>

Sebastian

0 Likes