Tyke Posted May 14, 2011 Share Posted May 14, 2011 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? Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted May 14, 2011 Share Posted May 14, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tyke Posted May 15, 2011 Author Share Posted May 15, 2011 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?. Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted May 15, 2011 Share Posted May 15, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tyke Posted May 15, 2011 Author Share Posted May 15, 2011 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). Quote Link to comment Share on other sites More sharing options...
dbroada Posted May 15, 2011 Share Posted May 15, 2011 if you can't get it to work could you make the template you are after the default one and issue a QNEW instead? Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted May 16, 2011 Share Posted May 16, 2011 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; Quote Link to comment Share on other sites More sharing options...
Tyke Posted May 16, 2011 Author Share Posted May 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tyke Posted May 16, 2011 Author Share Posted May 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
dbroada Posted May 16, 2011 Share Posted May 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted May 16, 2011 Share Posted May 16, 2011 Where is it best to save it? Any where in the search path of AutoCAD, which can be obtained by issuing ACADPREFIX command. Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted May 16, 2011 Share Posted May 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Tyke Posted May 16, 2011 Author Share Posted May 16, 2011 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 Quote Link to comment Share on other sites More sharing options...
Ahankhah Posted June 22, 2011 Share Posted June 22, 2011 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.