Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP Routine to Load Particular Object Snaps

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
5487 Views, 13 Replies

LISP Routine to Load Particular Object Snaps

A lot of the LISP routines we use turn off all snaps except the "nearest" snap when the routine is complete.

 

I draw with 6 out of the 10 snaps on (not the nearest).

 

Can someone point me in the right direction of a LISP routine that loads specific object snaps?

 

Thanks,

13 REPLIES 13
Message 2 of 14
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....

Can someone point me in the right direction of a LISP routine that loads specific object snaps?

....


Set up the ones you want, then with running Osnap on, type OSMODE to find out the value of that System Variable.  Then:

 

(setvar 'osmode 1234)

 

will force that combination at any time [with your value in place of the 1234].

Kent Cooper, AIA
Message 3 of 14
Anonymous
in reply to: Anonymous

This is my $0.02 worth.  Write yourself a program what I call a mini program.   One that loads the running object snaps that you desire.  I wrote a few that for instance, I want the snaps of node and endpoint.  I hit the 9 key and those snaps get loaded.  I hit zero and it clears them to no snaps.  I hit 1 and the endp snaps get loaded, and so on and so on.  Hope this helps.

Message 4 of 14
stevor
in reply to: Anonymous

AN example, that show previous setting as a number:

 

(DeFun C:Oe () (P_osm) (COMMAND "osnap" "end")(princ " Osnap_End ") (princ))

 

 ; prin os mode
 (defun P_osm () (princ" OSm: ") (prin1 (getvar"osmode")) (princ" "))

 

Or, name it c:SE instead of OE, to make it quicker, by a one hand entry; or put them in buttons, etc.

 

The object Snaps are also on a tab on the drwing editor screen, of course.

S
Message 5 of 14
Anonymous
in reply to: Anonymous

This is what I use, its right along with Kent's comment (which I am sure is where I got the idea originally)

 

;;;----------------------------------------------------------------------------
;;;OSMODE 63
;;; turns on osnaps
;;;  endpoint midpoint center
;;;  node  quadrant intersection
;;;----------------------------------------------------------------------------

(DEFUN c:O63 ()
(setvar"osmode" 63) (SETVAR "AUTOSNAP" 63)
(PRINC)
)

Message 6 of 14
Anonymous
in reply to: Anonymous

+1

 

Good Lisp practice is to get any user defined settings that will be changed in the program at the beginning of the routine then load them back at the end of the routine.  i.e.:

 

(setq Snap (getvar "osmode"))  ;; in the beginning

;;; code ;;;

(setvar "osmode" Snap)  // at the end

 

(also for cmdecho, blipmode, etc. and any other common user settings)  (and if you have an error trap that exits out of the routine early, throw the setvar's in there too)  ...just my humble opinion

Message 7 of 14
scot-65
in reply to: Anonymous

Now my 2 cents worth...

Many times OSMODE is corrupted when one UNDO's a LISP program with a command inside.

The user tends to stop just before the command (and therefore after the SETVAR).

Same applies to the CMDECHO.

Then there are those not so perfect programs as well...

 

One resolve is to set up a "Custom User Section" inside acad, acaddoc, or MNL file that will employ

your initials.

Here is an example:

(defun c:USR ()

 (setvar 'OSMODE 559)

 (setvar 'CMDECHO 1)

)

Now, when these become corrupted, just type in your initials!

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 8 of 14
Anonymous
in reply to: Anonymous

I had a couple of hours free time so I've been reading up on error trapping.

 

good stuff here:

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Error-Trapping/td-p/2208173/highlight...

 

.... and other places.  just search on error trap and variations

 

I'm most interested at this point on how to reset variables when someone hits the ESC key before the routine is finished.

 

fun stuff it is

Message 9 of 14
coopdetat
in reply to: Anonymous

Kent wrote (paraphrased) "...(GETVAR "OSMODE") when osnaps are as you like them, then use that number in (SETVAR "OSMODE" ####) to reset them."

 

Kent has it exactly right.  That is the easiest way to set your osnaps.  You can put it in a custom command and assign it to any toolbar you want using CUI.  That number always represents those exact osnap settings.

 

The best practice is for the programs you use to store the current value of the system variables they change (e.g. OSMODE) when they begin and restore them when they end.  However, hitting [Esc] during the program will cause all such end-of-function resets to be skipped.  To account for this a custom error function is necessary.  The custom error function should include all of the resets for all of the system variables that were stored when the routine began.  It is easier to make a custom command / toolbar button to take care of the problem. 

 

For programmers who share their routines it is always good form to manage the system variables for the users.

---------------------------------------------Signature--------------------------------------------
Civil Design Professional Since 1983 (Intergraph), AutoCAD since 1989

Windows 10 Pro 64-bit Intel﴾R﴿ Core﴾TM﴿ i9-12900KF CPU 3.19GHz; 32 GB DDR4 4266 Dual Channel RAM
nVidia Quadro RTX 4000; AutoCAD Civil 3D 2023.2.1 Update
Message 10 of 14
dgorsman
in reply to: coopdetat

Trying to handle system variables prior to posting sample code can be a bit of work.  Its generally a good idea to evaluate all posted sample code in the context of your own system, and ensure/replace all procedures are compatible with what you are using.  Otherwise building whole code from samples can end up with unnecessary churn as each function pushes/pops values.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 11 of 14
Anonymous
in reply to: Anonymous

You're my snap soul mate 🙂

Sometimes I add insertion too though, depends how I'm feeling

Message 12 of 14
ritzofriya
in reply to: Anonymous

(setvar 'osmode x )

 

check attached table

Replace X with sum of snap values 

eg: if u want mid and end only  (setvar 'osmode 3)

 

osmode_system_variable.jpg

 

Message 13 of 14
Sea-Haven
in reply to: Anonymous

That post is ten years old !

Message 14 of 14
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

@Anonymous wrote:

Can someone point me in the right direction of a LISP routine that loads specific object snaps?


....

(setvar 'osmode 1234)

....


[Yes, 10 years old, but still valid, and useful for anyone looking for this kind of information.]

 

Another thought occurs to me:  If, instead of setting an inscrutable number into the OSMODE System Variable, you do it with an OSNAP command, such as this [the combination that I typically have running]:

 

(command "_.osnap" "END,MID,INT,PER")

 

then with the operation reported at the command line [that is, assuming this isn't buried inside a larger routine with command echoing suppressed], you can clearly see exactly which modes you just set.  This could be especially helpful if you have several little commands defined, or Tool Palette buttons coded, that set different combinations of modes, and you find the visual confirmation useful.

 

And even if it is buried inside something larger with command echoing suppressed, when going into the code to edit it in any way, it's similarly obvious exactly which modes are set, without the need to get out the chart and figure out the bits involved.  Of course, that can also be made clear with a comment after a (setvar) function, but if what you want to edit is actually the combination of modes, it's easier with the (command) approach that has the modes spelled out.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost