assoc???

Discussion in 'AutoCAD' started by aaron weissner, Jan 20, 2004.

  1. how do i get two points out of this item... I want the first two (10 ? ?)
    points... the item is a pline shaped to be a closed rectangle... the first
    two (10 ? ?) are the start point and the next point entered...

    Select object: ((-1 . <Entity name: 400edf10>) (0 . "LWPOLYLINE") (330 .
    <Entity name: 400edcf8>) (5 . "62") (100 . "AcDbEntity") (67 . 0) (410 .
    "Model") (8 . "0") (100 . "AcDbPolyline") (90 . 4) (70 . 1) (43 . 0.0) (38 .
    0.0) (39 . 0.0) (10 8.65821 1.5892) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10
    9.32908 1.92449) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 9.32908 48.8775) (40 .
    0.0) (41 . 0.0) (42 . 0.0) (10 8.65821 48.5422) (40 . 0.0) (41 . 0.0) (42 .
    0.0) (210 0.0 0.0 1.0))
     
    aaron weissner, Jan 20, 2004
    #1
  2. aaron weissner

    BillZ Guest

    (defun LWPolylist (/ ent)
    (setq ent (car (entsel "\nSelect LWPolyline: < pick > ")))
    (if (equal (cdr (assoc 0 (entget ent))) "LWPOLYLINE") ;check entity
    (progn
    (setq ent (entget ent)
    ) ; setq
    (foreach n ent
    (if (= (car n) 10)
    (setq verlist (cons (cdr n) verlist)
    )
    )
    ) ;end foreach.
    ) ;end progn.
    ) ;end first if.
    (setq pt1 (nth 0 (reverse verlist))
    pt2 (nth 1 (reverse verlist)))
    ) ;end LWPolylist
     
    BillZ, Jan 20, 2004
    #2
  3. aaron weissner

    Devin Guest

    (vl-remove-if 'null

    (mapcar

    '(lambda (a)

    (if (= (car a) 10) a)

    )

    elist

    )

    )


    where elist is the entity data list. This will strip all but dxf code 10's
    from the list. Then use car and cadr to get 1st and second items.

    HTH,

    Devin
     
    Devin, Jan 20, 2004
    #3
  4. thanks...
     
    aaron weissner, Jan 20, 2004
    #4
  5. aaron weissner

    Devin Guest

    If you need to keep the 40-41-42 values then just adjust the code as
    follows...
    (vl-remove-if 'null
    (mapcar
    '(lambda (a)
    (cond
    ((= (car a) 10) a)

    ((= (car a) 40) a)

    ((= (car a) 41) a)

    ((= (car a) 42) a)
    )
    )
    elist
    )
    )
     
    Devin, Jan 20, 2004
    #5
  6. aaron weissner

    BillZ Guest

    I see it's time to update more of my code. :)

    Thanks

    Bill
     
    BillZ, Jan 20, 2004
    #6
  7. I still prefer the good 'ole massoc function that
    has been floating around here *forever*
     
    Jason Piercey, Jan 20, 2004
    #7
  8. aaron weissner

    BillZ Guest

    Jason,

    Why?

    Bill
     
    BillZ, Jan 20, 2004
    #8
  9. (vl-remove-if-not
    '(lambda (x) (member (car x) '(10 40 41 42)))
    lst
    )

    If you need to keep the 40-41-42 values then just adjust the code as
    follows...
    (vl-remove-if 'null
    (mapcar
    '(lambda (a)
    (cond
    ((= (car a) 10) a)

    ((= (car a) 40) a)

    ((= (car a) 41) a)

    ((= (car a) 42) a)
    )
    )
    elist
    )
    )
     
    michael puckett, Jan 20, 2004
    #9
  10. aaron weissner

    Devin Guest

    Actually if you wanted to get optimized...

    (vl-remove-if-not
    (mapcar
    '(lambda (a)
    (setq dxf (car a))
    (if
    (or (= dxf 10) (= dxf 40) (= dxf 41) (= dxf 42))
    a
    )
    )
    elist
    )
    )

    That way you can buffer the (car a). The member would only return a 10 or
    41 etc and not the data with it, right?

    Devin
     
    Devin, Jan 20, 2004
    #10
  11. aaron weissner

    Devin Guest

    I think we responded at the same time, jinks you owe me a coke :)
     
    Devin, Jan 20, 2004
    #11
  12. aaron weissner

    Devin Guest

    Michael,

    My apologies, I stand corrected, I didn't realize that you could do that.
    But I tested your code and sure enough. It works.

    Good Job,

    Devin
     
    Devin, Jan 20, 2004
    #12
  13. aaron weissner

    Devin Guest

    (vl-remove-if-not
    I miss understood Michael's post and code. Here's one that works too...

    (vl-remove-if 'null
    (mapcar
    '(lambda (a)
    (setq dxf (car a))
    (if
    (or (= dxf 10) (= dxf 40) (= dxf 41) (= dxf 42))
    a
    )
    )
    elist
    )
    )

    Devin
     
    Devin, Jan 20, 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.