View Full Version : Pick out the common in a list
devitg
1st Nov 2009, 01:57 am
From a SSGET at a
(setq ins-pt '(785765.0 9.28376e+006 0.0) )
(setq ent-ss (ssget "_c" ins-pt ins-pt '((0 . "LINE") )))
I got all its 10 and 11 code , as I do not know wich one are on the INS-PT.
I sort it to Z value and got it ,
(setq pt-list (list '(785766.0 9.28375e+006 2418.41)
'(785768.0 9.28375e+006 2420.24)
'(785760.0 9.28377e+006 2421.07)
'(785769.0 9.28375e+006 2421.72)
'(785770.0 9.28376e+006 2422.19)
'(785770.0 9.28376e+006 2422.24)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785762.0 9.28377e+006 2422.77)
'(785763.0 9.28377e+006 2422.91)
))
It is clear that my common point is
(785765.0 9.28376e+006 2422.47)
How can I get it from the LIST.?
alanjt
1st Nov 2009, 03:01 am
From a SSGET at a
(setq ins-pt '(785765.0 9.28376e+006 0.0) )
(setq ent-ss (ssget "_c" ins-pt ins-pt '((0 . "LINE") )))I got all its 10 and 11 code , as I do not know wich one are on the INS-PT.
I sort it to Z value and got it ,
(setq pt-list (list '(785766.0 9.28375e+006 2418.41)
'(785768.0 9.28375e+006 2420.24)
'(785760.0 9.28377e+006 2421.07)
'(785769.0 9.28375e+006 2421.72)
'(785770.0 9.28376e+006 2422.19)
'(785770.0 9.28376e+006 2422.24)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785765.0 9.28376e+006 2422.47)
'(785762.0 9.28377e+006 2422.77)
'(785763.0 9.28377e+006 2422.91)
))It is clear that my common point is
(785765.0 9.28376e+006 2422.47)
How can I get it from the LIST.?
Are you asking how to extract the point in the list that has duplicates?
devitg
1st Nov 2009, 12:16 pm
Are you asking how to extract the point in the list that has duplicates?
Yes , because it hold the Z value , just over the block
(setq ins-pt '(785765.0 9.28376e+006 0.0) )Ins-pt is the insertion point of the block , so by
(setq ent-ss (ssget "_c" ins-pt ins-pt '((0 . "LINE") )))I got all the lines that match it's code 10 or code 11 at such point.
Now I get all code 10 and 11 , only the repeated value hold the Z over the block's insertion point
I tried with
(ssget "_c"
INS-PT
INS-PT
(list '(0 . "LINE")
'(-4 . "<or")
'(-4 . "=,=,*")
(cons 10 INS-PT)
'(-4 . "=,=,*")
(cons 11 INS-PT)
'(-4 . "or>")))
Given the * as wildcard for any Z value , but it did not work.
See the Sample DWG ,
So I got all code 10 and 11 from each line , then sort it by it's Z value , an got the LIST with the repeated and not repeated points.
The repeated , hold the Z value over the block's insertion point
alanjt
1st Nov 2009, 04:16 pm
Call it a first draft, it will only return 1 duplicate...
(defun DuplicatePoint (#List / #New #Dup)
(foreach x #List
(if (member x #New)
(setq #Dup x)
(setq #New (cons x #New))
) ;_ if
) ;_ foreach
#Dup
) ;_ defun**UPDATE: Much better one posted here:
http://www.cadtutor.net/forum/showpost.php?p=280056&postcount=12
I'll leave the original up for posterity. :)
alanjt
1st Nov 2009, 04:26 pm
This might also help:
;;; Remove all duplicates from list
;;; #List - List to process
;;; Alan J. Thompson, 04.21.09
(defun AT:ListNoDuplicates (#List / #New)
(foreach x #List
(or (vl-position x #New) (setq #New (cons x #New)))
) ;_ foreach
(reverse #New)
) ;_ defun
devitg
1st Nov 2009, 04:33 pm
It work as I need to be .
Thanks
alanjt
1st Nov 2009, 04:44 pm
It work as I need to be .
Thanks
No problem. :)
devitg
1st Nov 2009, 05:56 pm
This one is like the
REMOVE-DUPS I use , it is not the case , It remove , but do not show wich one is the duplicate.
Thanks
alanjt
1st Nov 2009, 06:29 pm
This one is like the
REMOVE-DUPS I use , it is not the case , It remove , but do not show wich one is the duplicate.
Thanks
I know that. I was just offering another list duplicate example.
devitg
1st Nov 2009, 11:06 pm
Thanks.I appreciate it .
alanjt
1st Nov 2009, 11:13 pm
Thanks.I appreciate it .
:)
No problem. I assume you figured everything out.
alanjt
2nd Nov 2009, 03:09 am
Thought about this over dinner...
;;; Return all all duplicates within list
;;; #List - List to process
;;; Alan J. Thompson, 11.01.09
(defun AT:ListDuplicates (#List)
(vl-remove-if-not
'(lambda (x) (member x (cdr (member x #List))))
#List
) ;_ vl-remove-if-not
) ;_ defun
Will return all duplicates. :)
Powered by vBulletin™ Version 4.1.2 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.