So this is my code the way I would do it if it were on my machine.
Code:
;___________________________________________________________________________________________________________|
;
; Function to get layout number from name of layout
;___________________________________________________________________________________________________________|
(defun LayoutNumber (strLayoutName / colLayouts lstLayoutObjects lstOfLayouts)
(if (and (setq colLayouts (Layouts 'activedocument))
(setq lstLayoutObjects (toobjects colLayouts))
(setq lstOfLayouts (mapcar '(lambda (X)(list (strcase (vlax-get X "Name"))
(vlax-get X "Taborder")
)
)
lstLayoutObjects)
)
)
(cadr (assoc (strcase strLayoutName) lstOfLayouts))
)
)
I have rewritten activeX to give me access to all activeX commands with error trapping built in and without vla- prefixes.
In one of my libraries I have a function called toobjects that converts collections, autolisp selectionsets, lists of handles, objectid's, entity names, entity lists, activeX selection sets to a list of vla objects. One of the functions is collection to list. So I rewrote it here as an example below.
I stopped nesting functions a long time ago, because I found it is better to test every expression for success (error trapping).
All of the functions return nil for failure.
This approach gives me libraries of functions (1000+ functions) that load at every drawing is less than a second.
This one below will work for you.
Code:
;___________________________________________________________________________________________________________|
;
; Function to get layout number from name of layout
;___________________________________________________________________________________________________________|
(defun LayoutNumber (strLayoutName / colLayouts lstLayoutObjects lstOfLayouts objApplication objActiveDocument)
(if (and (setq objApplication (vlax-get-acad-object))
(setq objActiveDocument (vlax-get objApplication "ActiveDocument"))
(setq colLayouts (vlax-get objActiveDocument "Layouts"))
(setq lstLayoutObjects (CollectionToListOfObjects colLayouts))
(setq lstOfLayouts (mapcar '(lambda (X)(list (strcase (vlax-get X "Name"))
(vlax-get X "Taborder")
)
)
lstLayoutObjects)
)
)
(cadr (assoc (strcase strLayoutName) lstOfLayouts))
)
)
;___________________________________________________________________________________________________________|
;
; Function to convert a collection to a list of objects
;___________________________________________________________________________________________________________|
(defun CollectionToListOfObjects (colLayouts / lstObjects objLayout)
(vlax-for objLayout colLayouts
(setq lstObjects (cons objLayout lstObjects))
)
(reverse lstObjects)
)
(vl-load-com)