sysvar OSNAPCOORD

Discussion in 'AutoCAD' started by Mark McDonough, Feb 23, 2004.

  1. From the sytems variable editor express tool, regarding OSNAPCOORD:

    Controls whether coordinates entered on the command line override running
    object snaps.

    0 Running object snap settings override keyboard coordinate entry
    1 Keyboard entry overrides object snap settings
    2 Keyboard entry overrides object snap settings except in scripts

    Does the OSNAPCOORD setting apply to lisp? I was tweaking a command to find
    the midpoint between two points, to be used transparently... works just fine
    UNLESS osnaps are on, then the osmode can override the resulting midpoint.
    If I (setvar "osmode" 0) all is good. But I was trying the osnapcoord
    setting, to see if it would effect the outcome, and apparently not.

    I wanted the lisp command to be well behaved, and reset whatever osnap might
    have been set, but can't seem to do that and deliver a midpoint value
    transparently at the same time.
     
    Mark McDonough, Feb 23, 2004
    #1
  2. Mark McDonough

    JamesA Guest

    I'm not sure I understand your question, but I'll give it a shot. I've
    never messed with the OSNAPCOORD var, but for a transparent point routine I
    use something like the following:

    (setq oldos (getvar "osmode"))
    (setvar "osmode" 0)
    (setq pt <your code>)
    (setvar "osmode" oldos)
    (command pt)

    And don't end with (princ)... Hope this helps

    James
     
    JamesA, Feb 24, 2004
    #2
  3. Thanks for offering up a suggestion. But it still doesn't work, because the
    lisp command's last line must evaluate to the point, and if there is an
    osnap set, the (setvar "osmode" oldos) BEFORE delivering the last point,
    ends up with osnap modes potentially interfering with the actual point.

    To explain a bit more, I have a lisp command named MIP (MId Point) that
    finds the point between any 2 selected points. So I can be in the LINE
    command, then enter 'MIP to start a line between two endpoint or
    intersection points on some other geometry. Works great most of the time.
    What if the user has an ENDP osnap mode set, then snaps to two opposite ends
    of the same line, and the lisp properly finds the midpoint, but the ENDP
    osnap will override that specified midpoint and will find an endpoint on the
    line instead.

    Why doesn't the person just use the MID osnap you ask (for that last
    scenario)... well, if you give people a command that finds the midpoint
    between any two points, then that's what it should do, even if they do
    something dumb like use the command to show two opposite endpoints on the
    same line.

    That's why I'm asking about the OSNAPCOORD system variable, because it's
    supposed to control the behavior of specific point input regardless of
    osmode setting, designed for keyboard input and scripts.... help says
    nothing about whether that setvar helps out when used from lisp.
     
    Mark McDonough, Feb 25, 2004
    #3
  4. Mark McDonough

    David Kozina Guest

    Mark,
    I understand that in AC2005 there will FINALLY be a new OSMODE for this!
    But for now - why don't you provide this ability in your POP0 button menu,
    using 'cal - something like so?:


    ***POP0
    **SNAPCURSOR
    [&Object Snap Cursor Menu]
    ID_Tracking [Temporary trac&k point]_tt
    ID_From [&From]_from
    [--]
    ID_CalMEE [MEE (Midpt. Between Endpts. P1 and P2)]_non '_.CAL MEE;
    ID_CalMPP [MPP (Midpt. Between any Two Pts. P1 and P2)]_non '_.CAL
    (cur+cur)/2;
    ID_CalOther [->Other Cal Functions]
    ID_Cal [Cal (3D Calculator Utility)]_non '_.CAL
    ID_CalILLE [ILLE (Int. of Lines defined by Endpts. P1 thru P4)]_non
    '_.CAL ILLE;
    ID_CalPLT [PLT (Point T* from Endpt. P1 toward Endpt. P2)]_non '_.CAL
    PLT(end,end,T);
    ID_CalPLD [PLD (Point T Units from Endpt. P1 toward Endpt. P2)]_non
    '_.CAL PLD(end,end,T);
    ID_CalT [T (Set T variable)]'_.CAL T=\
    [--]
    ID_CalCVUnit [<-cvunit (Convert Quantity,From,To)]'_.CAL cvunit(\
     
    David Kozina, Feb 25, 2004
    #4
  5. Mark McDonough

    ECCAD Guest

    Mark,
    In your routine, do:
    (setq old_osmode (getvar "OSMODE"))
    (setvar "OSMODE" 0)
    ...
    ... do stuff
    ...
    (setvar "OSMODE" old_osmode); reset old values on exit.

    Bob
     
    ECCAD, Feb 25, 2004
    #5
  6. Mark McDonough

    JamesA Guest

    You're right. My bad. Try putting the second setvar *after* (command pt).
    Will check back later to see if that worked for you. I think it will.

    Of course the return value to a calling lisp function has to be the last
    line evaluated. But because we are 'returning' the point using "command",
    it doesn't have to be the last line of the routine. I don't remember how I
    first came stumbled onto that revelation (well it was for me anyway... :),
    but it works here.

    James
     
    JamesA, Feb 25, 2004
    #6
  7. I tried what you suggest, putting the osmode setvar at the end, and was
    hoping that it would work like you suggest in your 2nd paragraph, but
    couldn't get it to work to transparent deliver the point value. Will try
    again in earnest tomorrow.
     
    Mark McDonough, Feb 25, 2004
    #7
  8. Mark McDonough

    JamesA Guest

    Good morning Mark. I believe this works how you want it to...

    (defun c:MIP (/ p1 p2 oldos)
    (setq p1 (getpoint "\nPick first point: ")
    p2 (getpoint p1 "\nPick second point: ")
    p1 (mapcar '(lambda (a b) (/ (+ a b) 2.0)) p1 p2)
    oldos (getvar "osmode")
    )
    (setvar "osmode" 0)
    (command p1)
    (setvar "osmode" oldos)
    )

    If not, does it:

    1. Run but still return the wrong point? Check other point mod. modes
    maybe? (orthomode, autosnap, snapmode, ...)
    2. Not run at all? You do have "defun c:<...>" right? And it looks like
    you are calling with the ' in 'MIP.

    Doesn't this work? Stay posted.

    James
     
    JamesA, Feb 26, 2004
    #8
  9. Excellent! That works. I guess it was the COMMAND function that does the
    trick.

    However, in my version I still have an odd problem. When asked for the 2nd
    point, if I hit ESC, I'd like the command to exit cleanly, but for some
    reason it's not working and mysteriously the P2 point is still getting a
    value:

    (defun c:MIP (/ p1 p2 p3 os)
    (setq os (getvar "osmode")
    p1 (getpoint "\nShow 1st point: ")
    )
    (princ "\nCalculate midpoint...")
    (if p1 (setq p2 (getpoint "\nShow 2nd point: ")))
    (setvar "osmode" 0)
    (if (and p1 p2)
    (setq p3 (mapcar '(lambda(a b)(*(+ a b 0.0) 0.5)) p1 p2))
    (princ "\n2 points not picked.")
    )
    (if p3 (command p3) (princ))
    (setvar "osmode" os)
    (setq os nil)
    (princ)
    )

    When I hit ESC on the 2nd point (e.g. the user changes his/her mind) then I
    get:

    Show 2nd point: *Cancel*
    ; error: Function cancelled
    Specify first point: Specify first point:
     
    Mark McDonough, Feb 26, 2004
    #9
  10. Mark McDonough

    JamesA Guest

    It sounds like you want a custom error handler. Look in your AutoCAD Help
    files: Developer Documentation->AutoLISP Developer's Guide->Using the
    AutoLISP Language->AutoLISP Basics->Error Handling->Using the *error
    Function.

    I also use *error* to reset any system variables I use in a routine (e.g.
    osmode). This way even when a user cancels the routine their settings are
    left how they had them when it started.

    James
     
    JamesA, Feb 26, 2004
    #10
  11. Thanks James,

    I didn't report back in here, but I did exactly as you suggest. Typically I
    include error-handler swappping code in my larger routines but didn't plan
    to on this smaller one. But I did get the behavior I wanted when adding the
    error handler.
     
    Mark McDonough, Feb 27, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.