Jump to content

Recommended Posts

Ok so to give a little background what is going on I have Autocad 2010 with Rastercad Add on. I want to create a macro that will let me open a new drawing hit enter(for the basic autocad templete) and then run the command gattach which will open a window that will allow me to open my raster image. I can not get the new command to open the dwg templete without asking me. Here is what i have so far:

 

^C^C_new ;-Gattach:(

Link to comment
Share on other sites

  • Replies 30
  • Created
  • Last Reply

Top Posters In This Topic

  • clydemit

    12

  • Jack_O'neill

    11

  • BlackBox

    8

Top Posters In This Topic

Posted Images

You need to use Visual LISP.

 

Look into the vla-Add , and vla-Activate Methods of the Documents Object, and the resultant Document Object respectively.

Link to comment
Share on other sites

put this on a toolbar button:

^c^c filedia 0 _new ; filedia 1 -gattach.

 

I don't have the rastercad addon you mentioned, but this works when I substitute ._move for -gattach. you may have to play with the gattach command a bit, but the first part will get you around the dialog box

Link to comment
Share on other sites

Example:

 

Macro:

^C^C(if (not c:[color=red]FOO[/color])(load "[color=red]FOO[/color]"));[color=red]FOO[/color]

 

FOO.lsp code:

(defun c:[color=red]FOO[/color]  ( / oAcad)
 (vl-load-com)
 (vla-activate
   (vla-add
     (vla-get-documents (setq oAcad (vlax-get-acad-object)))
     (vla-get-qnewtemplatefile
       (vla-get-files (vla-get-preferences oAcad)))))
 (princ))

 

Simply replace all instances of "FOO" with whatever name you want.

Link to comment
Share on other sites

put this on a toolbar button:

^c^c filedia 0 _new ; filedia 1 -gattach.

 

I don't have the rastercad addon you mentioned' date=' but this works when I substitute ._move for -gattach. you may have to play with the gattach command a bit, but the first part will get you around the dialog box[/quote']

 

I also do not have the add-on; if that works, then great.

Link to comment
Share on other sites

I also do not have the add-on; if that works, then great.

 

Sorry...started that answer, then got a phone call. By the time I finished and got back to it, your answer (which might be the better one) was there. The "filedia 0" part turns that dialog box off, "new" is obvious, the ; after it is an enter of course (causing it to use whatever default template you have set), then "filedia 1" turns the dialog box back on. After that, any command should work in the format you would use if you typed it in on the command line.

Link to comment
Share on other sites

put this on a toolbar button:

^c^c filedia 0 _new ; filedia 1 -gattach.

 

I don't have the rastercad addon you mentioned' date=' but this works when I substitute ._move for -gattach. you may have to play with the gattach command a bit, but the first part will get you around the dialog box[/quote']

 

 

I will try this then get back to you.

Link to comment
Share on other sites

put this on a toolbar button:

^c^c filedia 0 _new ; filedia 1 -gattach.

 

I don't have the rastercad addon you mentioned' date=' but this works when I substitute ._move for -gattach. you may have to play with the gattach command a bit, but the first part will get you around the dialog box[/quote']

 

 

It was a no go it wants me to hit enter for each command it wont enter itself (enter meaning execute) within the new part of the command

 

Could it have something to do with a setting i have on that i dont know about?

Link to comment
Share on other sites

Well, heckydurn as my wife would say. It worked here, several times...but now I can't get it to do it again. Ok...so that apparently don't work after all. Sorry. See Renderman's answer, maybe his will.

 

This is very annoying. I sat here and ran it several times...each time it opened a new drawing...hmmm. If I get it fixed, I'll post what did. Its probably something pretty obvious that I'm just overlooking. Sitting there waving it's little arms at me I'm sure.

 

Did find one mistake...there should be no space between the two cancels and the first "filedia".

 

I will figure this out.

Link to comment
Share on other sites

Well' date=' heckydurn as my wife would say. It worked here, several times...but now I can't get it to do it again. Ok...so that apparently don't work after all. Sorry. See Renderman's answer, maybe his will.

 

This is very annoying. I sat here and ran it several times...each time it opened a new drawing...hmmm. If I get it fixed, I'll post what did. Its probably something pretty obvious that I'm just overlooking. Sitting there waving it's little arms at me I'm sure.

 

Did find one mistake...there should be no space between the two cancels and the first "filedia".

 

I will figure this out.[/quote']

 

I also noticed a space after new command does not enter it starts typing so is there a way to use enter instead of spacebar to do commands?

Link to comment
Share on other sites

Example:

 

Macro:

^C^C(if (not c:[color=red]FOO[/color])(load "[color=red]FOO[/color]"));[color=red]FOO[/color]

 

FOO.lsp code:

(defun c:[color=red]FOO[/color]  ( / oAcad)
 (vl-load-com)
 (vla-activate
   (vla-add
     (vla-get-documents (setq oAcad (vlax-get-acad-object)))
     (vla-get-qnewtemplatefile
       (vla-get-files (vla-get-preferences oAcad)))))
 (princ))

 

Simply replace all instances of "FOO" with whatever name you want.

 

 

are all the ( ) needed or were they to separate?

Link to comment
Share on other sites

I also noticed a space after new command does not enter it starts typing so is there a way to use enter instead of spacebar to do commands?

 

Space should do the same as the enter, but so should the ";" (semi colon) and ^M but none of them are making it do it. Gonna jump over to the other machine and try in on 2007

Link to comment
Share on other sites

are all the ( ) needed or were they to separate?

 

Yeah, they are all needed. Lisp has been humorously refered to as "Lost In Superfluous Parentheses". For every open, you have to have a closed one.

Link to comment
Share on other sites

Well, I think I figured it out. Apparently the fact that it worked a few times was an abberation. The sequence will work for any string of commands you want to put in it, except one that opens a new drawing. Apparently once it pops the new one open, it forgets that its running a toolbar macro from the previous one.

 

Now that I think back on it, I think I know why it worked when it wasn't supposed to too. In one of the first attempts that didn't work, I don't think I closed that drawing window. I think I hit the minimize button instead, and I remember manually opening a new window. When I hit the button for the macro, I think that having that other window open allowed it to run. That's just a theory that happens to fit the facts, and I haven't tested that to find out. In any case, it ain't gonna work.

Link to comment
Share on other sites

Well' date=' I think I figured it out. Apparently the fact that it worked a few times was an abberation. The sequence will work for any string of commands you want to put in it, except one that opens a new drawing. Apparently once it pops the new one open, it forgets that its running a toolbar macro from the previous one.

 

Now that I think back on it, I think I know why it worked when it wasn't supposed to too. In one of the first attempts that didn't work, I don't think I closed that drawing window. I think I hit the minimize button instead, and I remember manually opening a new window. When I hit the button for the macro, I think that having that other window open allowed it to run. That's just a theory that happens to fit the facts, and I haven't tested that to find out. In any case, it ain't gonna work.[/quote']

 

 

I replaced the new command with the macro to be able to use it with out any drawings open but it still asks me to hit enter, then if i do it while i another drawing open from doing this macro the first drawing finishes its macro. Very odd.

Link to comment
Share on other sites

You need to use Visual LISP.

 

Look into the vla-Add , and vla-Activate Methods of the Documents Object, and the resultant Document Object respectively.

 

Well' date=' I think I figured it out. Apparently the fact that it worked a few times was an abberation. The sequence will work for any string of commands you want to put in it, except one that opens a new drawing. Apparently once it pops the new one open, it forgets that its running a toolbar macro from the previous one.

[/quote']

 

Jack,

 

The reason for my initial post is that AutoLISP / DIESEL are drawing level APIs that can only function properly within the drawing in which they are invoked. Visual LISP on the other hand can tap into the ActiveX COM API (similar to that of the former VBA), which is an application level API... hence the ability to access the "Application" (AutoCAD) Object, the "Documents" Object, and even external Objects such as "Scripting.FileSystemObject", "Outlook.Application" Object, etc.

 

The code I posted (post #4) will successfully open a new drawing based upon the QNew Template File (DWT) specified in the active Profile's Files tab. My code stops there, as I did not include the functionality to change Document NameSpaces (post vla-activate call) and pass the command call specified in the OP. However, this will hopefully demonstrate that it is possible (you guys get to do the fun part, so read up! LoL).

 

Hope this helps!

Link to comment
Share on other sites

Jack,

 

The reason for my initial post is that AutoLISP / DIESEL are drawing level APIs that can only function properly within the drawing in which they are invoked. Visual LISP on the other hand can tap into the ActiveX COM API (similar to that of the former VBA), which is an application level API... hence the ability to access the "Application" (AutoCAD) Object, the "Documents" Object, and even external Objects such as "Scripting.FileSystemObject", "Outlook.Application" Object, etc.

 

The code I posted (post #4) will successfully open a new drawing based upon the QNew Template File (DWT) specified in the active Profile's Files tab. My code stops there, as I did not include the functionality to change Document NameSpaces (post vla-activate call) and pass the command call specified in the OP. However, this will hopefully demonstrate that it is possible (you guys get to do the fun part, so read up! LoL).

 

Hope this helps!

 

Yeah, it just didn't occur to me at the time. I use lots of little macros to do lots of stuff, and just wasn't thinking that far ahead. Once it dawned on me what I was asking it to do, I realized it was one of those stupid fish moments (you know...dumb bass). The odd set of conditions that allowed it to work when it normally won't is what screwed me up. I kept thinking, "I sat here and watched it work a dozen times...it's got to work again". Oh well, thats what I get for sitting here running through my little maze every day instead of finding things to keep the edge sharp.

Link to comment
Share on other sites

No worries.

 

This is the oldest macro I have, and I still use it daily:

 

^C^C._qsave;._open;

 

I've tried making this more complete, add extras, etc., but once the "open" call is made, no additional code will function (without writing it in VL).

Link to comment
Share on other sites

No worries.

 

This is the oldest macro I have, and I still use it daily:

 

^C^C._qsave;._open;

 

I've tried making this more complete, add extras, etc., but once the "open" call is made, no additional code will function (without writing it in VL).

 

Turn it into a script. I've got one here somewhere that will open a drawing, purges, replaces an old company logo with a new one, zooms all and saves, then goes on to the next drawing in the list and repeats.

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