Copy, Rename, and Sort Layout Tabs in Order

Copy, Rename, and Sort Layout Tabs in Order

Anonymous
Not applicable
4,744 Views
10 Replies
Message 1 of 11

Copy, Rename, and Sort Layout Tabs in Order

Anonymous
Not applicable

I use the following code to copy, renumber (rename), and sort the tabs in the correct order. However, I'm looking to automate our operations even more by using a diesel expression in the layout to reference the first 3 characters of the drawing name (typically a number 100, 101, 102, etc...). When we open our drawings we have to rename the first layout in order to get the following code to work.

 

The steps the code takes to create the copies is critical for Sheet Set Manager. I'm just not versed enough to figure out the code for the tab order.Tab Order.jpg

 

(defun c:cnl  (/ a adoc curpos curtab i n)
 (and (= 0 (getvar 'tilemode))
      (setq i    (getint "\nEnter begining integer for suffix: ")
     curtab (substr (getvar 'ctab) 1 (- (strlen (getvar 'ctab)) 2))
     n    (getint "\nHow many copies of this tab: "))
      (repeat n
       (command "._layout" "_copy" "" (strcat curtab (if (= 1 (strlen (setq a (itoa i))))
    (strcat "0" a)
    a)))
       (setq i (1+ i))))
while
(setq ctr  (1+ (length (layoutlist)))
       adoc (vla-get-activedocument (vlax-get-acad-object))
       lst  (vl-sort (cdr (vlax-for i (setq lays (vla-get-layouts adoc)) (setq lst (cons (read (vla-get-name i)) lst)))) '>))
 (while lst
  (vla-put-taborder (vla-item lays (rtos (car lst) 2 2))
                    (setq lst (cdr lst)
                          ctr (1- ctr))))
)

 

Any help with this would be extremely appreciated!

0 Likes
Accepted solutions (1)
4,745 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

I've been pulling my hair out trying to get something to work. I'm definitely not as versed as I hoped I was becoming. I'm really hoping someone can help me out with this.

0 Likes
Message 3 of 11

ВeekeeCZ
Consultant
Consultant

I'm probably missing something - do you even need the sorting? 

 

(defun c:cnl  (/ a adoc curpos curtab i n)
  (and (= 0 (getvar 'tilemode))
       (setq i    (getint "\nEnter begining integer for suffix: ")
	     curtab (substr (getvar 'ctab) 1 (- (strlen (getvar 'ctab)) 2))
	     n    (getint "\nHow many copies of this tab: ")
	     i (+ i n)
	     )
       (repeat n
	 (command "._layout" "_copy" "" (strcat curtab (if (= 1 (strlen (setq a (itoa i))))
							 (strcat "0" a)
							 a)))
	 (setq i (1- i))))
)
0 Likes
Message 4 of 11

Anonymous
Not applicable

It's very close to working. A few things, when giving the suffix to start with, it renames starting after the suffix given (for example, a suffix of 01 skips 01 and makes the tab 02). The order in which it creates the layout really messes up Sheet Set Manager. Since Sheet Set Manager places them in the order the layouts are created, they have to be created in sequential order otherwise the sheet placements are all over the map.

 

I wish I could better understand what the code is saying, or what I would need to put in the code to make it do what I want. There's so much power with Lisp, but there's also a lot of "odd" terminology that I have a hard time understanding.

0 Likes
Message 5 of 11

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this.

 

(defun c:cnl  (/ num idx old bas new)
  
  (if (and (= 0 (getvar 'tilemode))  					; make sure some layout is current
           (setq num (getint "\nNumber of  copies of this tab: "))	
           (setq idx (getint "\nFirst suffix number: "))
           (setq old (getvar 'ctab))					; current name of layout
           (> (strlen old) 1)						; current name is longer the 1 character
           (setq bas (substr old 1 (- (strlen old) 2)))			; cut last 2 chars for current name to make base name
           )
    (repeat num								
      (setq str (itoa idx)						; make string of suffix integer
            str (if (= 1 (strlen str))					; if is only 1 digit long...
                  (strcat "0" str)					; ... add 0 before
                  str)
            new (strcat bas str))					; new name = base + string
      (if (member new (layoutlist))					; is the new name already used for layout?
        (princ (strcat "\nLayout '" new " ' already exists."))
        (command "._LAYOUT" "_Copy" old (strcat old ".")		; copy current tab, for new tab would be used dummy name (old + .) to make sure that new layout would be always right behing the old one
                 "._LAYOUT" "_Rename" (strcat old ".") new))		; rename dummy layout with real new name.
      (setq idx (1+ idx)						; add 1 to index
            old new)))							; set new name to old for next copy.
  (princ)
)

 

Message 6 of 11

Anonymous
Not applicable

Thanks a ton!

 

Oh, and thanks for the help text off to the side. That really helps a lot.

0 Likes
Message 7 of 11

Anonymous
Not applicable

How do I used the code mentioned above? Do I just copy all the text and paste it in the command line in AutoCAD?

0 Likes
Message 8 of 11

ВeekeeCZ
Consultant
Consultant

You can. But it a LISP so better copy-paste the code into an empty txt file and save as *.lsp. Then you can drag n drop the lst into your drawing. Run the command with a name that is stored behind 'c:' in the code.

More info of how to run lisp, possibly automatically, read HERE

0 Likes
Message 9 of 11

Anonymous
Not applicable

Thank you

0 Likes
Message 10 of 11

Anonymous
Not applicable

This looks like it could help me out. However, I am running a version of AutoCAD that doesn't allow LISP. Could this be done through a macro? I'm not good with macros, I've only created some basic ones.

0 Likes
Message 11 of 11

Sea-Haven
Mentor
Mentor

Are you running the oem version of Autocad and if so whose software are you running ? 

0 Likes