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,
@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].
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.
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.
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)
)
+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
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.
I had a couple of hours free time so I've been reading up on error trapping.
good stuff here:
.... 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
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.
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.
(setvar 'osmode x )
check attached table
Replace X with sum of snap values
eg: if u want mid and end only (setvar 'osmode 3)
@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.