Jump to content

Open a new drawing from a named template


Recommended Posts

I have added a button to a tool-bar in AutoCAD 2008, the button "New". When I click it it opens up the dialogue for selecting a template. I tried various ways using the /t switch with the name of the template, but it always comes back with"Unknown command ..."

 

Is there a way to do it using a DIESEL expression or anything similar, so that when I click my new button it opens a new drawing from the named template?

Link to comment
Share on other sites

Addthis macro to your menu:

 

^C^C^Pfiledia;0;new;[b]mytemplate.dwt[/b];filedia;1;^P

 

where mytemplate.dwt refers to the desire template file.

Link to comment
Share on other sites

Thanks for the advice Ahankhah.

 

In the CUI, I put the following code in the Macro line under Command:

 

^C^C^PFiledia;0;new;Test_Template.dwt;Filedia;1;^P

and get the following situation:

 

The macro stops and asks me for the name of the template file:

 

Enter template file name or [. (for none)] \AppData\Local\Autodesk\C3D 2008\enu\Template\acad.dwt>:
From the text window:

 

Command:

Unknown command "TEST_TEMPLATE.DWT". Press F1 for help.

 

Command:

 

Enter new value for FILEDIA :

How can I get the macro to take the name of the template file given in the macro line?.
Link to comment
Share on other sites

Are you sure to put Test_Template.dwt file in template folder? To get the right place, first open your file (Test_Template.dwt), then issue SAVEAS command. The program saves it automatically in the correct location.

Link to comment
Share on other sites

Yes the Test_Template.dwt is in the default folder, if I type in its name or select it, then a new drawing is opened from the template.

 

I created the Test_Template.dwt file by using SAVEAS and selecting a DWT format. Afterwards I navigated to the folder in Windows Explorer and verified that it was there.

 

The macro you suggested looks as though it should work, but its not accepting the template name and the semicolon (as a return).

Link to comment
Share on other sites

Yes the Test_Template.dwt is in the default folder, if I type in its name or select it, then a new drawing is opened from the template.

 

I created the Test_Template.dwt file by using SAVEAS and selecting a DWT format. Afterwards I navigated to the folder in Windows Explorer and verified that it was there.

 

The macro you suggested looks as though it should work, but its not accepting the template name and the semicolon (as a return).

 

Tyke,

NEW command has a strange behaviour. Just when it is called, It forgets anything and doesn't know to continue the macro.

So you can do the followings:

 

1- Make a script file containing:

filedia
0
_.NEW
Test_Template.dwt
filedia
1

Be aware to press Enter after the last line of file.

Save it with any name but with .SCR extension, i.e. myscript.scr.

 

2- Change the menu macro this way:

^C^Cscript;myscript.scr;

Link to comment
Share on other sites

if you can't get it to work could you make the template you are after the default one and issue a QNEW instead?

 

Hi Dave, unfortunately that wouldn't work because the template is needed for a specific add-in with quite a few "unusual" settings (well anyway unusual for us) and its not required every day.

 

I'll give the script idea from Ahankhah a try.

Link to comment
Share on other sites

 

Save it with any name but with .SCR extension, i.e. myscript.scr.

 

Where is it best to save it? I have the path for the add-in in the AutoCAD support path, for a couple of other things, and would like to keep everything together if possible.

Link to comment
Share on other sites

I meant can you change the default template cariable and then reset it, but since I can't find what the variable is called that was a stupid suggestion. :)

 

As for scripts, don't forget that if your text editor adds an extra CR to the end this will be seen as "repeat the last command". I tend to finish my scripts with a RESUME these days as AutoCAD doesn't mind repeating that several times.

 

I *think* AutoCAD will run the script from where it finds it so you can put it in any pathed folder. Alternatively you could hard code the folder into the call.

Link to comment
Share on other sites

Where is it best to save it?

Any where in the search path of AutoCAD, which can be obtained by issuing ACADPREFIX command.

Link to comment
Share on other sites

As for scripts, don't forget that if your text editor adds an extra CR to the end this will be seen as "repeat the last command".

You are right dbroada,

but on the other hand, if you forget to press Enter after typing the last line, AutoCAD pauses when reading the line and waits for pressing Enter by user.

Link to comment
Share on other sites

Thanks Dave and Ahankhah, that did the trick, well almost. I used this code for the script:

 

filedia
0
_.NEW
Template.dwt
filedia
1

and this for the macro:

 

^C^Cscript;Template_New.scr;^C^C

The two escapes cleaned up the command line when I was done.

 

Thanks guys :D

Link to comment
Share on other sites

  • 1 month later...

I believe the following code is more reliable and better than above mentioned methods.

[b](vl-load-com)
(vla-activate 
  (vla-add
     (vla-get-documents 
        (vlax-get-acad-object)
     )
     "Template.dwt"[/b][color=magenta]; You can change Template.dwt to any desired name.[/color]
[b]   )
)[/b]

Simply add it to your toolbar menu.

 

This is the code all in one line:

[b]^C^C^P(vl-load-com)(vla-activate(vla-add(vla-get-documents(vlax-get-acad-object))"Template.dwt"[/b][b]));^P[/b]

Link to comment
Share on other sites

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...