Author Topic: Selecting multiple objects fail  (Read 149 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 230
Selecting multiple objects fail
« 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))
 
 
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

ronjonp

  • Needs a day job
  • Posts: 7335
Re: Selecting multiple objects fail
« Reply #1 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. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

jlogan02

  • Bull Frog
  • Posts: 230
Re: Selecting multiple objects fail
« Reply #2 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
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10