Using 2008.
I wonder if the following problem is a known issue. It seems I cannot get data about objects in paper space layouts until the layout(s) are activated. IOW, if I open a DWG file which was saved with model space active, a LISP routine which tries to access objects in paper space returns nil.
Example code follows. Both methods fail.
(defun GetPSObjects1 ( / doc layouts pslst)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq layouts (vla-get-Layouts doc))
;; works okay if this line is included.
;(vlax-for x layouts (vlax-put doc 'ActiveLayout x))
(vlax-for x layouts
(if (not (eq "Model" (vlax-get x 'Name)))
(vlax-for i (vlax-get x 'Block)
(setq pslst (cons i pslst))
)
)
)
pslst
)
(defun GetPSObjects2 ( / doc blocks pslst)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq blocks (vla-get-Blocks doc))
(vlax-for x blocks
(if
(and
(not (eq "*MODEL_SPACE" (strcase (vlax-get x 'Name))))
(= -1 (vlax-get x 'IsLayout))
)
(vlax-for i x
(setq pslst (cons i pslst))
)
)
)
pslst
)
I should add, if the drawing contains one or more apparently empty paper space layouts, the code should return the default viewport for each layout.