Author Topic: (list compare..in another list..  (Read 4664 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
(list compare..in another list..
« on: April 21, 2006, 12:57:02 PM »
woo !

I'm trying to figure out how to...but... :ugly:

there it is..
I have a list containing a list...

(("TEST1" "4.2" 2.34")("TEST2" "45.42" 4.34")("TEST3" "4.2" 3.5")("TEST4" "4.4" 2.34"))

all second list have 3 items
eg:

"TEST1" is a text
"4.2" is the X coord
"2.34" is the Y coord.

I need to compare each Y cood with the other to see if some text is at the same Y
and than, strcat all text having the same Y and put it on a another list...

 :cry:  hard for me to explain...

in fact..
I need to select by a crossing or window the text (see picture)
and have to result this.:

("1 test1 ok1" "2 test2 ok2" "3 test3 ok3" "4 test4" "test5 ok5" "6 ok6" "7 test7")

I was wondering doing it with list....but i'm lost now...
maybe my brain cpu is out of memory... :-o

If someone understand what i'm trying to do...
please...dont be shy to submit some suggestions..

thanks.
« Last Edit: April 21, 2006, 01:03:01 PM by Andrea »
Keep smile...

Tramber

  • Guest
Re: (list compare..in another list..
« Reply #1 on: April 21, 2006, 01:17:43 PM »
(("TEST1" "4.2" 2.34")("TEST2" "45.42" 4.34")("TEST3" "4.2" 3.5")("TEST4" "4.4" 2.34"))
seems false.
There are 5 " per pair of parenthesis.

Do you need to compare the Ys from to its near neighbour or to all the others ?
In other words, will you use MEMBER or VL-SORT  ^-^ for exemple ?

And, what's the link to the other list, wich is buit so differently and that I don't understand ?

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
Re: (list compare..in another list..
« Reply #2 on: April 21, 2006, 01:26:46 PM »
Andrea, Tony Tanzillo posted a SelectionSet re-sort routine on the autodesk newsgroups that will get you most of the way to your goal. Search there for the thread "Selection set re-sort" started on March 23, 2000 by Dan Elkins.

I would just repost it here, but Tony placed a copyright notice in the code and since he does not visit here I thought it best to direct you to it.

Tramber

  • Guest
Re: (list compare..in another list..
« Reply #3 on: April 21, 2006, 01:46:59 PM »
Do you want to remove 1 or 2 elements each time you find one having the same Y of the other one ?

Check this :
Code: [Select]
(setq l1 '(("TEST1" "4.2" "2.34")("TEST4" "4.4" "6.34")("TEST2" "45.42" "4.34")("TEST3" "4.2" "3.5")))
(setq l2(vl-sort l1(function (lambda (e1 e2)(< (caddr e1) (caddr e2)))))); sorted by Ys

It sorts the elements, for the next step, I need to understand more before helping.

Tramber

  • Guest
Re: (list compare..in another list..
« Reply #4 on: April 21, 2006, 01:52:47 PM »
Then, this code :
Code: [Select]
(setq endlA nil endlB nil compt 0)
(repeat(1-(length l2))
  (if(=(caddr(nth compt l2))(caddr(nth(1+ compt)l2)))
    (setq endlA(append endlA(list(nth compt l2))))
    (setq endlB(append endlB(list(nth compt l2)))))
  (setq compt(1+ compt)))
(setq endlB(append endlB(list(last l2))))
endlA  endlB

will build 2 lists but is not very fast and tightened

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (list compare..in another list..
« Reply #5 on: April 21, 2006, 01:55:37 PM »
If I have correctly understood a problem...

Creation of the test list:
Code: [Select]
(if(setq
     ss (ssget
          "_X"
          (list
            '(0 . "MTEXT,TEXT")
            '(1 . "test#")
          ) ;_  list
        ) ;_  ssget
   ) ;_  setq
  (setq lst (mapcar
              (function
                (lambda (x)
                  (list
                    (cdr (assoc 1 (entget x)))
                    (rtos(cadr (assoc 10 (entget x))) 2 2)
                    (rtos(caddr (assoc 10 (entget x))) 2 2)
                  ) ;_  list
                ) ;_  lambda
              ) ;_  function
              (vl-remove-if (function listp)
                            (mapcar (function cadr) (ssnamex ss))
              ) ;_ vl-remove-if
            ) ;_  mapcar
  ) ;_  setq
)

The program:
Code: [Select]
(mapcar
  (function
    (lambda (x / e)
      (strcat
        (if (setq e (ssget "_X"
                           (list
                             '(0 . "MTEXT,TEXT")
                             '(-4 . "<and")
                             '(-4 . "<,>,*")
                             (list 10 (- (atof (cadr x)) 0.01) (- (atof (caddr x)) 0.01) 0.)
                             '(-4 . "<,<,*")
                             (list 10 (- (atof (cadr x)) 0.01) (+ (atof (caddr x)) 0.01) 0.)
                             '(-4 . "and>")
                           ) ;_  list
                    ) ;_  ssget
            ) ;_  setq
          (cdr (assoc 1 (entget (ssname e 0))))
          ""
        ) ;_  if
        " "
        (car x)
        " "
        (if (setq e nil
                  e (ssget "_X"
                           (list
                             '(0 . "MTEXT,TEXT")
                             '(-4 . "<and")
                             '(-4 . ">,>,*")
                             (list 10 (+ (atof (cadr x)) 0.01) (- (atof (caddr x)) 0.01) 0.)
                             '(-4 . ">,<,*")
                             (list 10 (+ (atof (cadr x)) 0.01) (+ (atof (caddr x)) 0.01) 0.)
                             '(-4 . "and>")
                           ) ;_  list
                    ) ;_  ssget
            ) ;_  setq
          (cdr (assoc 1 (entget (ssname e 0))))
          ""
        ) ;_  if
      ) ;_  strcat
    ) ;_  lambda
  ) ;_  function
  lst
)
; =>
("1 test1 ok1" "2 test2 ok2" "3 test3 ok3" "4 test4" "test5 ok5" "6 ok6" "7 test7")

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (list compare..in another list..
« Reply #6 on: April 21, 2006, 02:14:16 PM »
no...not need to sort anything..
just stay like it is...

since this morning I'm trying to do something like this...
and you guys shoot me the code in less of 10 min...

ElpanovEvgeniy got the solution..!
thanks you all...

you'r génious ! :-)

Now the only thing I need to do...
Is studying the code.... :ugly:
Keep smile...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (list compare..in another list..
« Reply #7 on: April 21, 2006, 02:34:15 PM »
no...not need to sort anything..
just stay like it is...

since this morning I'm trying to do something like this...
and you guys shoot me the code in less of 10 min...

ElpanovEvgeniy got the solution..!
thanks you all...

you'r génious ! :-)

Now the only thing I need to do...
Is studying the code.... :ugly:

Then I shall add, the program will work even if the text is not visible on the screen! :-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10634
Re: (list compare..in another list..
« Reply #8 on: April 21, 2006, 02:53:12 PM »
*lol* Your amazing Elpanov.
How long did that take you to write?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (list compare..in another list..
« Reply #9 on: April 21, 2006, 02:54:51 PM »
*lol* Your amazing Elpanov.
How long did that take you to write?
Ten minutes... :-)

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (list compare..in another list..
« Reply #10 on: April 21, 2006, 03:05:30 PM »
Keep smile...

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (list compare..in another list..
« Reply #11 on: April 21, 2006, 03:17:31 PM »
by the way...

I have noted that when MTEXT is selected...the result is...

Code: [Select]
("line1 line2\\PLine 3\\PLine4" "572.06" "811.29")
in this exemple..no "enter" done between line1 and line2 no I dont have the \\P switch..
Keep smile...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (list compare..in another list..
« Reply #12 on: April 21, 2006, 03:37:47 PM »
by the way...

I have noted that when MTEXT is selected...the result is...

Code: [Select]
("line1 line2\\PLine 3\\PLine4" "572.06" "811.29")
in this exemple..no "enter" done between line1 and line2 no I dont have the \\P switch..

Probably, I not correctly have understood you...
At you the test text has many lines with formatting and spaces?

Andrea

  • Water Moccasin
  • Posts: 2372
Re: (list compare..in another list..
« Reply #13 on: April 21, 2006, 03:56:11 PM »
by the way...

I have noted that when MTEXT is selected...the result is...

Code: [Select]
("line1 line2\\PLine 3\\PLine4" "572.06" "811.29")
in this exemple..no "enter" done between line1 and line2 no I dont have the \\P switch..

Probably, I not correctly have understood you...
At you the test text has many lines with formatting and spaces?

No, in fact, i have written 4 line of MTEXT, between the 2 first line i haven't use "ENTER" to switch line..
but I use it between the 3rd and 4th line.. so when "ENTER" is use in MTEXT the result return \\P for each "ENTER".

Also,..i'm trying to understand your code...
Code: [Select]
(if (setq e (ssget "_X"
                          (list
                            '(0 . "MTEXT,TEXT")
                            '(-4 . "<and")
                            '(-4 . "<,>,*")
                            (list 10 (- (atof (cadr x)) 0.01) (- (atof (caddr x)) 0.01) 0.)
                            '(-4 . "<,<,*")
                            (list 10 (- (atof (cadr x)) 0.01) (+ (atof (caddr x)) 0.01) 0.)
                            '(-4 . "and>")
                          ) ;_  list
                   ) ;_  ssget
           ) ;_  setq
         (cdr (assoc 1 (entget (ssname e 0))))
         ""
       ) ;_  if

but I don't know why you r using..

                       
Code: [Select]
     '(-4 . "<and")
                            '(-4 . "<,>,*")
I don'T understand....could you explain please ?
I'm trying to modify your routine to alle user that tey can make selection...
like

Code: [Select]
(setq e (SSGET '((0 . "TEXT")))

thanks.
Keep smile...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: (list compare..in another list..
« Reply #14 on: April 21, 2006, 04:25:02 PM »
I wrote the program which handles separate primitives (each visible text on your picture, a separate primitive)

but I don't know why you r using..
                       
Code: [Select]
     '(-4 . "<and")
                            '(-4 . "<,>,*")
I don'T understand....could you explain please ?
I'm trying to modify your routine to alle user that tey can make selection...
like

It is the usual filter of coordinates...