Create a new list from an existing list

Create a new list from an existing list

neam
Collaborator Collaborator
1,608 Views
24 Replies
Message 1 of 25

Create a new list from an existing list

neam
Collaborator
Collaborator

Hi everyone :

I have created a list of entity names of blocks (all blocks used in dwg is same name "CAP")

and their insertion point :

 

((<Entity name: 7ef390c0> (290253.0 3.26728e+006 0.0))
(<Entity name: 7ef397b8> (290171.0 3.26727e+006 0.0))
(<Entity name: 7ef3ed30> (290253.0 3.26728e+006 0.0))
(<Entity name: 7ef405c0> (290171.0 3.26727e+006 0.0))
(<Entity name: 7ef49228> (290156.0 3.26724e+006 0.0))
(<Entity name: 7ef49230> (290171.0 3.26727e+006 0.0)))

 

How can I create a new list of the first items of each of the members of this list,
provided that their second items is equal.

New list:
(<Entity name: 7ef397b8> <Entity name: 7ef405c0> <Entity name: 7ef49230>)

 

If it is possible to define the value of fuzz to compare x and y of the second items,
it would be great.

THX 🙏🙏🙏

0 Likes
Accepted solutions (3)
1,609 Views
24 Replies
Replies (24)
Message 21 of 25

neam
Collaborator
Collaborator

Dear _gile:

Can make only list of all <Entity name> if count item of member (>= 3)

(((290156.0 3.26724e+06 0.0)
"<Entity name: 7ef49228>"   <==== no list this 
)

((290134.0 3.26721e+06 0.0)
"<Entity name: 7ef492100>"   <==== no list this 


((290171.0 3.26727e+06 0.0)
"<Entity name: 7ef49230>"     <==== list this 
"<Entity name: 7ef405c0>"     <==== list this 
"<Entity name: 7ef397b8>"     <==== list this 
)
((290253.0 3.26728e+06 0.0)
"<Entity name: 7ef3ed30>"    <==== list this 
"<Entity name: 7ef390c0>"    <==== list this 
)
)

(if (>= (count (item (car lst))  3)  ====> Then list =====> <Entity name>

0 Likes
Message 22 of 25

neam
Collaborator
Collaborator

Dear _gile:

Can make list of <Entity name> if item of member (>= 3) :

 

(((290156.0 3.26724e+06 0.0)
"<Entity name: 7ef49228>"    <===== no list this
)

((290123.0 3.26524e+06 0.0)
"<Entity name: 7ef49108>"   <===== no list this
)
((290171.0 3.26727e+06 0.0)
"<Entity name: 7ef49230>"   <===== list this
"<Entity name: 7ef405c0>"   <===== list this
"<Entity name: 7ef397b8>"   <===== list this
)
((290253.0 3.26728e+06 0.0)
"<Entity name: 7ef3ed30>"   <===== list this
"<Entity name: 7ef390c0>"   <===== list this
)
)

(if (>= (count (item (car lst))) 3) ====> Then ====> make list "<Entity name>"

0 Likes
Message 23 of 25

_gile
Consultant
Consultant
Accepted solution

This is precisely what the cddr function does: return the list but 2 first items.

 

(cddr '(a b)) ; => nil
(cddr '(c d e) ; => (E)
(cddr '(f g h i) ; => (H I)

 

 

Used with mapcar, you can can process all sublists:

 

(mapcar 'cddr '((a b) (c d e) (f g h i))) ; => (nil (E) (H I))

 

 

Then you can concatenate the sublists into a flat list

 

(apply 'append '(nil (E) (H I))) ; => (E H I)

 

 

All in a single expression:

 

(apply 'append (mapcar 'cddr '((a b) (c d e) (f g h i)))) ; => (E H I)

 

 

LISP stands for LISt Processing, list manipulation functions are the basis of LISP. You must learn how to use them.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 24 of 25

neam
Collaborator
Collaborator

excuse me

oops!!! duplicate reply 

0 Likes
Message 25 of 25

neam
Collaborator
Collaborator

Thank you very much ,
Because you explained it so well.
I was able to complete the code with your help.

0 Likes