TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on October 07, 2021, 04:53:07 PM

Title: Selecting multiple objects fail
Post by: jlogan02 on October 07, 2021, 04:53:07 PM
Quick piece of code to change selected text to green and then edit selected text.

When I run it, it lets me select multiple text objects and changes all of them to green but only allows editing of the last text
object selected.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Appred ( / sel1)
  2.  (if (setq sel1 (ssget))
  3.  
  4.    (foreach x (mapcar 'cadr (ssnamex sel1))
  5.      (entmod (append (entget x) '((62 . 3))))
  6.      )
  7.    )
  8.      (command "textedit" sel1 "")
  9.    (while (> (getvar "cmdactive") 0)
  10.      (command "pause")
  11.    )  
  12.   )
(if (setq sel1 (ssget))
 
 
Title: Re: Selecting multiple objects fail
Post by: ronjonp on October 07, 2021, 05:50:10 PM
Quick piece of code to change selected text to green and then edit selected text.

When I run it, it lets me select multiple text objects and changes all of them to green but only allows editing of the last text
object selected.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Appred ( / sel1)
  2.  (if (setq sel1 (ssget))
  3.  
  4.    (foreach x (mapcar 'cadr (ssnamex sel1))
  5.      (entmod (append (entget x) '((62 . 3))))
  6.      )
  7.    )
  8.      (command "textedit" sel1 "")
  9.    (while (> (getvar "cmdactive") 0)
  10.      (command "pause")
  11.    )  
  12.   )
(if (setq sel1 (ssget))
 
One thing .. if you're wanting to select text you should filter for them and also use (vl-remove-if 'listp ...
Code - Auto/Visual Lisp: [Select]
  1. (defun c:appred (/ sel1)
  2.   (if (setq sel1 (ssget '((0 . "TEXT"))))
  3.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex sel1)))
  4.       (entmod (append (entget x) '((62 . 3))))
  5.       (command "_.textedit" x "")
  6.     )
  7.   )
  8.   (princ)
  9. )
Title: Re: Selecting multiple objects fail
Post by: jlogan02 on October 08, 2021, 01:43:38 PM
Quick piece of code to change selected text to green and then edit selected text.

When I run it, it lets me select multiple text objects and changes all of them to green but only allows editing of the last text
object selected.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Appred ( / sel1)
  2.  (if (setq sel1 (ssget))
  3.  
  4.    (foreach x (mapcar 'cadr (ssnamex sel1))
  5.      (entmod (append (entget x) '((62 . 3))))
  6.      )
  7.    )
  8.      (command "textedit" sel1 "")
  9.    (while (> (getvar "cmdactive") 0)
  10.      (command "pause")
  11.    )  
  12.   )
(if (setq sel1 (ssget))
 
One thing .. if you're wanting to select text you should filter for them and also use (vl-remove-if 'listp ...
Code - Auto/Visual Lisp: [Select]
  1. (defun c:appred (/ sel1)
  2.   (if (setq sel1 (ssget '((0 . "TEXT"))))
  3.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex sel1)))
  4.       (entmod (append (entget x) '((62 . 3))))
  5.       (command "_.textedit" x "")
  6.     )
  7.   )
  8.   (princ)
  9. )

It's those little things that always get me. I either read (comprehend) wrong, or in this case didn't know.

Thanks RonJonp