PDA

View Full Version : Write a macro that opens a specific drawing/template



Mr Cory
2007-02-12, 10:51 PM
Hay guys,

For the life of me i can not figure out how to write a lisp that opens a specific drawing/template!
What would the command be?

Thanks for any help!!

T.Willey
2007-02-12, 11:35 PM
Which style do you use Acad with? I mean MDI or SDI? Different calls per style. One you add the document to the document manager, and one you open it.

kennet.sjoberg
2007-02-12, 11:48 PM
If you want this ? (command "._new" "acad.dwt" )
i think you have to change the registry key "Default Template File Name for QNEW" to "acad.dwt"
before you run (command "._new" ) otherways I do not now how to let the "acad.dwt" as an argument in (command "._new" "acad.dwt" )

: ) Happy Computing !

kennet

Mr Cory
2007-02-13, 12:27 AM
MDI or SDI? (sorry) well basically we have to templates, ones a dwg and the other is a dwt. and i want to create a short cut that opens each i have tried (open "....") but that doesnt seem to seem to work.

abdulhuck
2007-02-13, 06:21 AM
MDI or SDI? (sorry) well basically we have to templates, ones a dwg and the other is a dwt. and i want to create a short cut that opens each i have tried (open "....") but that doesnt seem to seem to work.
Sorry, I didn't understand you completely. The idea of a template file is to start a new drawing from the scratch. If you are always using a typical template file, then you can create a shortcut in the desktop and launch AutoCAD from there with the new template file.

Create a shortcut in your desktop and enter the following line in the target field:

"C:\Program Files\AutoCAD 2005\acad.exe" /t MyTemplateName

You will have to change the path according to the version of your AutoCAD and give your template file name instead of MyTemplateNme. If your template file name includes spaces, then put them within double quotes (eg. "My template Name")

Regards,

Abdul Huck

Adesu
2007-02-13, 07:45 AM
Hi Cory,
Test this code,maybe suitable with you.


(defun c:test (/ filename path vgad vgao vgd)
(setq path "D:/xxx/yy/z/") ; change with your folder
(setq filename (getfiled "Select a Dwg File" path "dwg" 8))
(setq vgao (vlax-get-acad-object))
(setq vgad (vla-get-activedocument vgao))
(setq vgd (vla-get-documents vgao))
(if
(= 0 (getvar "SDI"))
(vla-activate (vla-open vgd filename)) ; if sdi = 0
(vla-sendcommand vgad (strcat "(command \"_open\")\n" filename "\n")); if sdi = 1
)
(princ)
)



Hay guys,

For the life of me i can not figure out how to write a lisp that opens a specific drawing/template!
What would the command be?

Thanks for any help!!

Mr Cory
2007-02-13, 07:36 PM
It was i want to be able to type the shortcut which opens the template so that if i want to make changes to it i dont have to go though the change drawing type etc (basically just want to make things quicker)

Adesu i tried that but i must have not done it correctly, see attached picture

david_peterson
2007-02-13, 08:14 PM
If this is specific just for you and for one template/drawing it gets real easy. Make a button


^c^cfiledia;0;sdi;0;open;"full drawing path you wish to open";filedia,1;

This is if you typically have sdi set to 1. You can't get the sdi back to 1 with both drawings open.
There's my 2 cents on the easy way.

Mr Cory
2007-02-13, 08:22 PM
That was how it was going to end up, as a button, so was is sdi/mdi????

It seems to open the last drawing i opened (not off the PN) :?

Opie
2007-02-13, 08:26 PM
That was how it was going to end up, as a button, so was is sdi/mdi????

It seems to open the last drawing i opened (not off the PN) :?
SDI = Single Document Interface
MDI = Multiple Document Interface

SDI only allows one drawing open at a time. MDI allows one or more to be open at a time.

Mr Cory
2007-02-13, 08:28 PM
Uhuh i see would that be why it doesnt work then? I normally have 3 or so drawings open

david_peterson
2007-02-13, 08:39 PM
In ADT (correct me if that's not what you're using) SDI always wants to be set to 0. ADT hates single drawing mode. I'm not sure on the MDI. I've never needed to change that one. But if you are using PN, you're kind of not allowed to open drawings without going through PN. Main reason is that it will mess up the file structure on your current project and may be saving a copy to a different location. I could be wrong, but you may need to be looking at .xml files to get this to work. If you simply want to open a template or drawing (Not associated to PN) you should be able to use the button code above. Don't forget that you need to use the full path ie p:\client\projectnumber\cad\adt\templates\companytemplate.dwt.
I'll try to find some time to test this, but I think what I gave you before should work.

Mr Cory
2007-02-13, 08:42 PM
Yea that files i want to open arent part of the project.

Heres the code from the button


^c^cfiledia;0;sdi;0;open;"Z:\10 - ADT System Files\All Users\Template\KGR - Template.dwt";filedia,1;

david_peterson
2007-02-13, 08:44 PM
Here's a little snip from the help files



Is the Project Navigator MDI compliant?

No. During a session of Autodesk® Architectural Desktop, only one project can be opened at a time. You can open files from different projects with the regular File mk:@MSITStore:C:Program%20FilesAutodesk%20Architectural%20Desktop%202005helpadt.chm::/images/ac.menuaro.gif Open command. You do not, however, see the associated project in the Project Navigator.


So I'm not sure what the work around is. I'm thinking that you may have to close PN before you can open something that's not in the current project. But I could be way wrong.
Opie, Any better ideas?

david_peterson
2007-02-13, 08:50 PM
Well the second "filedia" command isn't needed when using ADT and PN is active. Or at least the way mine is set up it's not. After you open a drawing I think ADT automatically re-sets it back to default ie 1.

Mr Cory
2007-02-13, 08:55 PM
I restarted ADT and its not using the file that is specficied in the macro, its remembering the last file that it was told to open

Opie
2007-02-13, 09:03 PM
David, I don't use ADT. The latest macro Cory has posted sets the SDI system variable to 0 which turns on the Multiple Document Interface.

Cory, you may need to change the backslashes in your folder / file string to double backslashes, "\\".

Opie
2007-02-13, 09:07 PM
Hi Cory,

Please note I have *moved* this thread from the AutoLISP Forum to this one as I feel this particular Forum is a more appropriate place for such a topic.

Thanks,

Richard
Forum Moderator

Mr Cory
2007-02-13, 09:09 PM
Double backslashes, All of them?

Cheers for moving it!

Opie
2007-02-13, 09:24 PM
Double backslashes, All of them?

Cheers for moving it!
It's only four of them. Plus, that is only a guess as I do not use macros often.

david_peterson
2007-02-13, 09:25 PM
Ok, I tried my code. It dosen't work. I'm not sure that PN Allows you to do this. The trick is to find a way around PN.

Mr Cory
2007-02-13, 09:27 PM
I tried it but it didnt seem to change anything, its not using the file path that is specified instead it is prompting and the last drawing opened is the default, if you follow? :?

david_peterson
2007-02-13, 09:38 PM
Hold on there Mr. Cory, the Calvary is on it's way. I'm starting to think that a macro may not work. But the good news it's that's not the only way to get to what you want. I've asked our Resident ADT guru Mr. Steve Bennett to take a peak when he gets a chance. He may have some good suggestions. Again personally I think this is an issue specific to ADT/ABS and PN. Then again maybe not. I just figure that anything (or sequence) that you can type in with out the dialog box coming up can be made into a marco, but I couldn't get this one to work in plain cad either. I keep getting prompted for the last file that it opened. It won't open it, so I can't seem to get past the path portion.

dzatto
2007-02-13, 09:39 PM
If you only have one template, just go into options and change the path under template settings, default template for QNEW, to your template location. Then when you need it, just hit the QNEW icon.

Mr Cory
2007-02-13, 09:46 PM
Its more if i want to make changes to the template itself, and to my styles drawing

Thats where im stuck,

david_peterson
2007-02-13, 09:47 PM
If you only have one template, just go into options and change the path under template settings, default template for QNEW, to your template location. Then when you need it, just hit the QNEW icon.Hi Dan,
Dosen't that just start a new drawing from a template? I think what he wants to do is open the template to edit it. ie He's working on some drawings and thiinks of something that needs to be fixed in his template (becuase he's testing it) and hits the button. Or at least that's my understanding.

Mr Cory
2007-02-13, 09:48 PM
Spot on David, sorry i didnt explain it very well

Steve_Bennett
2007-02-13, 09:49 PM
If you only have one template, just go into options and change the path under template settings, default template for QNEW, to your template location. Then when you need it, just hit the QNEW icon.What dzatto said...

It seems to me that your are trying to get it to do what it already can do using qnew.

Thanks for the guru reference, but honestly this is out of my relm (making macros that is...) - my understanding is that if a macro works in vanilla acad, then it should work in ADT as well. As far as getting macros to control stuff in PN, good luck and let me know if you find a way.

:beer:

dzatto
2007-02-13, 09:51 PM
Hi Dan,
Dosen't that just start a new drawing from a template? I think what he wants to do is open the template to edit it. ie He's working on some drawings and thiinks of something that needs to be fixed in his template (becuase he's testing it) and hits the button. Or at least that's my understanding.
Oh..... But wouldn't you need to open the template to edit it? When I created my templates, I would just QNEW to open it, make my changes, then save as and pick .dwt from the drop down, pick the template from the list and save it.

Mr Cory
2007-02-13, 09:52 PM
Thats another way to do it

Steve_Bennett
2007-02-13, 09:54 PM
Hi Dan,
Dosen't that just start a new drawing from a template? I think what he wants to do is open the template to edit it. ie He's working on some drawings and thiinks of something that needs to be fixed in his template (becuase he's testing it) and hits the button. Or at least that's my understanding.Then what about a shortcut of the item on the desktop?

Steve_Bennett
2007-02-13, 09:56 PM
Then what about a shortcut of the item on the desktop?nevermind. that just makes a new dwg

Mr Cory
2007-02-13, 09:56 PM
That only works for the dwg, it actions the same as qnew if you open a template in explorer

david_peterson
2007-02-13, 09:58 PM
Then what about a shortcut of the item on the desktop?Now there's an outside the box idea. Create an icon on your desktop set to open the template that you want to modify. Then you can simply pick on the little windows "show desktop" icon and you can open it directly. Only problem there is waiting for it to launch another session of ADT. I'm still thinking that there's a way around this using a basic button or a right click maybe that acts like the "open x-ref" command but you don't have to select what you want to open because you already know that.

Opie
2007-02-13, 09:59 PM
Will this post, "Opening new template in LISP" help?

david_peterson
2007-02-13, 10:06 PM
Will this post, "Opening new template in LISP" help?Thanks Opie, Looks like that one should work.

Steve_Bennett
2007-02-13, 10:11 PM
Thanks Opie, Looks like that one should work.Yeah, that would work. Just tested it. You can only have 1 dwg open when running the command in that lisp that rkmcswain posted.

Mr Cory
2007-02-13, 11:16 PM
Sweet cheers guys!! Thanx for all your help!

kennet.sjoberg
2007-02-13, 11:44 PM
Yeah, that would work. Just tested it. You can only have 1 dwg open when running the command in that lisp that rkmcswain posted.
yes, but you should try his last post
(vl-load-com) with
(vla-Add (vla-get-Documents (vlax-get-acad-object)) "acad.dwt")

: ) Happy Computing !

kennet

Mr Cory
2007-02-14, 12:32 AM
Grr is it just me or does it flick back to the drawing you had open?

Mr Cory
2007-02-14, 01:09 AM
Cancel that, just clicked it was opening the template file itself, just a new drawing created from that template

Mr Cory
2007-02-16, 04:34 AM
filedia;0;_open;"Z:/10 - ADT System Files/All Users/Template/KGR - Template.dwt";filedia;1

Anyone know why this does work? in theory it should work but no...

Mr Cory
2007-02-21, 08:43 PM
Hay guys no luck with the first problem, now i have another one lol, im trying to write macro that inserts a specfic block (which is already in the drawing) but i keep getting this message

Heres the marco: _.-insert;"text syles 100";

Any thoughts?

Opie
2007-02-21, 08:54 PM
Hay guys no luck with the first problem, now i have another one lol, im trying to write macro that inserts a specfic block (which is already in the drawing) but i keep getting this message

Heres the marco: _.-insert;"text syles 100";

Any thoughts?
The message means that AutoCAD cannot find the file you are trying to insert.

jaberwok
2007-02-21, 09:30 PM
Hay guys no luck with the first problem, now i have another one lol, im trying to write macro that inserts a specfic block (which is already in the drawing) but i keep getting this message

Heres the marco: _.-insert;"text syles 100";

Any thoughts?


should "syles" be "styles" ?

abdulhuck
2007-02-22, 06:32 AM
Heres the marco: _.-insert;"text syles 100";

Hi,

Give the path for the block, ie,



^c^c_.insert;"C:/Path/text styles 100.dwg";


Regards,
Abdul Huck

Mr Cory
2007-02-28, 09:56 PM
Sorry i havnt replied, i hadnt recieved any emails about this thread being updated grrr.

jaberwok, you are correct, sign man i feel like a spoon!!! :Oops: :Oops::Oops:Cheers Guys

Sigh :Oops:

Is there anyway to make it insert at the centre of the current display?