assoc???

aaron weissner

Usenet Archive
Joined
Jul 30, 2003
Messages
48
Reaction score
0
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))
 
(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
 
(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
 
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
)
)
 
I see it's time to update more of my code. :)

Thanks

Bill
 
I still prefer the good 'ole massoc function that
has been floating around here *forever*
 
(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
)
)
 
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
 
I think we responded at the same time, jinks you owe me a coke :)
 
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
 
(vl-remove-if-not
(mapcar
'(lambda (a)
(setq dxf (car a))
(if
(or (= dxf 10) (= dxf 40) (= dxf 41) (= dxf 42))
a
)
)
elist
)
)

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
 

Latest threads

Back
Top