Author Topic: issues changing 1 item in a list of multiple items with identical items in list  (Read 5612 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7533
Excuse me if I'm way off, but give this a try. Make a selection of your text from the  ' FT ' column to the ' REV ' column. You will have to deal with the formatting of fractions.
Code: [Select]
(defun c:foo (/ _dxf _mod _ss2l h l l1 p result tmp txt x)
  (defun _ss2l (ss / n result)
    (if   (= (type ss) 'pickset)
      (repeat (setq n (sslength ss)) (setq result (cons (ssname ss (setq n (1- n))) result)))
    )
  )
  (defun _dxf (code ename)
    (if   (and ename (= (type ename) 'ename))
      (cdr (assoc code (entget ename '("*"))))
    )
  )
  (defun _mod (ename code value)
    (if   (and ename (= (type ename) 'ename))
      (entmod (subst (cons code value) (assoc code (entget ename)) (entget ename)))
    )
  )
  (if
    (setq l (mapcar (function (lambda (x) (cons (_dxf 10 x) x))) (_ss2l (ssget '((0 . "text"))))))
     (progn (while (setq txt (car l))
         ;; Insertion point
         (setq p (car txt))
         ;; 1/2 Text Height for fuzz
         (setq h (* 0.5 (_dxf 40 (cdr txt))))
         ;; Sort lines by Y coord then X coord
         (setq tmp   (vl-sort (vl-remove-if-not '(lambda (x) (equal (cadr (car x)) (cadr p) h)) l)
             '(lambda (a b) (< (caar a) (caar b)))
         )
         )
         ;; Create list of lines
         (setq result (cons tmp result))
         ;; Remove from list
         (mapcar '(lambda (x) (setq l (vl-remove x l))) tmp)
       )
       ;; Sort lines from top to bottom and remove insertion points
       (setq result (mapcar '(lambda (x) (mapcar 'cdr x))
             (vl-sort result '(lambda (a b) (> (cadr (caar a)) (cadr (caar b)))))
          )
       )
       ;; Process the lines
       (while (setq tmp (cadr result))
         (setq l1 (car result))
         (if (and (= (_dxf 1 (car l1)) "-") (= (_dxf 1 (cadr l1)) "-"))
      (setq result (cddr result))
      (progn (_mod (caddr tmp)
              1
              (strcat (if (= (_dxf 1 (caddr tmp)) "-")
                   ""
                   (strcat (_dxf 1 (caddr tmp)) " ")
                 )
                 (vl-princ-to-string
                   (+ (* 12. (atof (_dxf 1 (car l1))))
                 (if (distof (_dxf 1 (cadr l1)))
                   (distof (_dxf 1 (cadr l1)))
                   0
                 )
                   )
                 )
                 " LG"
              )
             )
             (_mod (car l1) 1 "-")
             (_mod (cadr l1) 1 "-")
             (setq result (cddr result))
      )
         )
       )
     )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
hi Ron,
Thats what i basically i have with the code i last posted and works the same way the only thing is when i go to write the info back into the  list i get undesirable results.

i will play around with your code and see how it works with writing it back into a list.

thank you for your help

andrew_nao

  • Guest
just wanted to post here 1 more time and thank ron for his help.
i got my code to do what i wanted.

while my numb brain still cant grasp what lambda does. i learn a bit from his code.

again thank you Ron for your time

ronjonp

  • Needs a day job
  • Posts: 7533
just wanted to post here 1 more time and thank ron for his help.
i got my code to do what i wanted.

while my numb brain still cant grasp what lambda does. i learn a bit from his code.

again thank you Ron for your time


Glad to help :).


Does the code below make any sense to you?
Code: [Select]
(setq nx10 (mapcar '(lambda (x) (* x 10)) '(1 2 3 4 5 6 7 8.0 9.0 10)))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
Quote from: ronjonp


Glad to help :).


Does the code below make any sense to you?
Code: [Select]
(setq nx10 (mapcar '(lambda (x) (* x 10)) '(1 2 3 4 5 6 7 8.0 9.0 10)))

i understand that as take a number in that list and multiple it by 10

ronjonp

  • Needs a day job
  • Posts: 7533
What about this one:
Code: [Select]
(setq nx10
       (mapcar '(lambda (a b) (* a b)) '(1 2 3 4 5 6 7 8.0 9.0 10) '(10 10 10 10 10 10 10 10 10 10))
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
What about this one:
Code: [Select]
(setq nx10
       (mapcar '(lambda (a b) (* a b)) '(1 2 3 4 5 6 7 8.0 9.0 10) '(10 10 10 10 10 10 10 10 10 10))
)

No need for the lambda in that one  :wink:

(mapcar '* ...

andrew_nao

  • Guest
What about this one:
Code: [Select]
(setq nx10
       (mapcar '(lambda (a b) (* a b)) '(1 2 3 4 5 6 7 8.0 9.0 10) '(10 10 10 10 10 10 10 10 10 10))
)

looks like it does the same thing

ronjonp

  • Needs a day job
  • Posts: 7533
What about this one:
Code: [Select]
(setq nx10
       (mapcar '(lambda (a b) (* a b)) '(1 2 3 4 5 6 7 8.0 9.0 10) '(10 10 10 10 10 10 10 10 10 10))
)

No need for the lambda in that one  ;)

(mapcar '* ...


I was trying to somewhat relate it to the last example to not confuse Andrew ( unfortunately my teaching skill are lacking ), and yes you are correct that the solution can be shortened.  :whistling:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
I was trying to somewhat relate it to the last example to not confuse Andrew ( unfortunately my teaching skill are lacking ), and yes you are correct that the solution can be shortened.  :whistling:

Sorry for stepping on your toes Ron  :oops:

ronjonp

  • Needs a day job
  • Posts: 7533
I was trying to somewhat relate it to the last example to not confuse Andrew ( unfortunately my teaching skill are lacking ), and yes you are correct that the solution can be shortened.  :whistling:

Sorry for stepping on your toes Ron  :oops:


 :) No toe stepping at all Lee . Just clarifying my train of thought. I enjoy watching the way you solve problems.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC