3dEntsel - Solves 3d vlax...closestpointto vs. ~2d entsel problem

Discussion in 'AutoCAD' started by James Allen, Jun 10, 2004.

  1. James Allen

    James Allen Guest

    Hi all. First let me echo John Uhden's sentiments in his 2002-07-17 post:
    "vlax-curve-GetClosestPointTo & 3DPolylines". Though I didn't realize it
    the other day, his post *exactly* describes the problem I posted:
    "vlax-curve-getclosestpointto... or endpoint of?". With the exception that
    mine was just a line with an elevation and I had a non-plan view current.

    I am sure others have already found solutions for this, but I couldn't find
    them. So here's what I came up with. Please feel free to edit, improve,
    critique, etc. Feedback is welcome.

    Hoping others benefit,
    --
    James Allen
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO
    To reply by email; ~AA~ = @ and ~DD~ = .


    ;;; 3dEntsel basically finds (osnap "nea"... for a given entity without
    using osnap.
    ;;; Argument: 1. picked ename
    ;;; 2. pick point in UCS
    ;;; Returns: 1. picked ename
    ;;; 2. "(osnap "nea" ... in UCS
    ;;; Examples: 1. (setq near (nth 1 (3dEntsel (list ename pkpt))))
    ;;; 2. (setq esel (3dEntsel (entsel)));or nentsel or nentselp
    (defun 3dEntsel (arglst / enm ob1 p1 ob2)
    (setq enm (nth 0 arglst)
    ob1 (vlax-ename->vla-object enm)
    p1 (trans (nth 1 arglst) 1 0)
    v1 (trans (getvar "viewdir") 1 0)
    p1 (vlax-curve-getclosestpointtoprojection ob1 p1 v1)
    ob2 (vla-addxline
    (vla-get-block (vla-get-activelayout (active-document)))
    (vlax-3d-point p1)
    (vlax-3d-point (mapcar '+ p1 v1))
    )
    p1 (vla-intersectwith ob1 ob2 acExtendNone)
    p1 (vlax-safearray->list (vlax-variant-value p1))
    p1 (trans p1 0 1)
    )
    (vla-delete ob2)
    (subst p1 (nth 1 arglst) arglst)
    )
     
    James Allen, Jun 10, 2004
    #1
  2. James Allen

    John Uhden Guest

    Thanks, James! I'm very interested in playing with this. "viewdir" may be the
    key. It was probably Tony T. who advised using
    (vlax-curve-getclosestpointtoprojection ...), but I haven't had the time to
    figure out the projection part. Sadly, I have almost no play time these days,
    but don't you think it's really neat how cohesive this place can be?

    Joe... are you paying attention?
     
    John Uhden, Jun 11, 2004
    #2
  3. James Allen

    Joe Burke Guest

    Yes, John. :)

    Though I haven't had a chance to dig into James' post.

    Joe Burke
     
    Joe Burke, Jun 11, 2004
    #3
  4. James Allen

    James Allen Guest

    " Sadly, I have almost no play time these days,
    but don't you think it's really neat how cohesive this place can be?"

    Absolutely. I know what you mean about play time...

    James
     
    James Allen, Jun 14, 2004
    #4
  5. James Allen

    jcallenj Guest

    In case anyone is using this, a recent post by Juerg called my attention to a couple of things.

    First, the whole xline business was totally pointless. Apparently I missed the part in the help file about closestpointtoprojection that says it projects the point *back onto the curve*. LOL

    Also, it hadn't occured to me that it won't work on all entities, e.g. regions. In other words, it's not quite the general solution I thought it was.

    So here's a cleaner version.

    James

    ;;; 3dEntsel basically finds (osnap "nea"... for a given entity without
    ;;; using osnap, provided the object is a valid curve for vlax-curve functions.
    ;;;
    ;;; Argument List: 1. picked ename
    ;;; 2. pick point in UCS
    ;;; Return List: 1. picked ename
    ;;; 2. "(osnap "nea" ... in UCS
    ;;; Examples: 1. (setq near (nth 1 (3dEntsel (list ename pkpt))))
    ;;; 2. (setq esel (3dEntsel (entsel)));or nentsel or nentselp
    ;;;
    (defun 3dEntsel (arglst / obj p1 v1)
    (setq obj (vlax-ename->vla-object (nth 0 arglst))
    p1 (trans (nth 1 arglst) 1 0);pick ucs->wcs
    v1 (trans (getvar "viewdir") 1 0);view ucs->wcs
    p1 (vlax-curve-getclosestpointtoprojection obj p1 v1)
    p1 (trans p1 0 1);nea wcs->ucs
    )
    (subst p1 (nth 1 arglst) arglst)
    )
     
    jcallenj, Oct 1, 2004
    #5
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.