rename/copy/switch to next layout tab lisp help

rename/copy/switch to next layout tab lisp help

dwattersAMXH5
Enthusiast Enthusiast
3,558 Views
5 Replies
Message 1 of 6

rename/copy/switch to next layout tab lisp help

dwattersAMXH5
Enthusiast
Enthusiast

hello, 

I am currently working on a lisp to automate three tasks 

1- rename current layout tab 
2- copy layout tab (to end)

3-switch to last layout tab 

 

here is where i am at so far - 

 

(DEFUN C:RRT2 ()

 (command "-layout" "rename" "" (getstring T "\nEnter new name for current layout")))
 (princ)

)

i know how to get the sheet to rename through the lisp, but the next part of 
1- adding in the next command :

(command "-layout" "copy" "" "") 

2- the set command (i know it should look something like this): 

(command "ctab" "(the last sheet)" ) 

but i'm not positive on setting that "the last sheet" variable. this maybe? 

(cadr (member (getvar 'CTAB) (layoutlist)))

So that leaves me here 

(DEFUN C:RCS ()

 (command "-layout" "rename" "" (getstring T "\nEnter new name for current layout")))
 (princ)
 (command "-layout" "copy" "" "" "ctab" (cadr (member (getvar  'CTAB) (layoutlist))) 
)

the lisp runs the first part (renaming) but fails to run the rest, 

new to writing lisps here, what am i doing wrong? 

 

 

 

 

0 Likes
Accepted solutions (2)
3,559 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

I'd do it this way [minimally tested]:

 

(command
  "_.layout" "_rename" "" (lisped (getvar 'ctab))
  "_.layout" "_copy" "" (lisped (getvar 'ctab))
)
(setvar 'ctab (last (layoutlist)))

 

The (lisped) function populates a text-edit box with the current name, so you can, for instance, just change a character or two, or add a little at the beginning or end, without having to re-type the rest of the Layout name, though you can also just replace it wholesale if you don't want to keep any of it.  It returns what you end up with for use by the Layout commands.

 

The new one becomes the last item in the list returned by (layoutlist), which makes that part pretty easy.  I did it with (setvar) above [because System Variable names can be used like  command names, but they're not really], but you can do it in the (command) function if you prefer:

(command
  "_.layout" "_rename" "" (lisped (getvar 'ctab))
  "_.layout" "_copy" "" (lisped (getvar 'ctab))
  "_.ctab" (last (layoutlist))
)

[even though I find that a manual command-line  CTAB command won't accept (last (layoutlist)) as input!].

 

EDIT:  Whoops -- now I find the new one isn't  necessarily always the last in (layoutlist) as it was in my first trials.  Let's try this instead:

(command
  "_.layout" "_rename" "" (lisped (getvar 'ctab))
  "_.layout" "_copy" "" (setq new (lisped (getvar 'ctab)))
)
(setvar 'ctab new)
Kent Cooper, AIA
0 Likes
Message 3 of 6

ronjonp
Advisor
Advisor

Here is also a way to set the last tab current if you don't know what the name is.

;; Load ActiveX
(vl-load-com)
(vlax-for tab (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (if (= (length (layoutlist)) (vla-get-taborder tab))
    (setvar 'ctab (vla-get-name tab))
  )
)
0 Likes
Message 4 of 6

dwattersAMXH5
Enthusiast
Enthusiast

So walk me through this 

(command
  "_.layout" "_rename" "" (lisped (getvar 'ctab))
  "_.layout" "_copy" "" (setq new (lisped (getvar 'ctab)))
)
(setvar 'ctab new)

this is taking and renaming the current layout with the variable 'ctab 
then doing a copy and naming the new sheet the variable new which is the same as ctab? or is that a second input? 
could i change it to (setq new ("newlayout")) to set a standard name for the new layout tab as "newlayout" 
then command "CTAB" runs after to look like this? 

(command
  "_.layout" "_rename" "" (lisped (getvar 'ctab))
  "_.layout" "_copy" "" (setq new ("NewLayout"))
  "ctab" new
)
(setvar 'ctab new)

this will allow you to rename the current tab, then moves you to a copy of this tab (named NewLayout) 


right? maybe? nope? 


 

 

 

 

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@dwattersAMXH5 wrote:

So walk me through this 
....

this is taking and renaming the current layout with the variable 'ctab 
then doing a copy and naming the new sheet the variable new which is the same as ctab? or is that a second input? 
could i change it to (setq new ("newlayout")) to set a standard name for the new layout tab as "newlayout" 
then command "CTAB" runs after to look like this? 
....

this will allow you to rename the current tab, then moves you to a copy of this tab (named NewLayout) 
right? maybe? nope?  


Not quite.  It's not renaming the current Layout, nor the new copy, with the variable 'ctab, but rather with what is returned by the (lisped) function -- the 'ctab is just pre-populating the text-editing box for you with the current name, in case what you want will be a minor modification of that.  If it would always be wholly different, you could go back to using (getstring).

 

Your revision looks like it should work [I didn't try it] if you remove the parentheses  around "NewLayout":

(setq new "NewLayout")

Kent Cooper, AIA
0 Likes
Message 6 of 6

dwattersAMXH5
Enthusiast
Enthusiast
Accepted solution

THANK YOU! 
works great!

attached is a copy of the lisp for anyone in the future 

 

RCS : Rename,Copy,Set layout