Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy First Layout Multiple Times and Number Incrementally

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
koehler.drafting
6391 Views, 17 Replies

Copy First Layout Multiple Times and Number Incrementally

I found this routine and it is extremely close to what I am looking for (https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/automatic-number-of-layout-tabs/m-p/...), with a couple exceptions.

 

Our drawing template is set up with one default template (100.00 - this could be renamed to 101.00, 102.00, and so on depending on how many drawings we have for a particular job).  Our elevations us the suffix numbers 01-49; then the suffix for our sections start at 50. So we could end up having a drawing with layouts named 103.00, 103.01, 103.02, 103.03, 103.50, 103.51, 103.52, etc.

 

Typically when we open a new drawing we rename the first layout and then copy it however many times needed (i.e. 106.00, 106.00 (2), 106.00 (3), etc.) and then we go back and rename the layouts how we need them.

 

As mentioned the link for the code is very close to what I need. However, I would like to be able to have it copy the first layout tab, no matter what the name is. Then either enter in the desired prefix ("106." for example) or have it select the prefix based on the name of the first layout tab. And then finally enter the first suffix to be used (could be "01" or "50").

 

I have very little experience writing lisp routines so I'm not sure where I would alter the code to accomplish this. Any help would be greatly appreciated.

 

Thanks in advance.

17 REPLIES 17
Message 2 of 18

Try below code, it uses the existing layout name as prefix and adds a "." and then the number you specify and increments it. Make sure you run it while you are in the layout tab.

(defun c:somefunc  (/ adoc curpos curtab i n)
 (and (= 0 (getvar 'tilemode))
      (setq i	   (getint "\nEnter begining integer for suffix: ")
	    curtab (getvar 'ctab)
	    n	   (getint "\nHow many copies of this tab: "))
      (repeat n (command "._layout" "_copy" "" (strcat curtab "." (itoa (+ (1- n) i)))) (setq i (1- i)))))

 

Message 3 of 18

The code is very close to doing what I need. Is there a way to get it to number 01, 02, 03 ... 10, 11, 12? I need it to be a double integer suffix.

 

Also, I would like to keep the current tab ending with ".00" (i.e. 106.00). Can the string be trimmed to remove "00" and then start numbering with a double integer.

 

4-21-2017 11-11-01 AM.png

Message 4 of 18

Try below. This assumes you have a current layout with a format similar to 106.00

(defun c:somefunc  (/ 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 (+ (1- n) i)))))
			 (strcat "0" a)
			 a)))
       (setq i (1- i)))))
Message 5 of 18

With permission from Ranjit.Singh, what he did is fine.

 

Try this..

 

;;------------------------ C:Copy&Number_Layout ------------------------;;
;; José L. García G - 21/04/17                                          ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;

(defun c:CNL;|Copy&Number_Layout|;(/ curtab PrefixName i n NewNameLy
				     ;|functions|; ApplyZeros
				  )
	(defun ApplyZeros (StrInt NDigit)
	 (if (< (strlen StrInt) NDigit)
	  (repeat (- NDigit (strlen StrInt))(setq StrInt (strcat "0" StrInt)))
	 );c.if
	 StrInt
	)
 ;;-------------------------- MAIN ----------------------------------------
 (cond
  ((not (= 0 (getvar 'tilemode)))
   (prompt "\nNot in paper space..")
  )
  ((not (and (setq curtab (getvar 'ctab))
	     (not (initget (+ 2 4)))
	     (setq n (getint (strcat "\nHow many copies of this tab; (" curtab "): "))))))
  (T
   (if (wcmatch curtab "*.##")
    (setq i (substr curtab (1- (strlen curtab)))
	  PrefixName (vl-string-right-trim (strcat "." i) curtab)
	  i (1+ (atoi i)))
    (progn
     (initget (+ 2 4))
     (if (not (setq i (getint "\nEnter begining integer for suffix: ")))
      (setq i 1)
     )
     (setq PrefixName curtab)
    )
   );c.if
   (repeat n
    (setq NewNameLy (strcat PrefixName "." (ApplyZeros (itoa (+ (1- n) i)) 2)))
    (if (not (member (strcase NewNameLy) (mapcar 'strcase (layoutlist))))
     (vl-cmdf "._layout" "_copy" "" NewNameLy)
    )
    (setq i (1- i))
   );c.repeat
  )
 )
 (princ)
)

regards..

Message 6 of 18

Jose, thanks for the add on this thread. I compared both your routine and Ranjit's and the added versatility of being able to enter in a suffix was the reason I selected his as the answer. Our elevations we number starting with ".00" our sections we start with ".50".

 

Thank you both for your help. I hope to be able to write more complex codes like these in the future. Everyday I'm learning something new.

Message 7 of 18
scot-65
in reply to: koehler.drafting

Sounds like an interesting challenge.
Populate a list box inside a DCL with
the new tab names and OK...

Prefix name:

Suffix family name:

Suffix member count:

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 8 of 18
scot-65
in reply to: koehler.drafting

If you are interested...

About one hour of work to start.

 

testTAB01.jpg

 

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 18
htls69
in reply to: scot-65

@scot-65 when i try to load that lisp into my autocad i get error cant find dcl any solutions to fix it. and what is the command to start the lsp
Allen Robberson
Credit where credit is due! Give kudos or accept as solution whenever you can.
Message 10 of 18

Is there any way to get the layouts to copy in reverse order? When we create a new sheet set from drawing the layout tabs are out of order due to the routine creating the layouts from last to first instead of first to last.

Message 11 of 18

OK. Try now.

(defun c:somefunc  (/ 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)))))
Message 12 of 18

Ranjit,

 

Sorry to be a pain. It is creating them in the correct order, but they are now sorted in reverse order.

12-6-2017 7-20-32 AM.png

I don't know how much trouble it is to get it to create the tabs in the correct order (for SSM) and sort the tabs in the drawing in the correct order as well.

 

I really appreciate your help with all of this.

Message 13 of 18

If the previous routine as shown in Post# 4 worked for you and you simply want to reverse the order then try this to reverse the order (after creating the tabs with the routine in Post #4). Ignore Post #11.

Message 14 of 18

Ok, so I've tried going back to using Post #4 and the issue with sheet set manager still exists. Trying it with the routine from Post #11 creates them in the correct order for sheet set, but adds them in reverse order in the drawing. Running the routine from the link provided sorts them oddly (see images).

 

12-6-2017 5-08-50 PM.png12-6-2017 5-09-19 PM.png

 

As I've mentioned, I'm no expert - hardly a novice -  at writing/deciphering lisp, but is there a way to get them to sort in the drawing alphabetically/numerically? And if possible could that be tied into the routine from Post #11

Message 15 of 18

So post 11 gets the SSM thing resolved. And now we just need to fix the layout order?

(defun c:somefunc  (/ adoc ctr lays lst)
 (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)))))

I am assuming that all the layout tabs have a 'real' type name as you posted in the screenshots.

 

Message 16 of 18

Ok, so I'm trying to make everything fool proof for our drafters. The copy-number layout command works great. However, as we've been using it, there are a lot of times when my guys will forget to change the prefix, suddenly we have projects where all the drawings have 100. instead of 100, 101, 102... Our drawings are named with the same prefix (100-Kitchen 115, 101-Pantry 116, 102-Laundry 118, etc.). I've used a diesel expression to extract a substring of the drawing name that I've used in other fields. I thought about using the diesel expression in conjunction with the ctab field to populate the page name in the title block. What I was thinking about is changing the layout tabs to be named/numbered as 00, 01, 02, 03.... basically eliminating the prefix and allowing the diesel expression to populate the title block: 

 

$(substr,$(getvar,dwgname),1,3)"."$(getvar,ctab)

 

This works great... Until I use the copy-number layout lisp. By taking out the prefix, it will always list it with the newest tab created immediately after the original tab. For example, 00, 05, 04, 03, 02, 01 instead of 00, 01, 02, 03, 04, 05... As soon as I plug the prefix back into the layout name everything sorts correctly: 100.00, 100.01, 100.02....

 

Is there a way to continue to keep the tab creation so that Sheet Set Manager compiles them in the correct order, but have them list in the correct order without the prefix?

 

Again, the purpose is to eliminate the possibility of my drafters forgetting to change the prefix for the layout.

 

 

Message 17 of 18
eliasaJZKQY
in reply to: Ranjit_Singh2

Hello Ranjit,

can you please explain more how can I use the code: where to write it and how to run it.

thanks,

Message 18 of 18
symoin
in reply to: Ranjit_Singh2

Mr. Ranjith Singh,
Iam getting this error; please help.
; error: Automation Error. Key not found

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost