Author Topic: Creating new drawing from template  (Read 1768 times)

0 Members and 1 Guest are viewing this topic.

debgun

  • Guest
Creating new drawing from template
« 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

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Creating new drawing from template
« Reply #1 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Creating new drawing from template
« Reply #2 on: February 23, 2010, 10:49:57 AM »
I thought the lisp would fail if you activate another DWG without using ObjectDBX.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

debgun

  • Guest
Re: Creating new drawing from template
« Reply #3 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)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Creating new drawing from template
« Reply #4 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Creating new drawing from template
« Reply #5 on: February 23, 2010, 11:09:35 AM »
Cheers guys, mine was a stab in the dark...  :|

debgun

  • Guest
Re: Creating new drawing from template
« Reply #6 on: February 23, 2010, 11:17:35 AM »
Thanks all!  Could any of you point me to a good resource on ObjectDBX?

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Creating new drawing from template
« Reply #7 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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Creating new drawing from template
« Reply #8 on: February 23, 2010, 12:20:23 PM »
That is exactly how I was envisioning it VovKa.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.