Author Topic: Help List  (Read 5819 times)

0 Members and 1 Guest are viewing this topic.

velasquez

  • Newt
  • Posts: 195
Help List
« on: July 18, 2014, 03:34:03 PM »
I need help for a problem with lists:

I have:
list1: ->
Code: [Select]
(setq list1 (list '("1" "testA") '("2" "testB") '("3" "testC")))and
list2: ->
Code: [Select]
(setq list2 (list '("testA" "nononno") '("testB" "vcvcvcv") '("testC" "nmnmnmn") '("nonono" "xccxcxc") '("xxxxxx" "jhjhjhjj")))I need to get list3 ->
Code: [Select]
'(("1" "teste
A" "aaaaaa") ("2" "testB" "vcvcvcv") ("3" "testC" "nmnmnmn") ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj"))

Can anyone help me?

Thanks

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #1 on: July 18, 2014, 04:05:42 PM »
Quick one:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( l1 l2 )
  2.     (setq l1 (mapcar 'reverse l1))
  3.     (mapcar '(lambda ( x / a ) (if (setq a (assoc (car x) l1)) (reverse (cons (cadr x) a)) (cons "" x))) l2)
  4. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (foo list1 list2)
  2. (("1" "testA" "nononno") ("2" "testB" "vcvcvcv") ("3" "testC" "nmnmnmn") ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj"))

Actually, this is slightly shorter:
Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( l1 l2 )
  2.     (setq l1 (mapcar 'reverse l1))
  3.     (mapcar '(lambda ( x / a ) (if (setq a (assoc (car x) l1)) (cons (cadr a) x) (cons "" x))) l2)
  4. )
« Last Edit: July 18, 2014, 04:10:37 PM by Lee Mac »

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #2 on: July 18, 2014, 04:36:27 PM »
Thank you Lee
Your help was very important again.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #3 on: July 19, 2014, 05:28:48 AM »
You're welcome velasquez  :-)

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #4 on: July 19, 2014, 05:32:43 AM »
Another, recursive variation (slow):

Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( a b )
  2.     (if b (cons (bar (car b) a) (foo a (cdr b))))
  3. )
  4. (defun bar ( x l )
  5.     (cond
  6.         (   (null l) (cons "" x))
  7.         (   (= (cadar l) (car x)) (cons (caar l) x))
  8.         (   (bar x (cdr l)))
  9.     )
  10. )

Code - Auto/Visual Lisp: [Select]
  1. _$ (foo list1 list2)
  2. (("1" "testA" "nononno") ("2" "testB" "vcvcvcv") ("3" "testC" "nmnmnmn") ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj"))

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Help List
« Reply #5 on: July 19, 2014, 06:56:32 AM »
or a little simpler way would:
Code - Auto/Visual Lisp: [Select]
  1. (setq list3 nil)
  2. (foreach a list1
  3.   (setq list3 (cons (list (car a)
  4.                           (cadr a)
  5.                           (cadr (assoc (cadr a) list2))) list3)))
  6. (setq list3 (reverse list3))
  7.  

No error checking though which I would recommend  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #6 on: July 19, 2014, 07:56:55 AM »
or a little simpler way would:
Code - Auto/Visual Lisp: [Select]
  1. (setq list3 nil)
  2. (foreach a list1
  3.   (setq list3 (cons (list (car a)
  4.                           (cadr a)
  5.                           (cadr (assoc (cadr a) list2))) list3)))
  6. (setq list3 (reverse list3))
  7.  

What about these items David:
Code - Auto/Visual Lisp: [Select]
  1. ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj")

:wink:

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Help List
« Reply #7 on: July 19, 2014, 10:44:57 AM »

What about these items David:
Code - Auto/Visual Lisp: [Select]
  1. ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj")

:wink:

Like I said  it needs error checking.  I don't believe there would be any correct answer to your scenario.  My $0.02  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #8 on: July 19, 2014, 12:25:37 PM »

What about these items David:
Code - Auto/Visual Lisp: [Select]
  1. ("" "nonono" "xccxcxc") ("" "xxxxxx" "jhjhjhjj")

:wink:

Like I said  it needs error checking.  I don't believe there would be any correct answer to your scenario.  My $0.02  -David

I'm just going by the result requested by the OP.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help List
« Reply #9 on: July 19, 2014, 03:55:44 PM »
Just a question: Are the 2 lists always in the same order? If so a slightly faster version:
Code - Auto/Visual Lisp: [Select]
  1. (defun combine (L1 L2 / L3)
  2.   (setq L3 L2)
  3.   (append (mapcar '(lambda (a b) (setq L3 (cdr L3)) (cons (car a) b))) L1 L2)
  4.           (mapcar '(lambda (c) (cons "" c)) L3)))
Else you'll need the assoc to extract the correct item from either L1 or L2 (as the others' are doing).

BTW, is the 2nd list always longer (or same length) as the first or could the 1st list be longer? If so how should the result then look?
« Last Edit: July 19, 2014, 03:59:41 PM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #10 on: July 25, 2014, 07:52:14 PM »
You're welcome velasquez  :-)
Hi Lee,
I modified your function foo and got the list3 as follows:
Code: [Select]
(defun LM:foo+ (l1 l2)
  (setq l1 (mapcar 'reverse l1))
  (mapcar '(lambda (x / a)
             (if (setq a (assoc (car x) l1))
               (subst (cadr a) (car x) x)
               (subst "" (car x) x)
             ) ;_ fim de if
           ) ;_ fim de lambda
          l2
  ) ;_ fim de mapcar
) ;_ fim de defun
Code: [Select]
(setq list1 '(("1" "SG_1_TBLUTOP_D90_L2000") ("2" "SG_3_CP90FB-BLUTOP10PECB_D90") ("3" "SG_1_CC90B-BLUTOPPECB_D90")))
(setq list2 '(("SG_1_CC90B-BLUTOPPECB_D90" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0") ("SG_3_CP90FB-BLUTOP10PECB_D90" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0") ("SG_1_TBLUTOP_D90_L2000" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000") ("SG_1_KB-BLUTOPPECB_D90" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0") ("SG_1_KB-BLUTOPTIPECB_D160" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")))
 
I got the list3 with this order:
Code: [Select]
_$ (setq list3 (LM:FOO+ list1 list2))
(("3" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0") ("2" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0") ("1" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000") ("" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0") ("" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0"))
_$
You can help me sort the list as list4:?
Code: [Select]
'(("1" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000")
  ("2" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0")
  ("3" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0")
  ("" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0")
  ("" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0"))

Thanks for the time and the help of all.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #11 on: July 25, 2014, 08:00:07 PM »
Quick one:
Code - Auto/Visual Lisp: [Select]
  1. (setq l
  2.    '(
  3.         ("3" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0")
  4.         ("2" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0")
  5.         ("1" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000")
  6.         ("" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0")
  7.         ("" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")
  8.     )
  9. )
  10.  
  11. (vl-sort l '(lambda ( a b ) (if (and (/= "" (car a)) (/= "" (car b))) (< (atoi (car a)) (atoi (car b))))))

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #12 on: July 26, 2014, 06:09:26 AM »
Quick one:
Code - Auto/Visual Lisp: [Select]
  1. (setq l
  2.    '(
  3.         ("3" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0")
  4.         ("2" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0")
  5.         ("1" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000")
  6.         ("" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0")
  7.         ("" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")
  8.     )
  9. )
  10.  
  11. (vl-sort l '(lambda ( a b ) (if (and (/= "" (car a)) (/= "" (car b))) (< (atoi (car a)) (atoi (car b))))))

Perfect Lee.
Thanks

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #13 on: July 28, 2014, 09:22:57 AM »
I'm trying to better understand the mapcar and lambda functions.
I got a result with foreach but I can not say with mapcar.
Code: [Select]
;;;MyList -> (<Entity name: 7ffffc08530> <Entity name: 7ffffc05960> <Entity name: 7ffffc05440> ...)
(foreach JoyItem MyList
  (if (setq JoyTemp (dxf 1000 (JoyGetXdata (vlax-ename->vla-object JoyItem) "DuctilCAD_2D")))
    (setq JoyData (cons (list (dxf 2 (entget JoyItem)) JoyTemp) JoyData))
  ) ;_ fim de if
) ;_ fim de foreach

;;;returned list -> '(("SG_1_TNATJGS_D80_#D80" "TNATJGS;Tê com bolsas e junta elástica JGS - Linha Natural;80;80;0;0")
  ("SG_1_KB-BLUTOPTIPECB_D160" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")
  ("SG_1_TNATJGS_D80_#D80" "TNATJGS;Tê com bolsas e junta elástica JGS - Linha Natural;80;80;0;0")
  ("SG_1_KB-BLUTOPTIPECB_D160" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")
)
My question in this case is better to work with foreach?
I need to learn more about mapcar.

Thanks

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Help List
« Reply #14 on: July 28, 2014, 10:18:38 AM »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #15 on: July 30, 2014, 05:47:20 PM »
Quick one:
Code - Auto/Visual Lisp: [Select]
  1. (setq l
  2.    '(
  3.         ("3" "CC90B-BLUTOPPECB;Curva 90° com bolsas JE - Sistema Blutop;90;0;0;0")
  4.         ("2" "CP90FB-BLUTOP10/16PECB;Curva 90° com pé, bolsa e flange JE - Sistema Blutop;80;80;10;0")
  5.         ("1" "TBLUTOP;Tubo ponta e bolsa JE - Sistema Blutop;90;0;0;2000")
  6.         ("" "KB-BLUTOPPECB;Cap JE - Sistema Blutop;90;0;0;0")
  7.         ("" "KB-BLUTOPTIPECB;Cap JTI - Sistema Blutop;160;0;0;0")
  8.     )
  9. )
  10.  
  11. (vl-sort l '(lambda ( a b ) (if (and (/= "" (car a)) (/= "" (car b))) (< (atoi (car a)) (atoi (car b))))))

I'm trying to sort a list by its second element.
The first element is always variable.
Laboring with the result vl-sort not working.
Lee Please can you tell me what is wrong?

Code: [Select]
(setq l '(
          ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
          ("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
          ("C" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0")
          ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
          ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000")
          ("5" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
         ) ;_ fim de list
)
(vl-sort l '(lambda (a b) (eq (cadr a) (cadr b))))

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help List
« Reply #16 on: July 30, 2014, 06:35:29 PM »
Try this:
Code: [Select]
(vl-sort l '(lambda (a b) (< (cadr a) (cadr b))))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #17 on: July 30, 2014, 07:13:41 PM »
Try this:
Code: [Select]
(vl-sort l '(lambda (a b) (< (cadr a) (cadr b))))

Thanks ronjonp I used your suggestion in a function to count the items in a list.
Can you tell me how I can improve my way?
Code: [Select]
(defun JoyFinalizaLista (lst / n ent wrt)
  (while (> (length lst) 0)
    (setq ent (car lst)
          n   0
    ) ;_ fim de setq
    (while (and (car lst)
                (eq (cadr (car lst)) (cadr ent))
           ) ;_ fim de and
      (setq n (1+ n))
      (setq lst (cdr lst))
    ) ;_ fim de while
    (setq wrt (cons (append ent (list n)) wrt))
  ) ;_ fim de while
  wrt
)

;;;Result -> '(("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0" 3) ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0" 2) ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000" 1) ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0" 1) ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1) ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1))


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help List
« Reply #18 on: July 30, 2014, 09:50:21 PM »
Did you try this as suggested by Ron?
Code: [Select]
(defun JoyFinalizaLista (l)
  (vl-sort l '(lambda (a b) (< (cadr a) (cadr b))))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #19 on: July 31, 2014, 07:08:45 AM »
Did you try this as suggested by Ron?
Code: [Select]
(defun JoyFinalizaLista (l)
  (vl-sort l '(lambda (a b) (< (cadr a) (cadr b))))
)

Hello CAB,
Ron's suggestion worked perfectly.
I failed my goal when I showed her.
My question is the way that I showed to count the elements in the list can be improved.
I corrected my code.
Code: [Select]
(setq l '(
          ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
          ("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
          ("C" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0")
          ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000")
          ("5" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
          ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
          ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
         ) ;_ fim de list
)
;;;
(defun JoyFinalizaLista (lst / lst n ent wrt)
;;;BY RONJONP
(setq lst (vl-sort lst '(lambda (a b) (< (cadr a) (cadr b)))))
;;;
  (while (> (length lst) 0)
    (setq ent (car lst)
          n   0
    ) ;_ fim de setq
    (while (and (car lst)
                (eq (cadr (car lst)) (cadr ent))
           ) ;_ fim de and
      (setq n (1+ n))
      (setq lst (cdr lst))
    ) ;_ fim de while
    (setq wrt (cons (append ent (list n)) wrt))
  ) ;_ fim de while
  wrt
)
;;;TEST
_$ (JoyFinalizaLista l)
(("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0" 3) ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0" 2) ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000" 1) ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0" 1) ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1) ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1))
_$


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Help List
« Reply #20 on: July 31, 2014, 08:44:28 AM »
I don't understand what you are counting?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #21 on: July 31, 2014, 01:10:58 PM »
I don't understand what you are counting?

I'm counting the second item of each list (cadr ..) and adding the value at the end of the list.
I used the idea of ​​Ron to sort the list.
Please exeucte my code and observe the returned list.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help List
« Reply #22 on: July 31, 2014, 02:05:49 PM »
Give this a try:


Code: [Select]
(setq
  l '(("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
      ("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
      ("C" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0")
      ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
      ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000")
      ("5" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
     ) ;_ fim de list
)

(mapcar
  (function
    (lambda (x)
      (append
x
(list (length (vl-remove-if-not (function (lambda (txt) (= (cadr x) txt))) (mapcar 'cadr l)))
)
      )
    )
  )
  l
)
« Last Edit: July 31, 2014, 02:42:47 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #23 on: July 31, 2014, 03:04:29 PM »
Give this a try:


Code: [Select]
(setq
  l '(("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
      ("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0")
      ("C" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0")
      ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
      ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000")
      ("5" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0")
      ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0")
     ) ;_ fim de list
)

(mapcar
  (function
    (lambda (x)
      (append
x
(list (length (vl-remove-if-not (function (lambda (txt) (= (cadr x) txt))) (mapcar 'cadr l)))
)
      )
    )
  )
  l
)
Hi Ron,
Your code did the count I need.
But the list of return must be in the format below.
I'll study it.
Thank you very much.
Code: [Select]
(finalList '(("-" "VBFWCV10" "Válvula borboleta com flanges e volante na posição 1" "200" "0" "10" "0" 3) ("-" "TNATJGS" "Tê com bolsas e junta elástica JGS - Linha Natural" "80" "80" "0" "0" 2) ("-" "TBLUTOP" "Tubo ponta e bolsa JE - Sistema Blutop" "90" "0" "0" "2000" 1) ("-" "KB-BLUTOPTIPECB" "Cap JTI - Sistema Blutop" "160" "0" "0" "0" 1) ("-" "CC90B-BLUTOPPECB" "Curva 90° com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1) ("-" "CC22B-BLUTOPPECB" "Curva 22°30' com bolsas JE - Sistema Blutop" "90" "0" "0" "0" 1)))

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help List
« Reply #24 on: July 31, 2014, 03:49:22 PM »
Give this a whirl:

Code: [Select]
(while (setq line (car l))
  (setq tmp (vl-remove-if-not (function (lambda (x) (= (cadr line) (cadr x)))) l))
  (setq result (cons (append line (list (length tmp))) result))
  (mapcar (function (lambda (x) (setq l (vl-remove x l)))) tmp)
)
(setq result (vl-sort result '(lambda (a b) (< (cadr a) (cadr b)))))


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #25 on: July 31, 2014, 04:51:07 PM »
Another variation:

Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( l / a r )
  2.     (foreach x l
  3.         (if (setq a (assoc (cadr x) r))
  4.             (setq r (subst (subst (1+ (last a)) (last a) a) a r))
  5.             (setq r (cons  (append (cons (cadr x) x) '(1)) r))
  6.         )
  7.     )
  8.     (vl-sort (mapcar 'cdr r) '(lambda (a b) (> (cadr a) (cadr b))))
  9. )

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Help List
« Reply #26 on: July 31, 2014, 04:53:50 PM »
And another:

Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( l / n r x )
  2.     (while l
  3.         (setq x (car l)
  4.               n (length l)
  5.               l (vl-remove-if '(lambda ( y ) (= (cadr x) (cadr y))) (cdr l))
  6.               r (cons (append x (list (- n (length l)))) r)
  7.         )
  8.     )
  9.     (vl-sort r '(lambda (a b) (> (cadr a) (cadr b))))
  10. )

velasquez

  • Newt
  • Posts: 195
Re: Help List
« Reply #27 on: July 31, 2014, 05:25:35 PM »
Again your help was very important.
Thanks for the time you dedicated to my problems.