TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: debgun on February 23, 2010, 10:18:50 AM
-
I'm trying to create a new drawing from a template and saveas the new drawing. Unfortunately, the code below saves the previous blank drawing instead of the new drawing that was created from a template ("Kice 11X17").
(defun SaveDwg (/ dwgname path)
(vla-activate (vla-add (vla-get-documents (vlax-get-acad-object)) "Kice 11X17"))
(setq dwgname "IO-AA"
path (BrowseFolder))
(vla-saveas (vla-get-activedocument (vlax-get-acad-object)) (strcat path "/" dwgname) ac2007_dwg)
) ;defun
(defun BrowseFolder (/ ShlObj Folder FldObj OutVal)
(setq ShlObj (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application")
Folder (vlax-invoke-method ShlObj 'BrowseForFolder 0 "" 0)
) ;setq
(vlax-release-object ShlObj)
(if Folder
(progn
(setq FldObj (vlax-get-property Folder 'Self)
OutVal (vlax-get-property FldObj 'Path)
) ;setq
(vlax-release-object Folder)
(vlax-release-object FldObj)
OutVal
) ;progn
) ;if
) ;defun
-
Perhaps?
(defun SaveDwg (/ dwgname path newdoc)
(vla-activate (setq newdoc (vla-add (vla-get-documents (vlax-get-acad-object)) "Kice 11X17")))
(setq dwgname "IO-AA"
path (BrowseFolder))
(vla-saveas newdoc (strcat path "/" dwgname) ac2007_dwg)
) ;defun
-
I thought the lisp would fail if you activate another DWG without using ObjectDBX.
-
That could be why I'm having some difficulties, but it seems to work okay.
Lee, I moved the setq statements before creating new drawing. The only concern I have is I have to flip between the two drawings before the new drawing name shows the correct name. I tried regen, but no luck.
(defun SaveDwg (/ dwgname path newdoc)
(setq dwgname "IO-AC"
path (BrowseFolder))
(vla-activate (setq newdoc (vla-add (vla-get-documents (vlax-get-acad-object)) "Kice 11X17")))
(vla-saveas newdoc (strcat path "/" dwgname) ac2007_dwg)
)
-
Alan ( CAB ) is right. You can't open a drawing, and then activate it with lisp, and expect it to run the remaining lines of the lisp code. You can open it, and then save it, all from the current drawing without having to activate the new drawing.
Or you can just copy the file to the new location, and rename it, without even opening it in Acad, and it can be done with lisp.
-
Cheers guys, mine was a stab in the dark... :|
-
Thanks all! Could any of you point me to a good resource on ObjectDBX?
-
why activate? :)
(defun SaveDwg (/ dwgname path newdoc)
(setq newdoc (vla-add (vla-get-documents (vlax-get-acad-object)) "Kice 11X17"))
(setq dwgname "IO-AA"
path (BrowseFolder))
(vla-saveas newdoc (strcat path "\\" dwgname) ac2007_dwg)
) ;defun
-
That is exactly how I was envisioning it VovKa.