leonucadomi Posted Thursday at 11:06 PM Posted Thursday at 11:06 PM hello guys: I need a selection filter to select texts and mtext other than 3.5 in size try this code from Master Lee (ssget '((0 . "CIRCLE") (-4 . "<>") (40 . 5.0))) modified (defun c:pru (/ ss ) (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) (princ) ) I need to identify texts other than 3.5 with some color. help please thanks Quote
DATVO Posted Friday at 06:26 AM Posted Friday at 06:26 AM (edited) 7 hours ago, leonucadomi said: hello guys: I need a selection filter to select texts and mtext other than 3.5 in size Try this: ;; Modified by DV. Visit my page at: https://lispautocad.gumroad.com/ (defun c:PRU (/ ss) (if (setq ss (ssget '((0 . "TEXT,MTEXT") (-4 . "<>") (40 . 3.5)))) (progn (sssetfirst nil ss) (princ (strcat "\nSelecting: " (itoa (sslength ss)) " objects.")) ) (princ "\nNo Object.") ) (princ) ) Edited Friday at 06:32 AM by DATVO 1 Quote
leonucadomi Posted Friday at 02:14 PM Author Posted Friday at 02:14 PM 7 hours ago, DATVO said: Try this: ;; Modified by DV. Visit my page at: https://lispautocad.gumroad.com/ (defun c:PRU (/ ss) (if (setq ss (ssget '((0 . "TEXT,MTEXT") (-4 . "<>") (40 . 3.5)))) (progn (sssetfirst nil ss) (princ (strcat "\nSelecting: " (itoa (sslength ss)) " objects.")) ) (princ "\nNo Object.") ) (princ) ) I ALREADY TRIED IT AND IT SELECTED THEM ALL FOR ME, I DON'T KNOW WHAT HAPPENS My purpose is to detect all texts that do not have a desired height, in this case 3.5 Quote
leonucadomi Posted Friday at 02:35 PM Author Posted Friday at 02:35 PM (defun c:pru2 ( / ss alturaColor colorNuevo) (setq alturaColor 3.5) ; Define la altura a verificar (setq colorNuevo 1) ; Define el color a aplicar (ej. rojo) (setq ss (ssget "X" '((0 . "TEXT,MTEXT")))) ; Selecciona todos los textos (if ss (progn (setq i 0) (while (setq en (ssname ss i)) (setq obj (vlax-ename->vla-object en)) (if (/= (vla-get-height obj) alturaColor) (vlax-put-property obj 'color colorNuevo) ; Cambia el color ) (setq i (1+ i)) ) ) ) (princ) ) This routine does what I need, but it has a problem that I cannot understand, I have objects in the paperspace that have a height of 3.5 and it recognizes them as if they did not have it and changes them to red. can someone help? thanks Quote
Steven P Posted Friday at 04:00 PM Posted Friday at 04:00 PM (edited) This (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) should work. You can change "TEXT" to "*TEXT" to also capture MText Though looking at the code you have, I am assuming that is just a snippet of what you want to do. Here are a couple of hints: (defun c:pru ( / ss ) ;;Yup localised variables, C: prompt, all good (setq ss (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) ) ;; ADDED (SETQ SS ... ) so that you can use the selection set later (princ (sslength ss)) ;; Added this in to show the result of the selection set (princ) ;;Exit quietly ) Edited Friday at 04:01 PM by Steven P 1 1 Quote
leonucadomi Posted Friday at 10:48 PM Author Posted Friday at 10:48 PM 6 hours ago, Steven P said: This (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) should work. You can change "TEXT" to "*TEXT" to also capture MText Though looking at the code you have, I am assuming that is just a snippet of what you want to do. Here are a couple of hints: (defun c:pru ( / ss ) ;;Yup localised variables, C: prompt, all good (setq ss (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) ) ;; ADDED (SETQ SS ... ) so that you can use the selection set later (princ (sslength ss)) ;; Added this in to show the result of the selection set (princ) ;;Exit quietly ) thanks, now I explain In the modelspace I have texts of different height in paperspace in the paperspace I have viewports of different scales If I use the chspace command and take those texts to paper space they should be 3.5 height I'm looking for a routine that helps me detect which texts do not meet that height in each viewport (defun c:test (/ EscVP StrScale2 StrScale) (setq old_err *error*)(defun *error* ( a / )(princ "") (setq *error* old_err)(princ)) (setvar "cmdecho" 0) (if (and (setq EntVP (car (entsel "\Seleccione VIEWPORT: "))) (= (cdr (assoc 0 (entget EntVP))) "VIEWPORT")) (progn (setq EscVP (vla-get-CustomScale (vlax-ename->vla-object EntVP))) (setq StrScale2 (rtos (* 3.5 (/ 1 EscVP)) 2 1)) (setq StrScale (rtos (/ 1 EscVP) 2 2) ) (setq vpnum (cdr (assoc 69 (entget EntVP ) ) ) ) (vl-cmdf "_.mspace") (setvar "CVPORT" vpnum) (setq ss (ssget '((0 . "TEXT") (-4 . "<>") (40 . 3.5))) ) (Prompt (strcat "\nLa escala de La Ventana es 1/" StrScale)) (princ "\nLos textos de 3.5 en el interior de la ventana deben ser de: ") (princ StrScale2) ) ) (setvar "cmdecho" 1) (princ) );fin defun I am looking to enter this calculated value here but it doesn't work Quote
GLAVCVS Posted Saturday at 07:09 AM Posted Saturday at 07:09 AM Hi I think it would be easier to find the problem if you attached an example drawing. 1 Quote
Steven P Posted Saturday at 09:09 AM Posted Saturday at 09:09 AM (edited) To enter the value into your selection set see below. In LISP the '( ... ) lists mean it is a static list, it is read exactly as it is written, (list ... ) means that CAD will create the list if for example variables are a part of the list, and (cons ... ), also used to create a list - in this case relevant to create a dotted pair. (setq MyThing 5) '(1 2 3 4 MyThing) is read as 1 2 3 4 MyThing - and an error since it is looking for MyThing to be a string, "MyThing" (list 1 2 3 4 MyThing) is read as 1 2 3 4 5 - list has been created by the LISP (cons 1 MyThing) is read as (1 . 5) So this might help... As above though you select the text with the selection set ss, but haven't done anything with it - if you are a part way through the LISP that is all good, but just put a report in so you can see it is working as it should as you go along perhaps (sslength SS) maybe. (Oh, just me, I also amended the indents, and added where commands end if over a few lines, I find it easier to read LISPs as below, that's all) (defun c:test (/ old_err EscVP StrScale2 TxtHt StrScale ss) (setq old_err *error*) (defun *error* ( a / ) ;; Add here return cmdecho to as it was, cmdecho 1 (princ "") (setq *error* old_err) (princ) ) ; End Error Defun (setvar "cmdecho" 0) ; perhaps record the state of cmdecho before here, and reset to that value at the end (if (and (setq EntVP (car (entsel "\Seleccione VIEWPORT: "))) (= (cdr (assoc 0 (entget EntVP))) "VIEWPORT") ) ; end and (progn (setq EscVP (vla-get-CustomScale (vlax-ename->vla-object EntVP))) (setq StrScale2 (rtos (* 3.5 (/ 1 EscVP)) 2 1)) (setq TxtHt (* 3.5 (/ 1 EscVP)) ) ; a number not a string ;; added this (setq StrScale (rtos (/ 1 EscVP) 2 2)) (setq vpnum (cdr (assoc 69 (entget EntVP )))) (vl-cmdf "_.mspace") (setvar "CVPORT" vpnum) (setq ss (ssget (list(0 . "TEXT") (-4 . "<>") (cons 40 TxtHt))) ) ;;What are you doing with ss now? (Prompt (strcat "\nLa escala de La Ventana es 1/" StrScale)) (princ "\nLos textos de 3.5 en el interior de la ventana deben ser de: ") (princ StrScale2) ) ; end progn ) ; end if (setvar "cmdecho" 1) (princ) );fin defun Edited Saturday at 09:12 AM by Steven P Quote
leonucadomi Posted 4 hours ago Author Posted 4 hours ago On 8/9/2025 at 1:09 AM, GLAVCVS said: Hi I think it would be easier to find the problem if you attached an example drawing. example.dwg Quote
leonucadomi Posted 4 hours ago Author Posted 4 hours ago Good morning, I'm going to explain the problem. I receive many dwg with different viewport scales, example 1:10,1:5, 1:8 etc... The texts in those viewports should have a height of 3.5 being in the paperspace What I do is that within the viewport I take a text and with the chspace command I put it in the paperspace and check in properties that its height is 3.5 If the text is correct in height, I copy the properties to others, sometimes they are just texts, sometimes there are also mtexts I would like a routine that just by touching the viewport will detect which of those texts do not meet the height I need, changing the color to red. Sometimes I just need to detect them and sometimes I need to modify them according to the instructions they give me. In this kind forum they guided me and I put together a routine that changes the size of the texts as I need it, but I would like to be able to make it only change the color of those that do not meet the height. here code Quote (vl-load-com) (defun l-coor2l-pt (lst flag / ) (if lst (cons (list (car lst) (cadr lst) (if flag (caddr lst) 0.0)) (l-coor2l-pt (if flag (cdddr lst) (cddr lst)) flag) ) ) ) (defun TextUp (/ sssetfirst) (vl-load-com) (cond ( (vlax-for x (setq sssetfirst (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ) ;_ setq (vla-put-height x (* 3.5 inv-vps)) ) ;_ vlax-for (vl-catch-all-apply 'vla-delete (list sssetfirst)) ) ) ;_ cond (princ) ) ;_ defun (defun c:texview ( / AcDoc Space js pt_v id_vp l h lst_pt js_obj UCS save_ucs WSC nw_pl ob_lst_pt vps inv-vps) (setvar "CMDECHO" 0) ;TAMAÑOS DE TEXTO (setvar "textsize" 3.5) (setq AcDoc (vla-get-ActiveDocument (vlax-get-acad-object)) Space (vla-get-PaperSpace AcDoc) ) (vla-StartUndoMark AcDoc) (if (eq (getvar "CTAB") "Model") (setvar "TILEMODE" 0)) (command "_.PSPACE") (princ "\nSelect a viewport: ") (while (null (setq js (ssget "_+.:E:S:L" (list '(0 . "VIEWPORT") '(67 . 1) (cons 410 (getvar "CTAB")) '(-4 . "!=") '(69 . 1) ) ) ) ) ) (setq pt_v (cdr (assoc 10 (setq dxf_ent (entget (setq ent (ssname js 0)))))) id_vp (cdr (assoc 69 dxf_ent)) l (cdr (assoc 40 dxf_ent)) h (cdr (assoc 41 dxf_ent)) lst_pt (list (list (- (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0) (list (+ (car pt_v) (* 0.5 l)) (- (cadr pt_v) (* 0.5 h)) 0.0) (list (+ (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0) (list (- (car pt_v) (* 0.5 l)) (+ (cadr pt_v) (* 0.5 h)) 0.0) ) js_obj (ssadd) ) (entmakex (vl-list* (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 67 1) (cons 100 "AcDbPolyline") (cons 90 (length lst_pt)) (cons 70 1) (mapcar '(lambda (p) (cons 10 p)) lst_pt) ) ) (ssadd (setq nw_pl (entlast)) js_obj) (setq vps (vla-get-CustomScale (vlax-ename->vla-object (ssname js 0)))) (setq inv-vps (/ 1 vps)) (command "_.MSPACE") (setvar "CVPORT" id_vp) (command "_.PSPACE") (command "_.CHSPACE" js_obj "" (if (> id_vp 2) "")) (command "_.MSPACE") (setq Space (if (eq (getvar "CVPORT") 1) (vla-get-PaperSpace AcDoc) (vla-get-ModelSpace AcDoc) ) UCS (vla-get-UserCoordinateSystems AcDoc) save_ucs (vla-add UCS (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point (getvar "UCSXDIR")) (vlax-3d-point (getvar "UCSYDIR")) "CURRENT_UCS" ) ) (vla-put-Origin save_ucs (vlax-3d-point (getvar "UCSORG"))) (setq WCS (vla-add UCS (vlax-3d-Point '(0.0 0.0 0.0)) (vlax-3d-Point '(1.0 0.0 0.0)) (vlax-3d-Point '(0.0 1.0 0.0)) "TEMP_WCS")) (vla-put-activeUCS AcDoc WCS) (setq nw_pl (vlax-ename->vla-object nw_pl) ob_lst_pt (l-coor2l-pt (vlax-get nw_pl 'coordinates) nil) ) (vla-put-layer nw_pl "0") (vla-delete nw_pl) (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) )) (and save_ucs (vla-put-activeUCS AcDoc save_ucs)) (and WCS (vla-delete WCS) (setq WCS nil)) (vla-EndUndoMark AcDoc) (TextUp) (setvar "CMDECHO" 1) (prin1) ) Quote
Steven P Posted 3 hours ago Posted 3 hours ago Very quickly.... code tag is <> , you used quote tag '' which makes reading your code harder You use sssetfirst as a variable - it is better practice to not use a command name also as a variable even if it works. for example: (setq sssetfirst (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ) ;; A variable (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) )) ;; A command The next suggestion I would make for now is to separate out your code a bit - all good running lines together but while you are creating something go to simple programming methods, it often makes errors or bad code jump out: (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) )) could be (setq MySS (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) ) ) (sssetfirst nil MySS) Next thing would be to add comments to the code especially if you are asking how things work, we can read through the code quickly and see the intent of how the code works Last thing, when asking for help - and we have no problem with that - give a clue what is not working as it should. I think that if you add comments to the code it should be clear what to change to make the colours also red. Perhaps one of you comments will be 'adjust text to size 3.5'... and that might be where you want to change the colour also. 1 Quote
leonucadomi Posted 2 hours ago Author Posted 2 hours ago 6 minutes ago, Steven P said: Very quickly.... code tag is <> , you used quote tag '' which makes reading your code harder You use sssetfirst as a variable - it is better practice to not use a command name also as a variable even if it works. for example: (setq sssetfirst (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))) ) ;; A variable (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) )) ;; A command The next suggestion I would make for now is to separate out your code a bit - all good running lines together but while you are creating something go to simple programming methods, it often makes errors or bad code jump out: (sssetfirst nil (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) )) could be (setq MySS (ssget "_WP" ob_lst_pt '((0 . "*TEXT,ATTDEF")(-4 . "<NOT") (62 . 4) (-4 . "NOT>")) ) ) (sssetfirst nil MySS) Next thing would be to add comments to the code especially if you are asking how things work, we can read through the code quickly and see the intent of how the code works Last thing, when asking for help - and we have no problem with that - give a clue what is not working as it should. I think that if you add comments to the code it should be clear what to change to make the colours also red. Perhaps one of you comments will be 'adjust text to size 3.5'... and that might be where you want to change the colour also. Master I'm trying the modified routine and this happens... (defun c:test (/ old_err EscVP StrScale2 TxtHt StrScale ss) (setq old_err *error*) (defun *error* ( a / ) ;; Add here return cmdecho to as it was, cmdecho 1 (princ "") (setq *error* old_err) (princ) ) ; End Error Defun (setvar "cmdecho" 0) ; perhaps record the state of cmdecho before here, and reset to that value at the end (if (and (setq EntVP (car (entsel "\Seleccione VIEWPORT: "))) (= (cdr (assoc 0 (entget EntVP))) "VIEWPORT") ) ; end and (progn (setq EscVP (vla-get-CustomScale (vlax-ename->vla-object EntVP))) (setq StrScale2 (rtos (* 3.5 (/ 1 EscVP)) 2 1)) (setq TxtHt (* 3.5 (/ 1 EscVP)) ) ; a number not a string ;; added this (setq StrScale (rtos (/ 1 EscVP) 2 2)) (setq vpnum (cdr (assoc 69 (entget EntVP )))) (vl-cmdf "_.mspace") (setvar "CVPORT" vpnum) (setq ss (ssget (list(0 . "TEXT") (-4 . "<>") (cons 40 TxtHt))) ) ;;What are you doing with ss now? (Prompt (strcat "\nLa escala de La Ventana es 1/" StrScale)) (princ "\nLos textos de 3.5 en el interior de la ventana deben ser de: ") (princ StrScale2) ) ; end progn ) ; end if (setvar "cmdecho" 1) (princ) );fin defun Quote
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.