Aditya Bagaskara Posted February 6, 2023 Posted February 6, 2023 Hello guys, I am new in this forum! So, I want to ask. I was making a code that search for all intersections from all selected lines. When more than two lines intersect at the same coordinate, there will be duplicates, which I do not want. I was trying to solve it with the line that has foreach and member in it. The problem is, it does not work. It is still shows me duplicates. ;Automatic Column Placer 2.0 (setq intslist nil intslist2 nil ) (setq column (entsel)) (setq walls (ssget) wallsnum (sslength walls) count1 0 count2 0 ) (while (< count1 wallsnum) (setq wall1 (ssname walls count1) wallend11 (cdr (assoc 10 (entget wall1))) wallend12 (cdr (assoc 11 (entget wall1))) count2 (1+ count1) ) (while (< count2 wallsnum) (setq wall2 (ssname walls count2) wallend21 (cdr (assoc 10 (entget wall2))) wallend22 (cdr (assoc 11 (entget wall2))) ) (setq intslist (cons (inters wallend11 wallend12 wallend21 wallend22) intslist)) (setq count2 (1+ count2)) ) (setq count1 (1+ count1)) ) ;CODE BELOW IS THE DUPLICATION DELETER PART (foreach cycle intslist (if (not (member cycle intslist2)) (setq intslist2 (cons cycle intslist2)) ) ) When I use the same method (foreach and member) into manually made list with coordinates, it somehow worked well. (foreach cycle '((1.1 1.2 1.2) (1.2 1.2 1.1) (1.1 1.2 1.2)) (if (not (member cycle intslist2)) (setq intslist2 (cons cycle intslist2)) ) ) Can you guys tell me what's wrong with my code? Thank you so much. (Please explain to me only using built-in AutoLISP vocabularies.) Quote
mhupp Posted February 6, 2023 Posted February 6, 2023 Overkill command? Check out this post for overlapping. Quote
Aditya Bagaskara Posted February 8, 2023 Author Posted February 8, 2023 On 2/6/2023 at 10:57 PM, mhupp said: Overkill command? Check out this post for overlapping. No, sir, my problem is, somehow member command does not work on my code, especially when I use in inside while function. Like this part On 2/6/2023 at 10:26 PM, Aditya Bagaskara said: (while (< count2 wallsnum) (setq wall2 (ssname walls count2) wallend21 (cdr (assoc 10 (entget wall2))) wallend22 (cdr (assoc 11 (entget wall2))) ) (setq intslist (cons (inters wallend11 wallend12 wallend21 wallend22) intslist)) (setq count2 (1+ count2)) ) (setq count1 (1+ count1)) ) Do you know how to fix it? Quote
Steven P Posted February 8, 2023 Posted February 8, 2023 Put in a (princ intslist) just before your foreach command, that might give you a clue what it happening maybe. Quote
Aditya Bagaskara Posted February 8, 2023 Author Posted February 8, 2023 So I have used a much simpler code using 'foreach' and tested it (setq lines (ssget) linesnum (sslength lines) lineslist '() intslist '() ) (setq count1 0) (while (< count1 linesnum) (setq lineslist (cons (ssname lines count1) lineslist)) (setq count1 (1+ count1)) ) (foreach i lineslist (setq endp11 (cdr (assoc 10 (entget i)))) (setq endp12 (cdr (assoc 11 (entget i)))) (foreach j lineslist (setq endp21 (cdr (assoc 10 (entget j)))) (setq endp22 (cdr (assoc 11 (entget j)))) (setq ints (inters endp11 endp12 endp21 endp22)) (if (not (member ints intslist)) (setq intslist (cons ints intslist)) ) ) ) Test 1 using lines that intersect perfectly at the grid This is the result that I wanted. No duplicates. Test 2 using lines that intersect not at the grid This is the result that I do not want. There are duplicates. How is this possible? Is it somehow has to do with the 'member' command? Or the 'cons' ? Quote
Tharwat Posted February 8, 2023 Posted February 8, 2023 member function could help with plain values such integers, strings ... etc but not with list of coordinates that have embedded / suppressed values within, so you need to use equal function over each list in a list to check out for matches purposes. Besides that, you don't need to iterate the list two times so just check for equality / matches only once from the first list although rewriting the codes in another way would reduce the quantity of codes with much more efficient manner I believe. Quote
Aditya Bagaskara Posted February 8, 2023 Author Posted February 8, 2023 (edited) 10 minutes ago, Tharwat said: member function could help with plain values such integers, strings ... etc but not with list of coordinates that have embedded / suppressed values within, so you need to use equal function over each list in a list to check out for matches purposes. Ah I see. So the 'member' command can't handle the coordinate from the Model space. I did used the 'equal' command and it worked fine, but it took me a long route though. Thank you for the clarification. 10 minutes ago, Tharwat said: Besides that, you don't need to iterate the list two times so just check for equality / matches only once from the first list although rewriting the codes in another way would reduce the quantity of codes with much more efficient manner I believe. I'm soory sir, I don't quite follow what you just said. I believe that by iterating the list two times, I can check for every possible combinations for checking intersections from all possible pair of lines. Edited February 8, 2023 by Aditya Bagaskara Quote
mhupp Posted February 8, 2023 Posted February 8, 2023 (edited) 42 minutes ago, Aditya Bagaskara said: Ah I see. So the 'member' command can't handle the coordinate from the Model space. It can but only matches same values. even if you tell AutoCAD to draw a line from 50,50 it might be 50.00000000000001, 50.000000000000000000001 and thats not the same as 50,50. With equal you can give it a fuzz distance. This (equal 50 # 0.01) will return T for any number between 50.01 - 49.99 Edited February 8, 2023 by mhupp 2 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.