Jump to content

Turning object snap on/off within a macro.


Mirkin

Recommended Posts

Hi all.

I've written my first two macros.

This one ^C^Cgrid on;;^C^Csnap on;;^C^Ccursorsize 100 turns the grid and snap on and expands the cursor.

This one ^C^Cgrid off;;^C^Csnap off;;^C^Ccursorsize 5 does the opposite.

I'm wondering if there is a way to turn object snap on and off within these macros as well. This would be a great help but I can't seem to find a command to do it.

Thanks in advance.

Link to comment
Share on other sites

  • Replies 26
  • Created
  • Last Reply

Top Posters In This Topic

  • Mirkin

    9

  • ReMark

    7

  • tombu

    4

  • YZ

    2

Top Posters In This Topic

You are running full AutoCAD so why not use lisp?

 

Re: OSnaps. Are you turning ALL osnaps on or just a select few? If it is a select few which ones would they be?

Link to comment
Share on other sites

Hi there.

Lisp is a completely foreign thing to me right now and I don't really have bundles of time to learn about it.

As for the snaps, yes I want to turn them all on and off.

Thanks

Link to comment
Share on other sites

A single lisp routine that would give the user the ability to enable, disable or change all/some of those settings using just two commands would be very simple and straight forward.

 

Are you sure you want all the osnaps enabled if you are using grid?

 

Where/how will you be controlling your settings for grid and snap spacing?

Edited by ReMark
Link to comment
Share on other sites

If you say its easy maybe I'll have a try.

What would the Lisp look like and how would I make it into a command that I could assign to a short cut key?

You have to explain like I know nothing about it, because I don't lol.

Remember I just wrote two macros and it took me a while.

Link to comment
Share on other sites

OK...think I got it now.

 

Here is a rather crude lisp routine that will enable or disable the settings as you choose. Use the APPLOAD command to load the program. The two commands for enabling or disabling the settings are DSE and DSD (Drawing Settings Enabled / Drawing Settings Disabled). I'm sure it could be more streamlined but I did this for demonstration purposes only.

 

Test5.lsp

Link to comment
Share on other sites

Are you talking to me?

 

The OP said he wanted ALL osnaps on. So I assume the opposite of that is ALL osnaps off. He did not use or mention the word "temporarily".

Link to comment
Share on other sites

First with your osnaps set the way you usually like them type osmode. Lets say it is 32. Your macro would be

^C^C_osmode;32; turns osnap on

^C^C_osmode;0; turns osnap off

 

 

I didn't test it but that is close anyway.

Link to comment
Share on other sites

Like Rkent just play with your osnap settings then type osmode the number that appears is important and you can use it either macro toolbar or lisp

 

(defun C:15 ()(setvar "osmode" 15359))   ; sets all snaps on
(defun C:00 ()(setvar "osmode" 0))   ; sets all snaps off
(defun C:39 ()(setvar "osmode" 47))
(defun C:99 ()(setvar "osmode" 99))
(defun C:8 ()(setvar "osmode" )
(defun C:59 ()(setvar "osmode" 15359))
(defun C:9 ()(setvar "osmode" 9))

Link to comment
Share on other sites

Cheers for all the advice.

I think I'll use osmode in my macro for now.

I have a few more questions.

1. Is there a way to switch between osnap and gridsnap while a command is active (move for example)

2. If I load the lisp routine into autocad using appload is it there forever or do I have to load it on each start?

 

Thanks again for the help.

Edited by Mirkin
Link to comment
Share on other sites

Re: APPLOAD. The code is loaded into the current drawing session.

 

A second method would be to load the code every time a new drawing is opened via acaddoc.lsp.

 

A third method involves the use of the Startup Suite to load your custom programs.

Link to comment
Share on other sites

As BIGAL said, the command:

(setvar "osmode" 0)

will turn off osnap

To turn osnap on just replace the 0 with a number that is the sum of the osnap modes you want to set where End = 1, Midpoint = 2, Center = 4, Node = 8, etc. (check the order in the osnap setting dialog box and double the number for the next mode). So, if you want to turn on osnap End, Midpoint, and Center it would be 1+2+4 = 7

(setvar "osmode" 7)

However, if you just want End and Center the command would be 1+4 = 5

(setvar "osmode" 5)

Link to comment
Share on other sites

I'm totally understanding how this works now.

Can anybody advise if its possible to turn the osnap on and off from a macro while while a command is active.

Cheers

Link to comment
Share on other sites

Can anybody advise if its possible to turn the osnap on and off from a macro while while a command is active. Cheers

That's why God invented the F3 key. Enable/Disable OSnaps.

Link to comment
Share on other sites

Check out F8 also and F6 & F? Etc If you want transparent changes and do not want to press F3 then you will have to write a lisp that changes the snaps grid in between doing something.

Link to comment
Share on other sites

Yes, you can have a macro that will alter the osnap and gridsnap settings while you have another command active.

 

If you start the command with an apostrophe it will run the command transparently, without cancelling the current active command, so you can continue, but with the settings now changed to how you want them.

 

It would look something like:

'OSmode;0;Snap;On;

 

You can also, if this is of interest, have your macro store your current settings and then restore them at the end of the macro. So while you are in that macro command the settings will be exactly as you want them for that task. Then once the macro has finished it can restore the setting so you can continue with your previous settings.

 

Or you can return them to a standard normal which will be as you would want them say 80% of the time anyway.

Link to comment
Share on other sites

I forgot to mention that in order to achieve the above you need to ignore the usual convention of opening a macro with ^C^C.

 

It literally starts with the apostrophe only.

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