So I have two drawings.
The first has tabs Model, Layout1, Layout2, Layout3, Layout4.
The second has tabs Model, Layout1, COLOR-2, Layout3, SHEET-4
When this is placed in the command line I get different results
(vlax-for layname (setq colLayouts (vla-get-layouts(vla-get-activedocument(vlax-get-acad-object))))
(vla-get-name layname))
Drawing Default_tab_Test.dwg - Model (as expected)
Drawing Color_Sheet_Test.dwg - SHEET-4 (what?)
Why?
AutoCAD Mechanical 2019
Solved! Go to Solution.
Solved by cadffm. Go to Solution.
@Pretengineer wrote:
(vlax-for layname (setq colLayouts (vla-get-layouts(vla-get-activedocument(vlax-get-acad-object))))
(vla-get-name layname))
Drawing Default_tab_Test.dwg - Model (as expected)
Drawing Color_Sheet_Test.dwg - SHEET-4 (what?)
Why?
Why do you expect "Model"? Make no sense.. or better, make the same sense like "SHEET-4"
(vlax-for variablename ; iterate thru
(setq colLayouts
(vla-get-layouts ; all Tabs (layouts and model
(vla-get-activedocument ; from the active file
(vlax-get-acad-object)))) ; of THIS instance of AutoCAD
(vla-get-name layname) ; read the layout/tab name
)
and vlax-for visual feedback is ONLY the last evaluation, the name of the last tab in the 'layouts collections'
Use this one to see more:
(vlax-for variablename ; iterate thru
(setq colLayouts
(vla-get-layouts ; all Tabs (layouts and model
(vla-get-activedocument ; from the active file
(vlax-get-acad-object)))) ; of THIS instance of AutoCAD
(terpri)(princ(vla-get-name layname)) ; blank line, read&promt the layout/tab name
)
Back to your question: WHY?
Because of.. the layout collection is in order of alphabet
Try it: Rename "Layout4" to "XLayout4"... the last layout is XLayout4 now.
Move xlayout4 in the display order and recheck.
This may be helpful
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq tabs (vla-get-Layouts doc))
(vlax-for lay tabs
(princ (vla-get-taborder lay))
)
@Sea-Haven wrote:
Move xlayout4 in the display order and recheck.
As i explained, the order by alphabet and so it is depending of the Layout-names,
Why should i re-check this after i re-order the tabs? It isn't changing the names of thab tabs,
so the result is the same.
This may be helpful
(setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq tabs (vla-get-Layouts doc)) (vlax-for lay tabs (princ (vla-get-taborder lay)) )
Sure it is helpful, at the right place for a matching task,
but here is it just offtopic and not related to the question.
[or do you want to confuse @Pretengineer even more?]
sorry
@cadffm wrote:[or do you want to confuse @Pretengineer even more?]
sorry
No echo. Another
@cadffm Thank you for the explanation, I had not realized it returns the tab (layout) with the highest letter in the alphabet.
A check is being run right before the program to leave out the model tab. If I had a tab named SHEET it would skip the program and not run the settings for those tabs also. I need to alter my check or if statement to run all tabs except the model tab.
There are other comments on the original post, so I'll take a look at those.
Thanks again, still learning.
You can also check the function (layoutlist) that includes only the layout names and does not have the Model block among them.
@Pretengineer wrote:@cadffm Thank you for the explanation, I had not realized it returns the tab (layout) with the highest letter in the alphabet.
A check is being run right before the program to leave out the model tab. If I had a tab named SHEET it would skip the program and not run the settings for those tabs also. I need to alter my check or if statement to run all tabs except the model tab.
There are other comments on the original post, so I'll take a look at those.
Thanks again, still learning.
The code I wrote for you HERE has an example how to skip the modelspace tab?
...
(if (= 0 (vlax-get l 'modeltype))
...
FYI, in lisp 0 = False and -1 = True
In response to critisism if you make a number of layouts say 5 and move a layout visually so could have lay1 lay2 lay5 lay3 lay4
The taborder will return the order as 1 2 5 3 4 so what I did not post is you use this method and get the item/count from the layouts and then retrieve its name this will return all names in the correct visual order and not by name/alpha etc.
(vlax-for lay alllayouts
(if (= num (vla-get-taborder lay))
(setvar "ctab" (vla-get-name lay))
)
)