Creating new layout changed

dvertz
Advocate
Advocate

Creating new layout changed

dvertz
Advocate
Advocate

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


0 Likes
Reply
Accepted solutions (1)
843 Views
15 Replies
Replies (15)

CodeDing
Advisor
Advisor

@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


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

dvertz
Advocate
Advocate

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


0 Likes

CodeDing
Advisor
Advisor

@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


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

dvertz
Advocate
Advocate

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


0 Likes

paullimapa
Mentor
Mentor

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
0 Likes

CodeDing
Advisor
Advisor

@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


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

paullimapa
Mentor
Mentor

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

CodeDing
Advisor
Advisor

@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?


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

paullimapa
Mentor
Mentor

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

paullimapa
Mentor
Mentor
Accepted solution

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
0 Likes

CodeDing
Advisor
Advisor

@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.

 


Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
0 Likes

paullimapa
Mentor
Mentor

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
0 Likes

paullimapa
Mentor
Mentor

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

dvertz
Advocate
Advocate

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


0 Likes

paullimapa
Mentor
Mentor

Glad to have helped…cheers!!!


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