Here are just a few things I noticed about the code you provided. The best thing is it works. I included some other comments in the code for you to look at:
(Defun GetTabs (/ dwg cnt tab typ lst); rtn) not needed
;Always localize your variables unless
;intentionally using a global variable
(vl-load-com)
(setq DWG (vla-get-layouts
(vla-get-activedocument (vlax-get-acad-object))
)
CNT (vla-get-count DWG)
)
(while (<= 0 (setq CNT (1- CNT)))
;Changed the < to <= because 0 is a valid item.
(setq TAB (vla-item DWG CNT)
TYP (strcase (vla-get-name TAB))
)
(if (not (eq TYP "MODEL"))
;If you use cons instead of append to create your list
;then you won't need to test LST first.
;(if (= LST Nil)
;(setq LST (list TAB))
;(setq LST (append LST (list TAB)))
;)
(setq LST (cons TAB LST))
)
)
;If this is returning a list to another function you don't
;need to set this another variable just return the one
;already established.
;(setq RTN LST)
LST
)
Another way to do the same thing using vlax-for instead of while is:
(vlax-for is the same as foreach except used on a collection)
(Defun GetTabs2 (/ dwg typ lst)
(vl-load-com)
(setq dwg (vla-get-layouts
(vla-get-activedocument
(vlax-get-acad-object))
)
)
(vlax-for lay dwg
(setq typ (strcase (vla-get-name lay)))
(if (not (eq typ "MODEL"))
(setq lst (cons lay lst))
)
)
lst
)
But these methods do not put the layouttabs in order they just return a list of the tabs. The code I posted earlier returned the list in the order as given in the drawing.
(vlax-map-collection
(*layouts*)
'(lambda (x) (setq lst (cons x lst)))
)
This does what your code does. (*layouts*) is a function I made to illustrate a point. I normally use a global variable here. If you are not familiar with vlax-map-collection think of mapcar for collections. I think the syntax is different, but it works the same way. The lambda function is the same as your while loop except mine does not filter out the "MODEL" tab yet. I then called a sort function that uses the 'taborder property and once they were ordered I removed the first item which would be the "MODEL" tab. Then you have an ordered list of tab objects.[/code]
I hope this helps and keep asking those questions.