I’m trying to find a way to execute a few commands on every open drawing. Such as “pspace”, “zoom e”, and “qsave”. Or the commands may be different per the users or programmers requirements. Here are two functions that I was hoping would help get me started, GetDwgsList and ActivateDwg. The problem I’ve encountered is that once ActivateDwg changes to another open drawing, no further AutoLISP command are executed. I’ve heard that AutoCAD 2007 has something similar as in saving all open drawings, but it’s going to be a long wait before we get 2007. Also it would be great to have it execute any custom set of functions also. Here is what I’ve got to start from.
;-------------------------------------------------------------------------------
; GetDwgsList - Returns a list of open drawings
; Use (length (GetDwgsList)) for the number of open drawings.
;-------------------------------------------------------------------------------
(defun GetDwgsList (/ AcadOBJ DocsOBJ DwgsList@)
(if (>= (atoi (getvar "ACADVER")) 15)
(progn
(setq AcadOBJ (vlax-get-acad-object)
DocsOBJ (vlax-get-property AcadOBJ "Documents")
DwgsList@ nil
);setq
(vlax-for ForItem DocsOBJ
(setq DwgsList@ (cons (strcat (vlax-get-property ForItem "Path") "\\"
(vlax-get-property ForItem "Name")) DwgsList@))
);vlax-for
(setq DwgsList@ (reverse DwgsList@))
);progn
(setq DwgsList@ (list (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))))
);if
DwgsList@
);defun GetDwgsList
;-------------------------------------------------------------------------------
; ActivateDwg - Switches between open drawings
; Arguments: 1
; DwgPathFilename$ = Path and filename string of drawing
; Returns: Makes the drawing of DwgPathFilename$ current
;-------------------------------------------------------------------------------
(defun ActivateDwg (DwgPathFilename$ / Cnt# Num#)
(setq Cnt# 0 Num# 0)
(foreach Item (GetDwgsList)
(if (= (strcase DwgPathFilename$) (strcase Item))
(setq Num# Cnt#)
);if
(setq Cnt# (1+ Cnt#))
);foreach
(command "vbastmt" (strcat "Application.Documents.Item(" (itoa Num#) ").Activate"))
(princ)
);defun ActivateDwg