TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: debgun on February 23, 2010, 10:18:50 AM

Title: Creating new drawing from template
Post 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").

Code: [Select]
(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
Title: Re: Creating new drawing from template
Post by: Lee Mac on February 23, 2010, 10:43:42 AM
Perhaps?

Code: [Select]
(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
Title: Re: Creating new drawing from template
Post by: CAB on February 23, 2010, 10:49:57 AM
I thought the lisp would fail if you activate another DWG without using ObjectDBX.
Title: Re: Creating new drawing from template
Post by: debgun on February 23, 2010, 11:01:24 AM
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.

Code: [Select]
(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)
)
Title: Re: Creating new drawing from template
Post by: T.Willey on February 23, 2010, 11:08:03 AM
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.
Title: Re: Creating new drawing from template
Post by: Lee Mac on February 23, 2010, 11:09:35 AM
Cheers guys, mine was a stab in the dark...  :|
Title: Re: Creating new drawing from template
Post by: debgun on February 23, 2010, 11:17:35 AM
Thanks all!  Could any of you point me to a good resource on ObjectDBX?
Title: Re: Creating new drawing from template
Post by: VovKa on February 23, 2010, 11:59:02 AM
why activate? :)
Code: [Select]
(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
Title: Re: Creating new drawing from template
Post by: T.Willey on February 23, 2010, 12:20:23 PM
That is exactly how I was envisioning it VovKa.