Not getting Osnap

Discussion in 'AutoCAD' started by ffejgreb, Feb 19, 2004.

  1. ffejgreb

    ffejgreb Guest

    I am writing a routine that is a series of autocad commands wrapped in a
    defun. I would like to force an osnap at certain points in the commands
    where you would be pausing for user input, but can't figure out how to do
    it. Below is the routine. Before anyone comments on the formatting of the
    program, the book I am using to teach myself (ABC's of AutoLISP) uses this
    convention and it makes sense to me. I would like to use NEAREST when
    setqing p1 & p2 and use ENDPOINT when completing A2 (this would snap to the
    end of the arc of A1). I have another issue with the routine, but if I
    could get help with these items I would be very appreciative.

    (defun c:slo (/ osold)
    (setq osold (getvar "osmode"))
    (setvar "osmode" 0)
    (LS)
    (A1)
    (A2)
    (L1)
    (setvar "osmode" osold)
    )

    (defun LS ()
    (if (not (tblsearch "layer" "slope"))
    (command "-layer" "n" "SLOPE" "c" "1" "SLOPE" "s" "SLOPE" "")
    )
    )

    (defun A1 (/ p1)
    (setq p1 (getpoint "\nPick start point for first ARC: "))
    (command "_.arc" p1 pause pause)
    )

    (defun A2 (/ p2)
    (setq p2 (getpoint "\nPick start point for second ARC: "))
    (command "_.arc" p2 pause pause)
    )

    (defun L1 ()
    (command "_.line" "" pause "")
    )
     
    ffejgreb, Feb 19, 2004
    #1
  2. ffejgreb

    Jim Claypool Guest

    Before the command set the osnap mode to what you need.

    (setvar "osmode" 1) ; endpoint
    (setvar "osmode" 2) ; midpoint
    (setvar "osmode" 3) ; endpoint,midpoint
    (setvar "osmode" 4) ;center
    (setvar "osmode" 5) ; endpoint,center
    etc.....

    You should also use (setq osmode (getvar "osmode")) before setting osmode
    and (setvar "osmode" osmode) at the end of the function so that it is reset
    to whatever the user was using.
     
    Jim Claypool, Feb 19, 2004
    #2
  3. ffejgreb

    ffejgreb Guest

    I tried setting osmode prior to each function, but I don't want them to be
    running. I would like to emulate the command line way of doing things by
    issuing the "nea" override and have it go away. I have tried placing the
    "nea" where the "pause" is, but it didn't work correctly. Can a setvar be
    nested inside of a command call? If so, how would it be written?

    Also I believe that I am using a setq osmode. Mine is called osold however.
     
    ffejgreb, Feb 19, 2004
    #3
  4. ffejgreb

    Paul Turvill Guest

    Since you're using the (command ...) function, just insert the OSnaps in the
    command string, as if you were entering it from the Command: prompt. IF that
    doesn't work, then something else is amiss.

    (command "_.line" "_nea" pause ... <etc.> ...)
    ___
     
    Paul Turvill, Feb 19, 2004
    #4
  5. ffejgreb

    ffejgreb Guest

    I have been trying that to no avail. I will keep plugging away and see if I
    can find the amiss.

    Thank you Paul.
     
    ffejgreb, Feb 19, 2004
    #5
  6. ffejgreb

    Jim Claypool Guest

    The problem with (command ".line" "nea" pause ...) is that the "nea" only
    works for the first point.
    The command line override should work with the osmode set. It is no
    different than setting the osnaps before you start a command at the command
    line.

    (defun A1 (/ p1)
    (setvar "osmode" 512)
    (setq p1 (getpoint "\nPick start point for first ARC: "))
    (setvar "osmode" 0)
    (command "_.arc" p1 pause pause)
    )

    (defun A2 (/ p2)
    (setvar "osmode" 1)
    (setq p2 (getpoint "\nPick start point for second ARC: "))
    (setvar "osmode" 0)
    (command "_.arc" p2 pause pause)
    )

    (defun L1 ()
    (setvar "osmode" 0)
    (command "_.line" "" pause "")
    )

    Or if you don't like setting osnaps then you could do this:

    (defun A1 (/ p1)
    (setq p1 (osnap (getpoint "\nPick start point for first ARC: ") "nea"))
    (command "_.arc" p1 pause pause)
    )

    (defun A2 (/ p2)
    (setq p2 (osnap (getpoint "\nPick start point for second ARC: ") "endp"))
    (command "_.arc" p2 pause pause)
    )
     
    Jim Claypool, Feb 19, 2004
    #6
  7. ffejgreb

    ffejgreb Guest

    Thanks Jim. I took the same approach you did in the first section. The
    only problem I seem to have now is that I can't make L1 work correctly.
    When I do this:

    (defun L1 ()
    (command "_.line" "_endp" "_perp" "")
    )

    I get this:

    _.line Specify first point: _endp of _perp
    Invalid point.
    ; error: Function cancelled
    Specify first point:

    I've placed a pause in front of each osnap, but what happens then is that no
    osnap is set for the first pick, endp is set for the second, then the line
    command ends.

    Any other thoughts?
     
    ffejgreb, Feb 19, 2004
    #7
  8. ffejgreb

    Mark Propst Guest

    pause *after* osnap ?
    (command "_.line" "_endp" pause "_perp" pause "")
     
    Mark Propst, Feb 19, 2004
    #8
  9. ffejgreb

    ffejgreb Guest

    Well that seems to have worked! Thank you so much Mark! I don't know why I
    didn't think to try that myself.

    Jeff
     
    ffejgreb, Feb 19, 2004
    #9
  10. ffejgreb

    Mark Propst Guest

    You're welcome
    :)
    Glad to help
     
    Mark Propst, Feb 19, 2004
    #10
  11. ffejgreb

    Paul Turvill Guest

    You're leaving out the pauses.
    ___
     
    Paul Turvill, Feb 20, 2004
    #11
  12. ffejgreb

    ffejgreb Guest

    Figured that out. Thanks for continuing to look for my errors.

    Jeff
     
    ffejgreb, Feb 20, 2004
    #12
  13. ffejgreb

    Jan C Guest

    Method 1:
    Set osmode to 512 before getpoint P1
    Set osmode to 1 before getpoint P2

    (defun A1 (/ p1)
    (setvar "osmode" 512)
    (setq p1 (getpoint "\nPick start point for first ARC: "))
    (setvar "osmode" 0)
    (command "_.arc" p1 pause pause)
    )

    Method 2:
    Use (osnap pt mode)

    (defun A1 (/ p1)
    (setq p1 (getpoint "\nPick start point for first ARC: "))
    (setq p1 (osnap p1 "_nea")
    (command "_.arc" p1 pause pause)
    )

    This method is dangerous because (osnap pt mode) will give NIL if Autocad
    will not find an object that is nearest to p1.

    JanC
     
    Jan C, Feb 21, 2004
    #13
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.