Making an autolisp that copies layouts from an other drawing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm not that familiar with lisp yet, but I would like to copy layouts from other drawings into existing drawings. I have a lisp but it doesn't work. can someone tell me what i am doing wrong?
(defun c:layouts (/ fname)
(and (setq fname (getfiled "Select Drawing" "-- -- 2 -- 01 " "dwg" 0))
(imp_layouts fname)
)
(princ)
)
(defun imp_layouts (source / *acad* doc l_import odbx Doctest
path lays l_list)
(vl-load-com)
(setq *acad* (vlax-get-acad-object)
doc (vla-get-activedocument *acad*))
;;**** Check if source file is open
(vlax-for oDoc (vla-get-documents *acad*)
(if (= (vla-get-fullname oDoc) source)
(setq Doctest t)))
(if (and (not Doctest) (findfile source))
(progn ;; Ensure that ObjectDBX is available
(if (> (setq versn (atoi (getvar "AcadVer"))) 15)
(setq oDBX (vla-GetInterfaceObject
*acad* (strcat "ObjectDBX.AxDbDocument." versn)))
(progn
(if (not (vl-registry-read
"HKEY_CLASSES_ROOT\\ObjectDBX.AxDbDocument\\CLSID"))
(startapp "regsvr32.exe"
(strcat "/s \"" (findfile "axdb15.dll") "\""))
);;if
(setq oDBX (vla-GetInterfaceObject
*acad* "ObjectDBX.AxDbDocument"))
);;progn
);;if
(vla-open oDBX source);; "opens" source for our use
(setq lays (vla-get-layouts oDBX));; source layout table
(if (> (vla-get-count lays) 1);;ensure there are layouts to import
(progn
(vlax-for x lays ;; cycle thru table & check if name
;; exists in this drawing, omit if so
(if (not (or (= "Model" (vla-get-name x))
(member (vla-get-name x) (layoutlist))))
(setq l_list (append (list x) l_list )
b_list (append (list (vla-get-block x)) b_list))
);if
);for
(setvar "ctab" "Model")
(if l_list
(progn
(setq l_import (vlax-safearray-fill
(vlax-make-safearray vlax-vbObject
(cons 0 (- (length l_list) 1))
) l_list)
b_import (vlax-safearray-fill
(vlax-make-safearray vlax-vbObject
(cons 0 (- (length b_list) 1))
) b_list)
);; create safearray for use in ActiveX method
(vla-copyobjects oDBX l_import (vla-get-layouts doc))
(vla-copyobjects oDBX b_import (vla-get-blocks doc))
(foreach x (layoutlist)
(cond ((= x "Layout1")(vla-delete (vla-item (vla-get-layouts doc) x)))
((= x "Layout2")(vla-delete (vla-item (vla-get-layouts doc) x)))
)
)
(princ (strcat "\nLayouts imported successfully: "
(itoa (length l_list))))
;;import the layouts
);progn
(princ "\No new layouts to import from the source drawing...")
);if
);progn
(princ "\nSorry, no layouts found in source drawing, try again.")
);if
(vlax-release-object oDBX);; we're done with it
);progn
(progn
(if doctest
(princ "\nYou tried to use a file in use by Autocad, please close it and try again....")
(princ "\nSource file not found, please try again....")
);;if
);;progn
);if
(princ);; exit quietly
);defun
;;;(princ "Import layouts from source drawing to this drawing,")
;;;(princ "type \"(imp_layouts \"source path & file\")\" to run.")
;;;(princ)