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

Creating new layout changed

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
dvertz
638 Views, 15 Replies

Creating new layout changed

Just upgraded from 2022 to 2024 and one of my LSP routines is failing to perform as it did. I cannot figure out how to make it right again.

 

Setup a drawing with 3 layouts and name them as C-000; C-002; C-004

Select layout C-002 and run this code. (it is a snippet of the LSP).

 

(setq SYS:CURTAB (getvar "CTAB"))
(setq STR:CURTAB (strcat "C-00" (itoa (1+ (atoi (substr SYS:CURTAB (+ 2 (vl-string-search "-" SYS:CURTAB))))))))
(command "layout" "c" SYS:CURTAB STR:CURTAB)

The result is the new layout tab is inserted BEFORE the current tab.This make the order C-000; C-003; C-002; C-004. In 2022 it was inserted AFTER. Making it make the order C-000; C-002; C-003; C-004.

 

If 1+ is changed to 1- to decrease the number so inserting before makes sense, then the new tab is inserted AFTER the current layout. Making the order C-000; C-002; C-001; C-004.

 

Since "command 'layout' " does not have the "insert before sheet" as the dialog has, what controls if the new sheet is inserted before or after the current tab?

 

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


15 REPLIES 15
Message 2 of 16
CodeDing
in reply to: dvertz

@dvertz ,

 

This behavior seems normal. The 2024 and 2022 documentation seem to confirm that it has always been inserted BEFORE the layout being copied:

2024 Doc:

https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-BCE3AD90-9DE0-488C-9CA4-5FDB9401DCE0 

2022 Doc:

https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-BCE3AD90-9DE0-488C-9CA4-5FDB9401DCE0 

 

I have tested your code with 2021 and it also confirms that it is inserted before the layout being copied (even when I use 1+ or 1-).

 

Since you are merely creating a copy of the layout, perhaps just consider renaming the layouts after they're created?

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 16
dvertz
in reply to: CodeDing

Thanks for the suggestion. However, renaming the layout defeats the purpose of the LSP. It is designed to shortcut the creation through the dialog. Otherwise, the dialog is the way to go as it also requires renaming the layout after the creating the copy.

 

Strange, if it is designed to ALWAYS create before, then why is it creating it AFTER when the sheet name becomes C-001 with the 1-? Maybe someone using 2024 could verify this?

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


Message 4 of 16
CodeDing
in reply to: dvertz


@dvertz wrote:

However, renaming the layout defeats the purpose of the LSP. It is designed to shortcut the creation through the dialog.


It sounds like maybe you misinterpreted what I was suggesting, so I would like to clarify to be sure..

I am suggesting that to solve your issue.. 

..when your layouts begin like this..

C-000; C-002; C-004

..and after your command, they look like this..

C-000; C-003; C-002; C-004

..you could just rename 3 & 2 so they look proper, like this..

C-000; C-002; C-003; C-004

 

That would just be a few more lines of code and solve your issue yeah? I know it's not ideal, but still a workaround.

It's hard to digest further without knowing what the rest of the code does.

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 5 of 16
dvertz
in reply to: CodeDing

Thanks. I think maybe I did misunderstand what you were saying. And using the (command "layout" "rename") could work, if I always knew if the new layout was going to get inserted before or if it was inserted after. I will have to think this one through and run some tests.

 

Right now I think its best to just move the tab to the correct position.

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


Message 6 of 16
paullimapa
in reply to: dvertz

Looks like the change occurred with 2023 & continued in 2024 but not sure if that'll continue with the next 2025 release. But for now you can try to test for the version as newer than 2022 but older than 2025 then run code.

 

 

; cpytab copies current layout & places after
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/creating-new-layout-changed/m-p/12180581/thread-id/453428
(defun c:cpytab (/ get_layoutnum set_layoutnum SYS:CURTAB STR:CURTAB )
; get_layoutnum returns given layout name's layout order number in database as a string or nil if not found
; modified from c:tabpage:
; https://www.cadtutor.net/forum/topic/69748-current-number-position-of-layout-not-counting-model-lisp-code/
  (defun get_layoutnum (tab / lst ord)
   ; retrieve all layouts in database order and place into list
   (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (setq
       lst
       (cons (cons (vla-get-name lay) (itoa (vla-get-taborder lay))) lst)
    )
   )
   (foreach x lst ; cycle through list 
    (if (= (car x) tab)  ; if matches with given layout name
       (setq ord (cdr x))
    )
   ) ; foreach
   ord
  ) ; defun
; set_layoutnum moves given layout name to given order number
; modified from c:ChLayoutOrder
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-tab-position/td-p/818199
  (defun set_layoutnum (tab num)
   (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if (= (vlax-get-property lay 'Name) tab);what layout
        (vlax-put-property lay 'TabOrder num);position of layout
    )
   )
  ) ; defun
 ;
 ; main function
 ;
 (if(not(zerop(getvar"tilemode")))(setvar"tilemode"0))
 (setq SYS:CURTAB (getvar "CTAB"))
 (setq STR:CURTAB (strcat "C-00" (itoa (1+ (atoi (substr SYS:CURTAB (+ 2 (vl-string-search "-" SYS:CURTAB))))))))
 (command "_.Layout" "_C" SYS:CURTAB STR:CURTAB)
 (if(and(> (atof (getvar"acadver")) 24.1)(< (atof (getvar"acadver")) 24.4))
   (set_layoutnum STR:CURTAB (get_layoutnum SYS:CURTAB))
 )
 (princ)
) ; defun

 

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 16
CodeDing
in reply to: paullimapa

@paullimapa 


@paullimapa wrote:

Looks like the change occurred with 2023 & continued in 2024...


How were you able to confirm this? Curious how to test something like that.

You just test a handful of versions to check it yourself?

Can you confirm 21 for me then? Because mine confirmed the behavior as normal.

 

Best,

~DD

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 8 of 16
paullimapa
in reply to: CodeDing

Yes, I'm able to test by opening up each version actually starting with 2020 up to 2024.

I can confirm that the change only occurred starting 2023 which means 2022, 2021 & 2020 behave the same. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 9 of 16
CodeDing
in reply to: paullimapa


@paullimapa wrote:

I can confirm that the change only occurred starting 2023 which means 2022, 2021 & 2020 behave the same. 


Then something doesn't make sense because OP stated that his has always inserted AFTER (in Acad 2022) and mine is inserting BEFORE (in Acad 2021)..

 

@dvertz wrote:

The result is the new layout tab is inserted BEFORE the current tab.This make the order C-000; C-003; C-002; C-004. In 2022 it was inserted AFTER.


Can you confirm which action is happening for your 2021 & 2022 versions?

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 10 of 16
paullimapa
in reply to: CodeDing

when I run your code:

(setq SYS:CURTAB (getvar "CTAB"))
(setq STR:CURTAB (strcat "C-00" (itoa (1+ (atoi (substr SYS:CURTAB (+ 2 (vl-string-search "-" SYS:CURTAB))))))))
(command "layout" "c" SYS:CURTAB STR:CURTAB)

In 2020, 2021 & 2022, the result looks like this:

paullimapa_0-1692378346053.png

But for 2023 & 2024, it looks like this:

paullimapa_1-1692378612578.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 16
paullimapa
in reply to: CodeDing

ok, here's a better method instead of testing for acad version,  just test for the position:

; cpytab copies current layout & places after
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/creating-new-layout-changed/m-p/12180581/thread-id/453428
(defun c:cpytab (/ get_layoutnum set_layoutnum SYS:CURTAB STR:CURTAB )
; get_layoutnum returns given layout name's layout order number in database as a string or nil if not found
; modified from c:tabpage:
; https://www.cadtutor.net/forum/topic/69748-current-number-position-of-layout-not-counting-model-lisp-code/
  (defun get_layoutnum (tab / lst ord)
   ; retrieve all layouts in database order and place into list
   (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (setq
       lst
       (cons (cons (vla-get-name lay) (itoa (vla-get-taborder lay))) lst)
    )
   )
   (foreach x lst ; cycle through list 
    (if (= (car x) tab)  ; if matches with given layout name
       (setq ord (cdr x))
    )
   ) ; foreach
   ord
  ) ; defun
; set_layoutnum moves given layout name to given order number
; modified from c:ChLayoutOrder
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/layout-tab-position/td-p/818199
  (defun set_layoutnum (tab num)
   (vlax-for lay (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (if (= (vlax-get-property lay 'Name) tab);what layout
        (vlax-put-property lay 'TabOrder num);position of layout
    )
   )
  ) ; defun
 ;
 ; main function
 ;
 (if(not(zerop(getvar"tilemode")))(setvar"tilemode"0))
 (setq SYS:CURTAB (getvar "CTAB"))
 (setq STR:CURTAB (strcat "C-00" (itoa (1+ (atoi (substr SYS:CURTAB (+ 2 (vl-string-search "-" SYS:CURTAB))))))))
 (command "_.Layout" "_C" SYS:CURTAB STR:CURTAB)
 (if (< (get_layoutnum STR:CURTAB)(get_layoutnum SYS:CURTAB))(set_layoutnum STR:CURTAB(get_layoutnum SYS:CURTAB)))
 (princ)
) ; defun

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 16
CodeDing
in reply to: paullimapa

@dvertz & @paullimapa ,

 

This is weird, check this out. It appears that when you use the DEFAULT naming for the copied layout, it is added AFTER the copied layout.

 

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 13 of 16
paullimapa
in reply to: CodeDing

not for me...still same result for 2020, 2021 & 2022 all after

but for 2023 & 2024 all before

(command "_.LAYOUT" "_C" "" "")

is no different than:

(command "_.LAYOUT" "_C" "C-002" "C-003")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 14 of 16
paullimapa
in reply to: CodeDing

looks like it has something to do with the name

If you use Some-Layout, you'll get that result

But if you use what you had before C-002, then you'll get the results I've been reporting.

So the best bet is my revise code which tests for layout tab order #.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 15 of 16
dvertz
in reply to: paullimapa

Sorry for the delay getting back to you guys.

 

Paul,

I inserted your code into mine, made a few adjustments, and everything seems to be working very well. I thank you for taking the time to figure this one out. It seems you found what version of Autocad made the change. I appreciate that information as well.

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


Message 16 of 16
paullimapa
in reply to: dvertz

Glad to have helped…cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report