Jump to content

'member' somehow does not detect 'cons'-made list


Recommended Posts

Posted

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.)

Posted
On 2/6/2023 at 10:57 PM, mhupp said:

 

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?

Posted

Put in a (princ intslist) just before your foreach command, that might give you a clue what it happening maybe.

Posted

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

image.png.f589147a8930df7d9fb420de1bf90987.png

This is the result that I wanted. No duplicates.

image.png.214061eeaf354a33227fed6ec645c420.png

Test 2 using lines that intersect not at the grid

image.png.cbfd12d994b321cf97ed3359a7a017df.png

This is the result that I do not want. There are duplicates.

image.thumb.png.46d39f6d39e09fdb12ee544ffcbe4c82.png

 

How is this possible? Is it somehow has to do with the 'member' command? Or the 'cons' ?

Posted

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.

 

Posted (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 by Aditya Bagaskara
Posted (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 by mhupp
  • Like 2

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...