ABuckingham 发表于 2022-7-6 17:20:27

Test an object to see if it�

I have a routine that I use frequently at work and would like to improve it. The problem I have with it currently is that if I mis-click it cycles to the next number and I have to exit the command and start again. Basically I'd like the command to test the object to make sure it's text before running the iteration and "change" command.
 

(defun c:cx() ;;Edits text objects by replacing current text with a prefix and an incremental numerical suffix(setq prefix (getstring "Prefix:")) ;; prompts the user for the string prefix (setq startint (getint "Initial number:")) ;; prompts the user for the initial number (setq cnt 0) ;; intializes the counter(while   (PROGN   (setq ent (entsel)) ;;requests the first text to edit   (setq newstring (strcat prefix (itoa (+ startint cnt)))) ;;created the string   (command "change" (car ent) "" "" "" "" "" "" newstring) ;;replace the string   (setq cnt (1+ cnt)) ;; increment the counter    )) )
 
Thoughts?

borgunit 发表于 2022-7-6 18:20:50

Probably would want to replace entsel with something like this
 
(ssget '((0 . "TEXT")))
页: [1]
查看完整版本: Test an object to see if it�