Jump to content

Creating Custom Keyboard Shortcuts with Multiple Object Snaps.


Recommended Posts

Posted

Greetings, everyone.

 

I've been using AutoCAD on and off for the last couple of years but unfortunately I seem to have missed out on learning what appears to be basic / common knowledge amongst the community.

 

When I try searching for solutions to my issues they are always written in ways which seem to assume the reader already understands how to get to a certain point, or is familiar with customising AutoCAD.

 

I've always used AutoCAD (currently 2018) on computers which have been setup by someone else to use their own LISP and PGP files with custom settings, etc.

 

I've tried to find articles which explain the basics (such as what LISP and PGP files actually do and how they work), but it seems a lot harder than it should be to find anything.

 

Currently my biggest issue is understanding how to create my own keyboard shortcuts, especially for Object Snaps.

 

The LISP file I'm using already has some custom shortcuts set up, as per below:

 

;;;OBJECT SNAP SETTINGS:
(defun c:oem ()
  (setvar "osmode" 3)
  ;;OSNAP ENDPOINT AND MIDPOINT
)
(defun c:oo ()
  (setvar "osmode" 14)
  ;;OSNAP ENDPOINT AND MIDPOINT AND CENTER
)
(defun c:oep ()
  ;;OSNAP ENDPOINT AND PERPENDICULAR
  (setvar "osmode" 129)
)
(defun c:oei ()
  ;;OSNAP ENDPOINT AND INTERSECTION
  (setvar "osmode" 33)
)
(defun c:oen ()
  ;;OSNAP ENDPOINT AND NEAREST
  (setvar "osmode" 513)
)
(defun c:oenn ()
  ;;OSNAP ENDPOINT AND NODE
  (setvar "osmode" 9)
)
(defun c:ocm ()
  ;;OSNAP CENTRE AND MIDPOINT
  (setvar "osmode" 6)
)
(defun c:omn ()
  ;;OSNAP MIDPOINT AND NODE
  (setvar "osmode" 10)
)

 

I've tried adding to and editing these to create my own shortcut but it doesn't work.

 

Basically I want to create a keyboard shortcut (Command: OO) which turns on the following Object Snaps:

 

  • Endpoint
  • Midpoint
  • Centre (Center)
  • Node
  • Intersection
  • Perpendicular
  • Apparent Intersection
  • Parallel

 

I know most people don't like to work with so many turned on at the same time but this just works for me.

 

It's especially frustrating as whenever I use the Leader or MText command it automatically switches all Object Snaps off and turns on the Nearest Snap only.

 

I have no idea how to change this so that it doesn't alter my Object Snaps, so every time I use either the Leader or MText command I have to manually turn off the Nearest Snap then turn all 8 of my regular Snaps back on.

 

I've tried searching for ways to set default Object Snaps but haven't come across anything.

 

I did find an article which mentioned each Snap having its own value and needing to create a command which equals the total value, but this didn't make any sense to me.

 

I apologise if I seem stupid or ignorant, but I have literally spent weeks looking for solutions and it's just getting so frustrating.

 

I've even tried watching Lynda videos but they don't seem to cover these types of things.

 

Any help would be greatly appreciated, as the guy who was like a Mentor to me and essentially got me started just seems to get frustrated when I ask how to do what are probably simple things (he's an insanely good Facade Engineer with more years AutoCAD experience than I have in life) :(

 

Thanks again,

 

 

Scottie.

acad.pgp ben2017.lsp

Posted

Endpoint = 1

Midpoint = 2

Center = 4

Node = 8

Intersection = 32 Not needed if Apparent Intersection is set.

Perpendicular = 128

Apparent Intersection = 2048

Parallel = 8192

So setting OSMODE to that total of 10415 or 10383 (without unneeded Intersection snap) is what you're looking for.

Adding a macro like 

'setvar;osmode;$M=$(if,$(=,10415,$(getvar,osmode)),0,10415)

would toggle between the settings you're looking for and off completely.

Defining 100 commands for every combination you might use seems excessive. I use a shortcut menu that includes all the ones I use without defining a single command.  

Many of the ones in that lisp would conflict with ones installed with verticals like Civil 3D.

  • Like 1
Posted (edited)

Like tombu just set your osnaps to what you want then type osmode and write down the number.

 

I have all my defun snaps set to a number rather than a hard to type string ie 47 (defun c:47 ()(setvar 'osmode 47)) I have like 4 in total. 99=1023

 

Something else you can do is shift+right button mouse to do temporary osnap.

 

The other thing is you can do transparent changes within commands by using eg Line pick '47 pick, note the single apostrophe. Look into 'cal as well has some good routines. M2P also.

 

Edited by BIGAL
  • Like 2
Posted

G'day, guys. 

 

Thank you so much for taking the time to respond and providing the information. 

 

As I originally said, my understanding of customising AutoCAD (and even changing some of its deeper settings) is very, very basic, so I'm not really sure how to actually do what you have suggested :(

 

How exactly do I set the OSMODE to that value? Furthermore, will this permanently set those 7 or 8 snaps to on? 

 

Also, where and how do I create macros? Do I have to edit the LISP / PGP file, or are these completely unrelated? 

 

The part about the "Line Pick" means literally nothing to me.

 

I'm looking to learn as much as I can about AutoCAD, so if you guys have any suggestions on further reading they would be very welcome. 

Posted

For starters get as familiar with the AutoCAD interface as you can. The icon on the right end of the status bar controls the display of everything on it. With 2D Osnap displayed you have full control of setting all you snaps and toggling them on and off. 

 

You can enter OSMODE at the command line and enter a value or while in a command use an apostrophe prefix to make it transparent as in 'OSMODE 10415.

 

As we use different osnaps for different purposes it wouldn't make any sense to permanently set any of them. 

  • Like 1
Posted
7 hours ago, Scottie Fox said:

As I originally said, my understanding of customising AutoCAD (and even changing some of its deeper settings) is very, very basic, so I'm not really sure how to actually do what you have suggested :(

 

How exactly do I set the OSMODE to that value? Furthermore, will this permanently set those 7 or 8 snaps to on? 

 

On the status bar, along the bottom of the window, there's a button for setting object snap modes. (If you don't have a status bar, type the command STATUSBAR and change it from 0 to 1 [0=off, 1=on].) Button designs change from one version to the next, so I'm not sure what you'll see*. In my version (2014), it's a square with a spark in the top left corner. If you only click on the button, you turn the entire object snap system on and off. If you right click on that button, you will see a list of snaps so you can choose which one to turn on/off. That list also includes a Settings option, which opens the Object Snap dialog (you can open that same dialog with the command _OSNAP). The dialog box lists all the available snap modes in one place and lets you toggle them on and off. Once you hit OK, the settings remain in place until the next time you change them. Some snap settings only last for the duration of a command.

 

You'll find that AutoCAD usually has several methods for doing the same thing. It's confusing at first, but you'll appreciate the flexibility it gives you. For instance, some prefer the ribbon, some the mouse, some the keyboard. Once you've learned the basics, you can decide what works best for you.

 

Unfortunately, AutoCAD has a steep learning curve. Once you've got your feet underneath you, though, you will have a lot of power.

 

*They claim the meanings of these icons are "self-explanatory." If that's so, why do they change every year?

  • Like 1
Posted

Scottie Fox You are on the right track with the shortcuts you have in your post. I have a single library lisp that gets loaded at startup, I prefer this method to adding to Autocad default startup lisps that get loaded. So will keep going down this method.

 

So make a lisp you can call it Scottie.lsp if you want, then type Appload, choose your Scottie.lsp and load it, this makes it available to only the current dwg. So next step is add it to Start up suite. Just click on it and add.  Inside my autoload.lsp there are 40 short defuns and 34 autoloads.

 

Tombu and I are talking about transparent commands these can be used in the middle of a command as example when doing pline you can type snaps like "end" "mid" or reset your osnaps by typing a apostrophe and the defun name hence Line '9 then pick a point with snap now set to end and node as per your post. At end to reset osnaps just type say 47 as a command (my defun)

 

When writing programs and testing, osnap often gets reset so having a shortcut comes in handy to reset it back.

 

Don't forget F3 is on / off

 

image.thumb.png.e6dee88a06a75e005ab2cc633a1e7180.png

  • Like 1
Posted

Thanks again everyone for all your help; I'm admittedly still a little confused but at least I'm heading in the right direction! 

 

Unfortunately I don't have AutoCAD at home and am now on holidays for a couple of weeks, but as soon as I can get to a PC with AutoCAD on it I'll test out what you've taught me and let you know how I go :)

Posted
On 12/18/2019 at 11:11 PM, Scottie Fox said:

I've always used AutoCAD (currently 2018) on computers which have been setup by someone else to use their own LISP and PGP files with custom settings, etc.

 

Learning how to use AutoCAD without any customizations is absolutely necessary before learning how to customize.

  • Like 1
  • 1 month later...
Posted

Happy New Year to everyone! (I know it's late but I've been busy with other stuff at work).

 

Anyway, I'm definitely not doing something correctly, lol.

 

I tried following the instructions on here about creating a macro (see attached image), and I thought everything looked good.

 

However, when I type the command (OO in this case) it appears on the screen (see other attached image) but then the "Oops" command is activated, completely skipping mine.

 

The OSMODE part worked, but it's too much to type each and every time.

 

Can someone please point out where I am going wrong?

 

Also, does adding a macro add the command into my LISP file so it will work on all drawings, or do I have to do it for every drawing?

 

Thanks again for all your help and time, you guys are awesome :)

Custom_Command_Image_2.jpg

Custom_Command_Settings.jpg

Posted

Make your own lisp file as I suggested earlier, there is no reason why your desired snaps can not be like 1 2 3 4 as commands just checked appear to be not used.

Command: 2
Unknown command "2".  Press F1 for help.

 

As offered earlier can do transparent commands, Line '2 pickpoint '4 pickpoint note the apostrophe before the number implies transparent use. or 2 then Line. 

 

Same with macros they can be simple or very long, generally for long code save as a separate lisp can use the shortcut to load it and run.

Posted

Putting OO in as a Command Display Name doesn't make it a command.

Easiest way would be to add (defun C:OO ()(setvar "OSMODE" 14503)) to your acaddoc.lsp file.

I've modified our 'Object Snap Cursor Menu' with a flyout for commonly used Osnap settings and toggles for a few other settings as well.

image.thumb.png.dc3c6e950313c2785d174e29e6bed415.png

Posted (edited)

Tombu I prefer to not to add to acaddoc.lsp 1st its buried deep directory wise, when you do an upgrade must redo acaddoc.lsp. It does not take much to use appload and add to startup only needs to be done once. My auto has like 25 defuns and same number of Autoload. Its on a server so everybody gets the update straight away if use Acaddoc have to go to every pc.

Edited by BIGAL
Posted

I've never tried appload to be honest. There used to be lots of issues with it posted online but I haven't seen any in a while so they may have gotten the bugs out now. Don't you have to load every lisp in a dialog box for it to work? Sounds tedious to me compared to simply adding acad.lsp, acaddoc.lsp along with cuix, lin, mnl, pgp and other customization files with a batch file in a few seconds to the "roamablerootprefix" folder with each upgrade. 

Posted (edited)

Your startup lisp can have autoload statements so when you type a command the lisp will load automatically. They need to be in support path. My "autload.lsp" has 25+defuns and about same autoloads.

The other advantage was fornetwork of users only saved on the server so only ever one version. Same with custom mnu files. 

(autoload "COPY0" '("COPY0"))
(autoload "COPYCOMMAND" '("ZZZ"))
(autoload "COVER" '("COVER"))
(autoload "DIMFLIP" '("DIMFLIP"))
(autoload "DRAWXFALL" '("DRAWXFALL"))
(autoload "DRAWPIPE" '("DRAWPIPE"))

Other lisps are loaded from menu's or toolbars. 

Edited by BIGAL
Posted
On 1/24/2020 at 3:27 PM, BIGAL said:

Make your own lisp file as I suggested earlier, there is no reason why your desired snaps can not be like 1 2 3 4 as commands just checked appear to be not used.

Command: 2
Unknown command "2".  Press F1 for help.

 

As offered earlier can do transparent commands, Line '2 pickpoint '4 pickpoint note the apostrophe before the number implies transparent use. or 2 then Line. 

 

Same with macros they can be simple or very long, generally for long code save as a separate lisp can use the shortcut to load it and run.

 

G'day, Big Al!

 

Sorry I missed your suggestion earlier; I was under the impression that you could only use one LISP file at a time which just left me confused.

 

May I ask what the advantage is to creating a second LISP file, rather than just modifying the existing one I use (which I included in my original post)?

 

I've also been reading Tombu's suggestions and if I understand correct when he / she refers to editing their "acaddoc.lsp file" that is the main / only LISP file they actually use?

 

Can someone please either alter my existing LISP file to include the command I need, or create a new LISP file with the command inside so I can try both ways?

 

It would appear that I really need to learn about macros and how they affect PGP and LISP files, but I just don't know where to start?

 

I'm not bad with formulas on Excel, but there are so many books and videos out there for Excel and very little about AutoCAD.

 

Please note I'm not trying to be lazy, I'm just getting a little overwhelmed as I'm being pulled in different directions and I really don't understand enough about either to know which would suit me better.

 

I've even started looking for local people who offer private lessons, but of course they aren't cheap, and I know with the right guidance / instructions I should be able to figure this out.

Posted
On 1/24/2020 at 9:00 PM, tombu said:

Putting OO in as a Command Display Name doesn't make it a command.

Easiest way would be to add (defun C:OO ()(setvar "OSMODE" 14503)) to your acaddoc.lsp file.

I've modified our 'Object Snap Cursor Menu' with a flyout for commonly used Osnap settings and toggles for a few other settings as well.

image.thumb.png.dc3c6e950313c2785d174e29e6bed415.png

 

Hi, Tombu.

 

I tried searching Windows for the "acaddoc.lsp" file you mentioned but couldn't find anything, so I presume this is just the name you use (whereas mine is currently called ben2017.lisp)?

 

I tried adding that command as you suggested but it's still not recognising it when I type "OO"; I've attached a screen shot of the edited LISP file I am using in my Startup Suite.

 

Where am I going wrong? I tried closing and reopening AutoCAD with no luck.

 

Also, I found an online course which seems to deal with Macros and the like: https://www.udemy.com/course/practical-autolisp-programming-beginner-to-advanced/

 

What do you guys think? Would this be an ideal course for me to take?

 

Cheers.1880386377_EditedLISPFile.thumb.jpg.edab1b372f8bdcdf2e7d692b15b63c7f.jpg

 

 

Posted

Some useful links:

https://www.cadtutor.net/forum/topic/51506-acadlsp-and-acaddoclsp/

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/acad-lsp-vs-acaddoc-lsp/td-p/883468

ACAD.lsp, ACADDOC.lsp, and ACAD.rx are user defined files, they aren't part of the program/install.

If you want to have one, you can create your own. They were designed by AutoCAD to be helpful user files if we create them.

 

ACAD.lsp loads automatically every time you open an AutoCAD session which is great for some things. 

ACADDOC.lsp loads automatically every time you open a drawing which is best for loading lisp you need all the time.

If you place a list of arx files in ACAD.rx they will be automatically loaded as well.

 

These files have obvious advantages over ben2017.lsp (lisp is not an extension). 

 

You need to understand TRUSTEDDOCDOMAINS and TRUSTEDDOCPATHS as well.

Posted
13 hours ago, tombu said:

Some useful links:

https://www.cadtutor.net/forum/topic/51506-acadlsp-and-acaddoclsp/

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/acad-lsp-vs-acaddoc-lsp/td-p/883468

ACAD.lsp, ACADDOC.lsp, and ACAD.rx are user defined files, they aren't part of the program/install.

If you want to have one, you can create your own. They were designed by AutoCAD to be helpful user files if we create them.

 

ACAD.lsp loads automatically every time you open an AutoCAD session which is great for some things. 

ACADDOC.lsp loads automatically every time you open a drawing which is best for loading lisp you need all the time.

If you place a list of arx files in ACAD.rx they will be automatically loaded as well.

 

These files have obvious advantages over ben2017.lsp (lisp is not an extension). 

 

You need to understand TRUSTEDDOCDOMAINS and TRUSTEDDOCPATHS as well.

Hello, again!

 

Thank you for the links and additional information; I'll definitely do some further reading and will likely watch that tutorial series I linked also.

 

In the meantime, would it be possible for you to create an ACADDOC.lsp file for me with the macro / command I'm after then send me instructions / screen shots on how to activate it?

 

At least this way I'll have an actual working example to work with and learn from?

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