A Little Problem with OSNAP

Discussion in 'AutoCAD' started by Roderic Potter, Jan 23, 2004.

  1. Please take a look at the following pice of (probably inefficient) code:

    (setq ee1 (entsel "\nPick centrepoint of text: "))
    (setq ee (car ee1))
    (if ee
    (progn
    (setq e (entget ee))
    (setq n (cdr (assoc 8 e)))
    (setq pt1 (cadr ee1))
    (command "LAYER" "SET" n "")
    ))

    Here I am trying to do a number of things at once - pick an entity, capture
    its layer, and save the point coordinates of the actual pick. I would like
    to use an OSNAP "Near" in the entsel operation, and I would like this to be
    automatic. It makes no difference what the current setting of OSNAP is when
    this code is run, you are merely presented with a pickbox on the screen with
    no OSNAP to help you. You can call OSNAP Near on the fly during the entsel
    operation, but I would like this to be automatic.

    I tried adding OSNAP to the entsel line of code, but kept getting "too many
    arguments" errors.

    How can I invoke "Near" during the "entsel"?

    thanks!
     
    Roderic Potter, Jan 23, 2004
    #1
  2. (setq e (entsel "\nPick entity near desired point: "))
    (setq near_pt (osnap (cadr e) "qui,nea"))
     
    Tony Tanzillo, Jan 23, 2004
    #2
  3. Thanks for this Tony, but it has no effect on the original entsel command
    on-screen - there is still nothing but a pickbox, with no running OSNAP to
    help you pick the line.
     
    Roderic Potter, Jan 23, 2004
    #3
  4. Looking for something like this?

    (setq o-osmode (getvar "osmode"))
    (setvar "osmode" 512)
    (setq a (getpoint))
    (setq ent (nentselp a))
    (setvar "osmode" o-osmode)

    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jan 23, 2004
    #4
  5. Roderic,

    You cannot use the (osnap) function inside the entsel command. You can,
    however use the (osnap) function on the point after returning it. Ex:

    (setq ee1 (entsel "\nPick centrepoint of text: "))
    (setq ee (car ee1))
    (if ee
    (progn
    (setq e (entget ee))
    (setq n (cdr (assoc 8 e)))
    (setq pt1 (cadr ee1))

    ;; CODE ADDED HERE - Causes the point picked to snap to nearest point.
    (if (setq pt (osnap pt1 "nea"))
    (setq pt1 pt)
    (princ "\n Error - No nearest point found!")
    )

    (command "LAYER" "SET" n "")
    ))
     
    Phil Kenewell, Jan 23, 2004
    #5
  6. Ahh... I need to refresh my newsreader more frequently. Anyway Ken's
    solution is what you have to use to change the running osnap while
    prompting.
     
    Phil Kenewell, Jan 23, 2004
    #6
  7. BRILLIANT
    thanks, I had never heard of the nentselp function
     
    Roderic Potter, Jan 23, 2004
    #7
  8. Thanks Phil
    Ken Alexander provided an excellent solution!
     
    Roderic Potter, Jan 23, 2004
    #8
  9. You're Welcome.
    --
    Ken Alexander
    Acad2004
    Windows2000 Prof.

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jan 23, 2004
    #9
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.