Assoc 10 of the last vertex in an LWPOLYLINE

Discussion in 'AutoCAD' started by Andy, Jul 24, 2004.

  1. Andy

    Andy Guest

    I am trying to find the last X &Y coordinate of a polyline which I will
    select as follows:

    (setq W1 (list 0 0))
    (setq W2 (list 3000 125))
    (setq ALL (ssget "W" W1 W2))
    (setq ALL (ssget "P" '((0 . "LWPOLYLINE")(8 . "PROFILE"))))

    ;This will give me all the X&Y coords for all the verticies
    (setq EL (entget (ssname ALL 0)))


    How do I extract each vertex assoc 10 and in particular I would like the
    FIRST & LAST vertecies' X&Y value. Depending which one holds the highest X
    value it will tell me if the pline was started from the left hand side of
    the screen or the right (clockwise poly or anti-clockwise)

    BELOW IS A TYPICAL PRINTOUT FROM A POLYLINE DISPLAYED IN AUTOCAD:
    Command: (setq EL (entget (ssname ALL 0)))
    ((-1 . <Entity name: 7efac240>) (0 . "LWPOLYLINE") (330 . <Entity name:
    7efb5cf8>) (5 . "24A0") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
    "PROFILE") (100 . "AcDbPolyline") (90 . 7) (70 . 0) (43 . 0.0) (38 . 0.0)
    (39 .
    0.0)
    (10 1337.86 27.575) **** I WANT THIS (first vertix) *****
    (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 1523.04 63.1602)
    (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 1686.85 56.0431) (40 . 0.0) (41 . 0.0)
    (42
    .. 0.0) (10 1918.32 31.1335) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 2082.13
    52.4846) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 2249.5 48.9261) (40 . 0.0) (41
    ..
    0.0) (42 . 0.0)
    (10 2399.07 59.6016) ***** AND THIS (last vertex)*****
    (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0
    0.0 1.0))

    Thanks for your help in this. I know it's simple but I can't find an
    example to follow right now.

    Andy
     
    Andy, Jul 24, 2004
    #1
  2. Hi Andy

    This sample should help you (returns the endpoints of all objects they have):

    (defun c:GetEndPts ( / CurEnt CurObj)
    (vl-load-com)
    (if (setq CurEnt (entsel "\nSelect object: "))
    (progn
    (setq CurObj (vlax-ename->vla-object (car CurEnt)))
    (list
    (vlax-curve-getStartPoint CurObj)
    (vlax-curve-getEndPoint CurObj)
    )
    )
    )
    )

    Cheers
     
    Jürg Menzi, Jul 24, 2004
    #2
  3. And this one shows how to work wit a selection set:

    (defun c:GetAllEndPts ( / FltLst CurEnt CurObj CurSet)
    (vl-load-com)
    (setq FltLst '((0 . "LWPOLYLINE") (8 . "PROFILE"))
    ;;; CurSet (ssget "_W" '(0 0) '(3000 125) FltLst)
    CurSet (ssget "_X" FltLst) ;if you wanna select *ALL* use this line
    ) ;else the line above
    (if CurSet
    (while (setq CurEnt (ssname CurSet 0))
    (setq CurObj (vlax-ename->vla-object CurEnt))
    (ssdel CurEnt CurSet)
    (terpri)
    (princ
    (list
    (vlax-curve-getStartPoint CurObj)
    (vlax-curve-getEndPoint CurObj)
    )
    )
    )
    )
    (princ)
    )

    Cheers
     
    Jürg Menzi, Jul 24, 2004
    #3
  4. (setq data (entget (car (entsel))))

    ((-1 . <Entity name: 7ef8bac0>) (0 . "LWPOLYLINE") (330 .
    <Entity name: 7ef9fcf8>) (5 . "22C0") (100 . "AcDbEntity") (67 . 0) (410 .
    "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 3) (70 . 0) (43 . 0.0) (38 .
    0.0) (39 . 0.0) (10 12295.4 4089.56) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10
    12295.4 3893.53) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 12541.6 3893.53) (40 .
    0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))

    (setq start (cdr (assoc 10 data)))
    (12295.4 4089.56)

    (setq end (cdr (assoc 10 (reverse data))))
    (12541.6 3893.53)

    --
    Autodesk Discussion Group Facilitator



    <snip>
     
    Jason Piercey, Jul 24, 2004
    #4
  5. Andy

    CAB2k Guest

    Andy,
    You may be interested in this routine.
    Code:
    ;;===========================================================
    ;; PolyDir.LSP v1.0 (03-05-02) John F. Uhden, Cadlantic
    ;; This is freeware dedicated to Noah (?) and Cliff Middleton
    ;;
    (defun C:PolyDir ( / @delta @cv_parse_list @polydir 2pi e ans)
    ;;-----------------------------------------------------------------------
    ;; This function returns the deflection angle (in radians) of two angles:
    ;;
    (defun @delta (a1 a2)
    (cond
    ((> a1 (+ a2 pi))
    (setq a2 (+ a2 2pi))
    )
    ((> a2 (+ a1 pi))
    (setq a1 (+ a1 2pi))
    )
    )
    (- a2 a1)
    )
    ;;-------------------------------------------------------------
    ;; Function returns a list of 3D points from a continuous list
    ;; as returned by (vlax-safearray->list (vlax-variant-value X))
    ;;
    (defun @cv_parse_list (data n / item new)
    (foreach element (reverse data)
    (setq item (cons element item))
    (if (= (length item) n)
    (setq new (cons item new) item nil)
    )
    )
    new
    )
    (defun @polydir (e / ent etype object coords flag i p1 p2 p3 sum)
    (cond
    ((/= (type e) 'ENAME) nil)
    ((not (vl-position (setq etype (cdr (assoc 0 (setq ent (entget e)))))
    '("AECC_CONTOUR" "LWPOLYLINE" "POLYLINE")))
    (prompt (strcat " Object selected is a(n) " etype))
    )
    ((and (setq flag (cdr (assoc 70 ent)))(> (boole 1 16 flag) 0))
    (prompt " Object selected is a 3DMESH")
    )
    (1 (setq object (vlax-ename->vla-object e)
    coords (vlax-get object "Coordinates")
    coords (@cv_parse_list coords (if (= etype "LWPOLYLINE") 2 3))
    i 1
    sum 0.0
    )
    (and
    flag
    (= (logand 1 flag) 1) ; closed
    (setq coords (reverse (cons (car coords)(reverse coords))))
    )
    (repeat (- (length coords) 2)
    (setq p1  (nth (1- i) coords)
    p2  (nth i coords)
    i   (1+ i)
    p3  (nth i coords)
    sum (+ sum (@delta (angle p1 p2)(angle p2 p3)))
    )
    )
    (if (minusp sum) "CW" "CCW")
    )
    )
    )
    (setvar "errno" 0)
    (setq 2pi (* pi 2))
    (while (/= (getvar "errno") 52)
    (if (setq ans (@polydir (setq e (car (entsel "\nSelect a polyline: ")))))
    (princ ans)
    )
    )
    (princ)
    )
     
    CAB2k, Jul 24, 2004
    #5
  6. Andy

    Andy Guest

    A BIG THANK YOU to all that have contributed. All solutions were of help.

    Regards

    Andy
     
    Andy, Jul 24, 2004
    #6
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.