batch add suffix to layout tabs

batch add suffix to layout tabs

sschaper392FD
Explorer Explorer
2,120 Views
6 Replies
Message 1 of 7

batch add suffix to layout tabs

sschaper392FD
Explorer
Explorer

I have never done lisp, so I hope this is possible

 

At my work the AutoCAD layout tabs are named with the item number. Then before it is sent to the client I need to add a date in parenthesis and a letter. An example would be... 3-512(10-20-17)P.  I was looking for a lisp or something that would batch add a suffix to the layout tab without opening each drawing. So with a drawing that already has the tab named with the item number I could add (10-20-17)P to each existing tab in several closed drawings and it would be ready to be sent without opening each one to edit the tab names. 

 

I currently use the batch attribute editor found here:

http://www.lee-mac.com/batte.html

to batch edit attributes without opening each file and was hoping for something that would work similar to add a suffix to the existing layout tabs without opening each drawing.

 

thanks in advance

0 Likes
Accepted solutions (1)
2,121 Views
6 Replies
Replies (6)
Message 2 of 7

devitg
Advisor
Advisor

please upload a few dwg , and the way it will be the las letter after the close parenthesis. 

0 Likes
Message 3 of 7

DannyNL
Advisor
Advisor

Unfortunately Layouts can only be renamed when the drawing is openen by the user in AutoCAD.

When opening a drawing with ODBX (like with Lee Mac's ObjectDBX Wrapper), the Layout objects are read-only as far as I can tell and thus it will not be possible to rename the layouts. So the only way to rename Layouts in drawings in batch is by using a script I'm afraid (or perhaps with .NET).

0 Likes
Message 4 of 7

sschaper392FD
Explorer
Explorer

So for a script.. As I go thru the commands: LAYOUT; RENAME....then it has the entire text of the tab shown and highlighted. I able to keep the item number but get to the end of the text to add the date and letter if I use the arrow key and then the end key (end key by itself does not work). How would that be shown in notepad? Thanks.

0 Likes
Message 5 of 7

DannyNL
Advisor
Advisor
Accepted solution

You cannot use commands in a script that require user input as that would halt the script.

So for renaming the layouts in a script with just a pre- and/or suffix, the easiest way would to use a LISP that does the work for you. See code below.

 

You can use the TEST command to run with user input on your current drawing.

 

(defun c:Test ()
   (if
      (and
         (setq T_Prefix (getstring T "\nPrefix: "))
         (setq T_Suffix (getstring T "\nSuffix: "))
         (or
            (/= T_Prefix "")
            (/= T_Suffix "")
         )
      )
      (PreSufLayouts T_Prefix T_Suffix)
   )
   (princ)
)

(defun PreSufLayouts (PSL_Prefix PSL_Suffix / PSL_Layouts PSL_ActiveDoc)
   (if     
      (and
         (= (type PSL_Prefix) 'STR)
         (= (type PSL_Suffix) 'STR)
         (or
            (/= PSL_Prefix "")
            (/= PSL_Suxfix "")
         )
      )
      (progn
         (vla-StartUndoMark (setq PSL_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
         (setq PSL_Layouts (vla-get-Layouts PSL_ActiveDoc))
         (vlax-for PSL_Item PSL_Layouts
            (if
               (/= (strcase (vla-get-Name PSL_Item)) "MODEL")
               (vla-put-Name PSL_Item (strcat PSL_Prefix (vla-get-Name PSL_Item) PSL_Suffix))
            )
         )
         (vla-EndUndoMark PSL_ActiveDoc)
         (mapcar 'vlax-release-object (list PSL_Layouts PSL_ActiveDoc))
      )
   )
)

 

For a script you need to use the syntax: (PreSufLayouts "" "\(10-20-17\)P")  <-- mind the \ before the ( and ) in the suffix string!

Be sure the LISP is loaded in each drawing before using the command by loading it after opening each drawing (like in the script example below) or by adding it to your StartUp suite in AutoCAD (or other automatically loaded LISP). But if you automatically load the LISP in each drawing, you need to remove the (load .....  lines in the script.

 

Create the script something like this:

 

open "C:\Folder\Drawing-001.dwg"
(load "C:\\Folder2\\YourFile.LSP")
(PreSufLayouts "" "\(10-20-17\)P")
.qsave
.close
open "C:\Folder\Drawing-002.dwg"
(load "C:\\Folder2\\YourFile.LSP")
(PreSufLayouts "" "\(10-20-17\)P")
.qsave
.close
....
....
....

 

0 Likes
Message 6 of 7

sschaper392FD
Explorer
Explorer

Thanks so much for your help! Got it working and it will be a time saver around here for sure!

0 Likes
Message 7 of 7

DannyNL
Advisor
Advisor

You're welcome & glad I could help Smiley Happy

0 Likes