CADWORKER Posted September 20, 2023 Share Posted September 20, 2023 (Defun c:Tx2 (/ *error* lay ent pnt pnt2) (while (setq txt (car (ssget "\nSelect text: "))) (setq pnt (trans (cdr (assoc 10 (entget txt))) 0 1)) (setpropertyvalue txt "Height" 2) ) (*error* "end") ) Hi, I had a lisp to select each text to change the height, but when I replaced the entget to ssget its not working. How to fix this. Please let me know or any other lisp code for doing this. Thanks. Quote Link to comment Share on other sites More sharing options...
mhupp Posted September 20, 2023 Share Posted September 20, 2023 entsel returns the entity name and the point of our curser. (entity<asfasdf> (x, y)) ssget returns a list of entity names and the last point selected with the mouse. The code would work but for only the first entity in the selection set. You need to step thought the entire list of entity names for it to work properly. I like using the foreach function. Code untested but should work. (defun c:TH2 (/ ss pnt) (while (setq ss (ssget ":L" '((0 . "TEXT") ))) ;Selects only text on unlocked layers (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq pnt (trans (cdr (assoc 10 (entget txt))) 0 1)) (setpropertyvalue txt "Height" 2) ) ) (princ) ) 1 Quote Link to comment Share on other sites More sharing options...
exceed Posted September 21, 2023 Share Posted September 21, 2023 (edited) (defun c:tx2 ( / ss ssl index ent obj ) (vl-load-com) ; Loads Visual LISP extensions to AutoLISP (princ "\n Select Texts to Change Height to 2") ; ssget doesn't take small talk as an argument, ; so if there's anything you want to say to the user, write it separately at the front. (setq ss (ssget ":L" '((0 . "TEXT")))) ; Insert TEXTs from among those selected by the user into the variable ss. ":L" is an option to exclude locked layers. (setq ssl (sslength ss)) ; Find out how many objects in ss. (setq index 0) ; To use it within repeat, first declare the index as 0. (repeat ssl ; Repeat as many times as ss. (setq ent (ssname ss index)) ; get only 1 item from ss into ent with ssname. ; When extracting something from a list (nth index list), note that the order is different. (setq obj (vlax-ename->vla-object ent)) ; You can directly edit the ent list by subst, assoc, and cons or something. ; but since it is hard for starter to memorize the list numbers what is that property. so convert to object. (vlax-put-property obj 'height 2) ; Set the height value to 2 in this obj. (setq index (+ index 1)) ; Add 1 to index, place it back in index, and end the turn. After this, ; it goes up again to (setq ent (ssname ss index)) by repeat. ) (princ) ; to silence the parrot-like repetition of the last value. ) I don't know what setpropertyvalue or pnt pnt2 are for, but if you only change the text height to 2, Since mhupp already gave a good answer with foreach, I will write with repeat. Edited September 21, 2023 by exceed 1 Quote Link to comment Share on other sites More sharing options...
CADWORKER Posted September 21, 2023 Author Share Posted September 21, 2023 Thank you Mhupp and Exceed for all your help. both the codes are very good. Quote Link to comment Share on other sites More sharing options...
mhupp Posted September 21, 2023 Share Posted September 21, 2023 17 hours ago, exceed said: I don't know what setpropertyvalue or pnt pnt2 are for. Yeah don't know what pnt was for either just left it in. But for setpropertyvalue its a Autocad Function that sets values of an entity. you can feed it enames as well with out having to convert over to vla-objects. You can also use getpropertyvalue to pull things like attributes strings from blocks. with just one line of code. 1 Quote Link to comment Share on other sites More sharing options...
CADWORKER Posted September 24, 2023 Author Share Posted September 24, 2023 On 9/20/2023 at 7:21 PM, mhupp said: entsel returns the entity name and the point of our curser. (entity<asfasdf> (x, y)) ssget returns a list of entity names and the last point selected with the mouse. The code would work but for only the first entity in the selection set. You need to step thought the entire list of entity names for it to work properly. I like using the foreach function. Code untested but should work. (defun c:TH2 (/ ss pnt) (while (setq ss (ssget ":L" '((0 . "TEXT") ))) ;Selects only text on unlocked layers (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq pnt (trans (cdr (assoc 10 (entget txt))) 0 1)) (setpropertyvalue txt "Height" 2) ) ) (princ) ) Can we include adjusting the text width to 0.8? Quote Link to comment Share on other sites More sharing options...
asos2000 Posted September 24, 2023 Share Posted September 24, 2023 (edited) 2 hours ago, CADWORKER said: Can we include adjusting the text width to 0.8? (defun c:TH2 (/ ss pnt) (while (setq ss (ssget ":L" '((0 . "TEXT") ))) ;Selects only text on unlocked layers (foreach txt (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) (setq pnt (trans (cdr (assoc 10 (entget txt))) 0 1)) (setpropertyvalue txt "Height" 2) (setpropertyvalue txt "WIDTHFACTOR" 0.8) ; ADD THIS LINE ) ) (princ) ) And for another routine (vlax-put-property obj 'height 2) ; Set the height value to 2 in this obj. (vlax-put-property obj 'WIDTHFACTOR 0.8) ; Set the WIDTH value to .8 in this obj. <<<< ADD THIS LINE Edited September 24, 2023 by asos2000 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.