How to find assoc 10 at polyline

Discussion in 'AutoCAD' started by Adesu, Feb 16, 2005.

  1. Adesu

    Adesu Guest

    Would you like to help me,how to find second point and third point (assoc
    10) from dxf file of polyline,thanks for your respond.

    (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (setq n (sslength ss))
    (setq ssn (ssname ss 0))
    (setq cnt 0)
    (repeat n
    (setq sse (entget ssn))
    (setq 1pt (cdr (assoc 10 sse))) ; >>> only first point assoc 10
    (setq 2pt (cdr (... ; >>> to find second point assoc 10
    (setq 3pt (cdr (... ; >>> to find third point assoc 10
    (princ "\n")
    (princ sse)
    (setq cnt (1+ cnt))
    )

    ((-1 . <Entity name: 1480710>)
    (0 . LWPOLYLINE)
    (330 . <Entity name: 14800f8>)
    (5 . F2)
    (100 . AcDbEntity)
    (67 . 0)
    (410 . Model)
    (8 . 0)
    (100 . AcDbPolyline)
    (90 . 3)
    (70 . 0)
    (43 . 0.0)
    (38 . 0.0)
    (39 . 0.0)
    (10 5.93938 12.004)
    (40 . 0.0)
    (41 . 0.0)
    (42 . 0.0)
    (10 10.6869 13.027) ; >>> I want to find it (second point)
    (40 . 0.0)
    (41 . 0.0)
    (42 . 0.0)
    (10 12.828 9.17686) ; >>> I want to find it (third point)
    (40 . 0.0)
    (41 . 0.0)
    (42 . 0.0)
    (210 0.0 0.0 1.0)
    )1
     
    Adesu, Feb 16, 2005
    #1
  2. Adesu

    dean_bourke Guest

    if you mean from an alist, then:

    (defun get_lwpline_pts (ent / x entdata pt_list bit1 2d-pt 3d-pt)
    (setq Z (cdr (assoc 38 (entget ent))))
    (setq pt_list nil)
    (setq entdata (entget ent))
    (while entdata
    (setq bit1 (caar entdata))
    (if (= bit1 10)
    (progn (setq 2d-pt (cdar entdata))
    (setq 3d-pt (list (car 2d-pt) (cadr 2d-pt) Z))
    (setq pt_list (append pt_list (list 3d-pt)))
    )
    )
    (setq entdata (cdr entdata))
    )
    (setq x pt_list)
    )

    Dean
     
    dean_bourke, Feb 16, 2005
    #2
  3. Adesu

    Alaspher Guest

    Hi, string below gets list of vertex from dxf:
    Code:
    (mapcar (function cdr) (vl-remove-if-not (function (lambda (a) (= (car a) 10))) ssn))
    Best regards!
     
    Alaspher, Feb 16, 2005
    #3
  4. Adesu

    Adesu Guest

    Hi Alaspher and dean_bourke ,sorry may be you misinterpreted,my want is

    <snip>
    (setq sse (entget ssn))
    (setq 1pt (cdr (assoc 10 sse))) ; >>> only assoc 10 >>>this result is
    (5.93938 12.004)=>it's OK
    (setq 2pt (cdr (... ; >>> to find assoc 10 >>>this result is
    (10.6869 13.027)
    (setq 3pt (cdr (... ; >>> to find assoc 10 >>>this result is
    (12.828 9.17686)
    <snip.
     
    Adesu, Feb 16, 2005
    #4
  5. Adesu

    Alaspher Guest

    As variant you can try this:
    Code:
    (setq i 0)
    (foreach b (vl-remove-if-not (function (lambda (a) (= (car a) 10))) ssn)
    (set (read (strcat "pt" (itoa (setq i (1+ i))))) (cdr b))
    )
    pt1, pt2, ptN (no "1pt" - name with first digit - bad) - will contain values of vertexes.
     
    Alaspher, Feb 16, 2005
    #5
  6. Adesu

    Adesu Guest

    Hi Alaspher ,I am still troubling,may be I've wrong put your code in my code
    here result in text editor

    _$ (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (setq cnt 0)
    ;(setq n (sslength ss))
    ;(repeat n
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    (setq i 0)
    (foreach b
    (vl-remove-if-not
    (function
    (lambda (a) (= (car a) 10))) ssn))
    (set
    (read
    (strcat "pt" (itoa (setq i (1+ i)))))(cdr b))
    (princ "\n")
    (princ pt1)
    (princ "\n")
    (princ pt2)
    (princ "\n")
    (princ pt3)
    <Selection set: 19e>
    0
    <Entity name: 2be86d0>
    ((-1 . <Entity name: 2be86d0>) (0 . "LWPOLYLINE") (330 . <Entity name:
    2be5cd0>) (5 . "C4512") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 .
    "DIMENSION") (100 . "AcDbPolyline") (90 . 6) (70 . 1) (43 . 0.0) (38 . 0.0)
    (39 . 0.0) (10 401.021 31.5643) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 410.895
    14.4618) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 430.643 14.4618) (40 . 0.0)
    (41 . 0.0) (42 . 0.0) (10 440.518 31.5643) (40 . 0.0) (41 . 0.0) (42 . 0.0)
    (10 430.643 48.6668) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 410.895 48.6668)
    (40 . 0.0) (41 . 0.0) (42 . 0.0) (210 0.0 0.0 1.0))
    0
    ; error: bad argument type: listp <Entity name: 2be86d0>
    _$

    values of vertexes.
     
    Adesu, Feb 16, 2005
    #6
  7. Adesu

    Alaspher Guest

    Hi Ade!
    Yes, there is some mistakes. See revised code below:
    Code:
    (setq ss (ssget "x" '((0 . "LWPOLYLINE"))))
    (setq cnt 0)
    ;;;(setq n (sslength ss))
    ;;;(repeat n
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    (setq i 0)
    (foreach b (vl-remove-if-not
    (function
    (lambda (a) (= (car a) 10))
    )
    sse
    )
    (set (read (strcat "pt" (itoa (setq i (1+ i))))) (cdr b))
    )
    (princ "\n")
    (princ pt1)
    (princ "\n")
    (princ pt2)
    (princ "\n")
    (princ pt3)
    Best regards!
     
    Alaspher, Feb 16, 2005
    #7
  8. Adesu

    Adesu Guest

    Yes ! perfect , now I've got it ,thanks a lot
     
    Adesu, Feb 16, 2005
    #8
  9. Adesu

    Adesu Guest

    Hi Alaspher ,last dxf file only contained 3pcs assoc 10,but and if a dxf
    file that contain 5 or 7 or 15,in my question is how are you to count total
    assoc 10 in that file dxf?

     
    Adesu, Feb 16, 2005
    #9
  10. Adesu

    Joe Burke Guest

    Hi Ade,

    Try this function.

    ;returns list of information associated with a DXF code
    ;arguments: KEY - DXF code, ALIST - data list of object (entget ename)
    (defun massoc (key alist / nlist)
    (foreach x alist
    (if (eq key (car x))
    (setq nlist (cons (cdr x) nlist))
    )
    )
    (reverse nlist)
    ) ;end


    Example:
    Command: (setq ename (car (entsel "\nSelect lwpline: ")))
    Select lwpline: <Entity name: 79c5ba10>
    Command: (setq ptlst (massoc 10 (entget ename)))
    ((218114.0 -275179.0) (218298.0 -275424.0) (218160.0 -275528.0) (217976.0
    -275284.0))

    Joe Burke
     
    Joe Burke, Feb 16, 2005
    #10
  11. Adesu

    Alaspher Guest

    I never use this way for similar situations. You wanted this, I don't know your situation...

    The simple way to resolving your question is the first of my posts in this thread with access through (nth (1- <number of a vertex>) <list of vertexes>).

    Best regards!
     
    Alaspher, Feb 16, 2005
    #11
  12. Adesu

    Adesu Guest

    Yes again,perfect too,thanks a lot Joe !
     
    Adesu, Feb 16, 2005
    #12
  13. Adesu

    Joe Burke Guest

    Ade,

    You're welcome.

    I was waiting for the other shoe to drop. I figured you wanted a complete point list,
    but that's not what your initial question indicated.

    Note, the method posted works with light weight plines. Not with old style heavy
    plines. If you need to deal with both types, the following is a more comprehensive
    function.

    ;; argument: an ename or vla object
    ;; returns a point list from a lwpolyline (2D points)
    ;; or old style heavy pline, or leader, or 3D pline (3D points)
    (defun GetCoordinates (obj / objname coord lst)
    (if (= (type obj) 'ENAME)
    (setq obj (vlax-ename->vla-object obj)))
    (and
    (setq objname (vlax-get obj 'ObjectName))
    (vl-position objname '("AcDbPolyline" "AcDb2dPolyline"
    "AcDb3dPolyline" "AcDbLeader"))
    (setq coord (vlax-get obj 'Coordinates))
    (cond
    ((= objname "AcDbPolyline")
    (repeat (/ (length coord) 2)
    (setq lst (cons (list (car coord) (cadr coord)) lst))
    (setq coord (cddr coord))
    )
    )
    (T
    (repeat (/ (length coord) 3)
    (setq lst (cons (list (car coord) (cadr coord) (caddr coord)) lst))
    (setq coord (cdddr coord))
    )
    )
    )
    ) ;and
    (reverse lst)
    ) ;end

    Joe Burke
     
    Joe Burke, Feb 16, 2005
    #13
  14. Adesu

    Joe Burke Guest

    Luis,

    Nice... and quite a bit easier.

    I noticed your earlier post about passing an ename to the vlax-curve functions.
    Interesting.

    Thanks
    Joe
     
    Joe Burke, Feb 17, 2005
    #14
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.