Jump to content

Open new drawing template from command line


Recommended Posts

Posted

I am looking to open a new drawing from an existing template. I know I have seen how to do this on here but an totally not finding it. Does anyone have a sugestion. I just want a simple command that will open a new drawing and then I can save it. I have tried the open with the file path but I would really like something a little more simple.

 

Thanks.

Posted

Assuming you have your templates in place, are you looking for code or a command macro? If code, LISP or VBA or .Net?

Posted

Yes, I have my templates in place. Either a Macro or a Lisp would be fine. something as simple as nE05 would be perfect.

Posted

OK, Im thinking LISP is what you want, as that is the simplest to make a command with

Posted

I am not a LISP guru, so there may be a way to do all of this in LISP, but I dont know it. I do know you can do this though, which is create a template.dvb file, with LISP shortcuts to call the macros.

 

Sub Example_New()
   ' This example creates a new drawing based on the template ansi-a.dwt.
   ' Note: The path to the template file is included with its name. Adjust
   ' this path for your installation location before running this example.
   
   Dim templateFileName As String
   templateFileName = "c:\AutoCAD\template\ansi-a.dwt"
   
   ThisDrawing.New templateFileName
   
End Sub

 

and that could be called with

(defun c:nE05()
(command "-vbarun" "Example_New")
)

 

of course, substitute your template name and path. If you have a few names you want, we can knock thouse out real quick

Posted

Yes it possible in Visual lisp. You can define function like this:

 

(defun NewFromTemplate(Template / tmplPat cTmpl)
 
(vl-load-com)

; retrieve standard Template folder
(setq tmplPat
 (vla-get-TemplateDWGPath
   (vla-get-Files
     (vla-get-Preferences
       (vlax-get-acad-object)))))
 
; if template found
(if(setq cTmpl
  (findfile
	(strcat tmplPat "\\" Template)))
 
; create and activate drawing
 (vla-Activate
   (vla-Add
     (vla-get-Documents
(vlax-get-acad-object))
     cTmpl
     )
   )
 (alert(strcat "Can't to find template: " Template ))
 )
); end of NewFromTemplate

 

And short functions to define user commnads. For example:

 

(defun c:tmpl1()
 (NewFromTemplate "acadiso.dwt")
 (princ)
 ); end of c:tmpl1

(defun c:tmpl2()
 (NewFromTemplate "acadISO -Named Plot Styles3D.dwt")
  (princ)
); end of c:tmpl2

 

for TMPL1 and TMPL2 commands. As argument you must to use short *.dwt file name (without full path).

Posted

Thanks these were what I was looking for! :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...