comparing two lists against each other to find like items

comparing two lists against each other to find like items

dwattersAMXH5
Enthusiast Enthusiast
3,193 Views
5 Replies
Message 1 of 6

comparing two lists against each other to find like items

dwattersAMXH5
Enthusiast
Enthusiast

hello, 

i am trying to create a lisp to find matching intersecting points between two rectangles. 

specifically i am trying to determine match line points for sheet outlines (civil work)

where the left side of one sheet and the right side of one sheet have the same intersection point with a line that passes across both. 

i can get the intersection points using vl-intersectwith and get two different lists of intersection points 

i could use some help finding a way to compare the two lists, 

i was thinking i could get the list-length and while loop through the items in the first list getting the intersection x,y 
then find the list which equals those points then cond it against the center point of the sheet to determine which direction the matchline would be from the center.

see attached screen shot, 
my lists will look like this - 

main sheet ((1,2,3) (4,5,6)) (main sheet being the one matchlines are being added to

surrounding sheets (((sheet number)(1,2,3)(7,8,9)) ((sheet number)(4,5,6)(13,14,15)))

i would like to be able to make a loop to test (1,2,3) then test (4,5,6) from the main list 

against the surrounding sheets list in a way that if (1,2,3) is found in the surrounding sheets list it returns the whole ((sheet number)(1,2,3)(7,8,9)) item so that i can then get the sheet number and compare where its location is compared to the center of the main sheet to find left,right,top,bottom matchline location. 


can anyone point me in some kind of direction on comparing the lists, i think i have the rest covered. 

i was thinking (find) or (car(member) but am unsure about getting that to return exactly what i am looking for being the sublist which the point is located in

thinking assoc but i've only ever used assoc when it was the first item being searched (dxf codes) and can not test if it will return what i'm looking for at the moment. (search the whole sub list)

 

 

 

thanks

0 Likes
Accepted solutions (2)
3,194 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor
Are you after a list of the four intersection points in the screenshot?

I am not one of the robots you're looking for

0 Likes
Message 3 of 6

john.uhden
Mentor
Mentor
Accepted solution
I'm sure this can be simplified by some mapcar lambda thingies, but this is the first thing that came into this doddering old head...

(setq a (list "A" '(1 2 3)'(4 5 6))) (setq b (list "B" '(1 2 3)'(7 8 9))) (setq c (list "C" '(4 5 6)'(13 14 15))) (defun find (what where / found) (foreach item what (if (vl-position item where)(setq found where))) found ) (defun findall (what wheres / found founds) (foreach item wheres (if (setq found (find what item)) (setq founds (cons found founds)) ) ) (reverse founds) ) Command: (findall a (list b c)) (("B" (1 2 3) (7 8 9)) ("C" (4 5 6) (13 14 15)))

John F. Uhden

0 Likes
Message 4 of 6

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use the following gc:intersect routine.

 

(defun gc:intersect (l1 l2)
  (if l1
    (if	(member (car l1) l2)
      (cons (car l1) (gc:intersect (cdr l1) l2))
      (gc:intersect (cdr l1) l2)
    )
  )
)
_$ (setq a (list "A" '(1 2 3)'(4 5 6)))
(setq b (list "B" '(1 2 3)'(7 8 9)))
(setq c (list "C" '(4 5 6)'(13 14 15)))
("A" (1 2 3) (4 5 6))
("B" (1 2 3) (7 8 9))
("C" (4 5 6) (13 14 15))
_$ (gc:intersect a b)
((1 2 3))
_$ (gc:intersect a c)
((4 5 6))
_$ (gc:intersect b c)
nil


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 6

dwattersAMXH5
Enthusiast
Enthusiast

Thank you both! 
this should get me back on the right track. 


0 Likes
Message 6 of 6

dwattersAMXH5
Enthusiast
Enthusiast

i can get the list, of the intersection points, its comparing the two lists i was having problems with. 

basically here's what was happening

get all the lines crossing the sheetoutline (ssget everything within 1pt larger then the outline)

while loop through the lines getting the intersection point for each on the sheetoutline 
put these together in a list with the sheet number 
(from here you have your first list) 
from there you make a selection of all sheets that could possibly be touching the sheet you are working on (a selection set with a window three times the size of the sheetoutline) 
then it runs through the same intersection loop again for each sheet that is touching the main sheet.
(now you have a list for each sheet) 

from there i was hitting a wall, 
i needed to loop through each item of the first list and find those values in the other lists, if it finds the value it allows to find the sheet value. from there i can tell it where the matchline actually goes (east,west,north, south of viewport) 

needed to do it this way encase a sheet was surrounded by other sheets but the line path only crossed two sheets, you only need to show the match lines for the two sheets that actually share intersection points. 

 

 

 

i think with the below tips i can accomplish what i am looking for. 

0 Likes