How does someone get the variable for each open instance of documents in a cad program?
;; Gets the application
(setq objApp (vlax-get-acad-object))
;; Object collection of open documents
(setq objDocs (vla-get-documents objApp))
;; Each open document
(setq iCount (vla-get-count objDocs))
(setq iItr1 0)
(repeat iCount ; Also tried foreach
;; This is where I'm stuck
;; ssname works with selection sets, not objects.
(setq objOpenDoc (ssName objDocs iItr1));---; <-Error
(princ "\nDoc : ")(princ objOpenDoc)(terpri); Printing Results
(setq iItr1 (1+ iItr1));--------------------; Next Document
);repeat
Instead of repeat
, use vlax-for
. Vlax-for
allows for collections within object variables to be individually passed into the symbol variable.
;; Gets the application
(setq objApp (vlax-get-acad-object))
;; Object collection of open documents
(setq objDocs (vla-get-documents objApp))
;; Each open document
(vlax-for objOpenDoc objDocs
(princ "\nDoc : ")(princ objOpenDoc)(terpri); Printing Results
);repeat
Result:
Command: (progn (setq objApp (vlax-get-acad-object))(setq objDocs (vla-get-documents objApp))(vlax-for objOpenDoc objDocs (princ "\nDoc : ")(princ objOpenDoc)(terpri)))
Doc : #<VLA-OBJECT IAcadDocument 85066cc0>
Doc : #<VLA-OBJECT IAcadDocument 0828b3c0>
Doc : #<VLA-OBJECT IAcadDocument 60e96430>
Doc : #<VLA-OBJECT IAcadDocument 574d6760>
Doc : #<VLA-OBJECT IAcadDocument 86b0e3b0>
Doc : #<VLA-OBJECT IAcadDocument a5964cc0>
Doc : #<VLA-OBJECT IAcadDocument cdf25490>
nil