LISP/SCRIPT in copying multiple LAYOUT

LISP/SCRIPT in copying multiple LAYOUT

Anonymous
Not applicable
8,951 Views
28 Replies
Message 1 of 29

LISP/SCRIPT in copying multiple LAYOUT

Anonymous
Not applicable

Hi guys,

I need help on creating a LISP or an SCRIPT that will copy multiple existing LAYOUT.

Example:
- Existing layout name " Sheet 1"
- Execute a LISP/SCRIPT, let say "CMLayout"
- Will ask for the existing layout name to be copied or NULL get default. Let say "Sheet 1"
- Will ask for the number of times a layout to be copied. Let say "100"
- The LISP or SCRIPT will then copy the existing layout in a sequence.

 

Let say: Sheet 1, Sheet 2, Sheet 3, Sheet 4, Sheet 5, so on and so forth.

 

Appreciate any help on this matter.

 

Thank you,

0 Likes
Accepted solutions (2)
8,952 Views
28 Replies
Replies (28)
Message 2 of 29

ВeekeeCZ
Consultant
Consultant

Did you try google it? See the first one HERE...

0 Likes
Message 3 of 29

Anonymous
Not applicable

Actually, YES!

 

I did saw that and tried it. But, it does not create what I wanted and also it is not in sequence. So, I wanted to find other solutions.

 

Sorry but, I am not really into programming and do not know how to edit it.

0 Likes
Message 4 of 29

ВeekeeCZ
Consultant
Consultant
Sorry, I must be missing something... Is the naming the issue?
0 Likes
Message 5 of 29

Anonymous
Not applicable

That LISP or script, what it creates is example.

 

Layout 1, the next that will be created are "" Let say you want 100 copies"

 

Layout 1, Layout 1 (100), Layout 1 (99), Layout 1 (98) so on so forth...

 

What I was looking is

 

Layout 1, Layout 2, Layout 3.....

0 Likes
Message 6 of 29

ВeekeeCZ
Consultant
Consultant
Accepted solution

Maybe you should stop fill up the sentences with "let say" so much... We are usually focus on the technical side of issue - create multiple copies.. so if your main issue is correct naming, you should point that out 🙂 But maybe is just me and my language lacks...

 

Anyway, try this.

 

(defun c:CMLayout ( / *error* oCMDECHO ctab name namer namei nname n i x )
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO oCMDECHO)
    (princ))
  
  (setq oCMDECHO (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)

  ; --------------------------------------------------------------------------------------
  
  (setq ctab (getvar "ctab"))
  (setq name (getstring (strcat "\nLayout to duplicate <" ctab ">: ")))
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  
  (while (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#")
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)
  (setq n (getint "\nHow many copies: ")
        i (+ 1 namei n))
  
  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (setvar 'CMDECHO oCMDECHO)
  (princ)
)

PS. You might want change the CMDECHO system variable back to 1, because that previous program changed that to 0.

Message 7 of 29

braudpat
Mentor
Mentor

 

Hello Mr BeekeeCZ

 

Thanks, I appreciate your CMLayout routine !

 

Please what could be the Update if I would like something like:

Layout001, Layout002, ... Layout100, Layout101, etc ...

 

Regards, Patrice

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


0 Likes
Message 8 of 29

ВeekeeCZ
Consultant
Consultant

Sure, Patrice. Glad you like it.

Also added UNDO grouping. 

 

(vl-load-com)

(defun c:CMLayout ( / *error* oCMDECHO adoc :AddLeadingZeros ctab name namer namei nname n i x )
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO oCMDECHO)
    (vla-endundomark adoc)
    (princ))

  (defun :AddLeadingZeros (a d / b) ;add zeros to 'd' many digits  ;a string
    (strcat (substr "000000000" 1 (if (>= d (setq b (strlen (itoa (fix (atof a)))))) (- d b) 0)) a))

  ; --------------------------------------------------------------------------------------
  
  (setq oCMDECHO (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)

  (setq ctab (getvar "ctab"))
  (setq name (getstring (strcat "\nLayout to duplicate <" ctab ">: ")))
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  
  (while (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#")
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)
  (setq n (getint "\nHow many copies: ")
        i (+ 1 namei n))

  (vla-endundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  (vla-startundomark adoc)
  
  (repeat n
    (setq nname (strcat namer (:AddLeadingZeros (itoa (setq i (1- i))) 3)))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (*error* "end")
)
Message 9 of 29

Anonymous
Not applicable

I'm sorry if that annoy's you. That is just how politely I talk/write and also to be easily understood.

 

Anyway, I really do appreciate your time and effort exerted on my weakness. Kudos to you.

 

0 Likes
Message 10 of 29

Anonymous
Not applicable

Hi BeeKeeCZ,

 

I did tried running your LISP "CMLayout". But, there is an error;

 

"Error: bad argument value: positive 0bad argument type: VLA-OBJECT nil"

 

How do I correct this?

0 Likes
Message 11 of 29

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

"Error: bad argument value: positive 0bad argument type: VLA-OBJECT nil"

 

....

That happens if you start the command when in Model Space and  accept "Model" as the offered default current tab to make copies of.  You can't make copies of Model Space.  Either be sure you're in a Paper  Space Layout first, or if you're in Model Space, type in the name  of a Paper Space Layout to make copies of.

Kent Cooper, AIA
0 Likes
Message 12 of 29

Anonymous
Not applicable

Hi Kent1Cooper,

 

 

 

0 Likes
Message 13 of 29

ВeekeeCZ
Consultant
Consultant
Accepted solution

I see, the algorithm was not bulletproof and you've change the initial conditions - it's not 'Sheet 1' but just '1'... but the fix is quite easy.

 

(defun c:CMLayout ( / *error* oCMDECHO ctab name namer namei nname n i x )
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO oCMDECHO)
    (princ))
  
  (setq oCMDECHO (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)

  ; --------------------------------------------------------------------------------------
  
  (setq ctab (getvar "ctab"))
  (setq name (getstring (strcat "\nLayout to duplicate <" ctab ">: ")))
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  
  (while (and (> n 1)
              (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#"))
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (initget 6)
  (setq n (getint "\nHow many copies: ")
        i (+ 1 namei n))
  
  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname)))

  (setvar 'CMDECHO oCMDECHO)
  (princ)
)
Message 14 of 29

Anonymous
Not applicable

Hi BeeKeeCZ,

 

Appreciate your expertise and quick assistance into this matter. 

0 Likes
Message 15 of 29

gaexcalibur
Enthusiast
Enthusiast
Would it be possible to have this copy a single layout, then on the new layout go into the viewport and -pan the view 72" I have been trying to alter this to do a single but I have had no luck so far. thank you,
0 Likes
Message 16 of 29

ВeekeeCZ
Consultant
Consultant

You're not saying a direction when to PAN.

 

Once you're in new layout just go to the model space

(command "_.MSPACE")

and pan from point '(0 0) to (polar '(0 0) angle 72")

(command "_.PAN" "_non" '(0 0) "_non" (polar '(0 0) 0. 0.72))

...sorry I have no idea how to correctly set 72 inches... but I'm sure you will.

0 Likes
Message 17 of 29

gaexcalibur
Enthusiast
Enthusiast

thanks that may help a lot, i can figure that out but how do i get the lisp to do a single sheet copy rather than asking for multiple?  i have tried a lot of things this morning and get nothing good back.  Please that has me stumped.

thank you again.

 

0 Likes
Message 18 of 29

ВeekeeCZ
Consultant
Consultant

@gaexcalibur wrote:

thanks that may help a lot, i can figure that out but how do i get the lisp to do a single sheet copy rather than asking for multiple? ...

 


 

It's asking for n by (getint). So if you just set n to 1, you should be good to go.

(setq n (getint "\nHow many copies: ")
        i (+ 1 namei n))

Replace with:

(setq n 1
      i (+ 1 namei n))

 

The solution looks too simple to get struggle with that... so you might rather start over and tell us the whole story of what your goal is...

0 Likes
Message 19 of 29

gaexcalibur
Enthusiast
Enthusiast

honestly that was most of it, my goal is to copy a layout, move to that layout.  go into model space and pan over -72" from 0,0.  I did try to get exactly what you just posted but kept getting syntax error I tried different combinations but could not get it to work right.  now it will get the layout, copy the layout i just need to figure out how to change to the new layout and i am golden, the pan works perfectly just on the wrong layout, keeps doing it on the first layout rather than the second, i think it is order of command so i am working on fixing it this morning.

0 Likes
Message 20 of 29

ВeekeeCZ
Consultant
Consultant

Try this. I guess that polar needs value in feet, so I converted it.

Not sure whether you still need to prompt of what layout you're about to duplicate... I yes, change that as I was before.

Changes in the code are blue in color.

 

(defun c:LayoutCP ( / *error* oCMDECHO ctab name namer namei nname n i x ) ; Layout Create and Pan
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'CMDECHO oCMDECHO)
    (princ))
  
  (setq oCMDECHO (getvar 'CMDECHO))
  (setvar 'CMDECHO 0)

  ; --------------------------------------------------------------------------------------
  
  (setq ctab (getvar "ctab"))
  (setq name
         ctab)
         ;(getstring (strcat "\nLayout to duplicate <" ctab ">: ")))
  (if (= name "") (setq name ctab))
  (setq n (1+ (strlen name))
        namei "")
  
  (while (and (> n 1)
              (wcmatch (setq x (substr name (setq n (1- n)) 1)) "#"))
    (setq namei (strcat x namei)))
  
  (setq namer (substr name 1 (- (strlen name) (strlen namei)))
        namei (atoi namei))
  
  (setq n 1
        i (+ 1 namei n))
  
  (repeat n
    (setq nname (strcat namer (itoa (setq i (1- i)))))
    (if (member nname (layoutlist))
      (princ (strcat "\nLayout '" nname " ' already exists."))
      (command "_.LAYOUT" "_Copy" name (strcat namer "a")
               "_.LAYOUT" "_Rename" (strcat namer "a") nname
               "_.MSPACE"
               "_.PAN" "_non" '(0 0) "_non" (polar '(0 0) 0. 6)
               )))

  (setvar 'CMDECHO oCMDECHO)
  (princ)
)