KGehrels Posted February 29, 2024 Posted February 29, 2024 I'm new to working in LISP and have jumped into the deep end with lead boots on and am trying to clean up about 100 dwg files that have been exported from SolidWorks. The current part that I'm having trouble with is assigning textstyles based on a few different properties (mostly height, line spacing and underline or bold or the absence of). For whatever reason the AND statement that filters the selection of mtext is, I'm assuming, returning nil. This is because I get no error but the text doesn't change style after running the function. If I remove the IF statement, or change it to be something like (= text_height text_height) then the text styles change without issue. Any help would be appreciated. Thanks (defun c:t2 (/ acadObj doc text_style text_height selset idx obj) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-activedocument acadObj)) (setq text_style "Balloon") (setq text_height 0.1875) (if (setq selset (ssget "_X" '((0 . "MText")))); Select All (progn (setq idx (sslength selset)) (while (> idx 0) (setq obj (vlax-ename->vla-object (ssname selset (setq idx (1- idx))))); decreases the object count by 1 each time the while loop happens (if (and (= (vlax-get-property obj "Height") text_height); Check text height against above value (= vlax-get-property obj "LineSpacingDistance" line_spacing); Check line spacing against above value (/= vlax-get-property obj "TextString" "{\\L*}"); Confirm that Mtext is not underlined ); end and (vlax-put-property obj "StyleName" text_style); Change the text style to match what is stated above ); end if ); end while ); end progn ); end if (princ) );end Setprop Quote
ronjonp Posted March 1, 2024 Posted March 1, 2024 @KGehrels First off you're missing some parenthesis: And you need to use WCMATCH to check the textstring. (and (= (vlax-get-property obj "Height") text_height); Check text height against above value (= (vlax-get-property obj "LineSpacingDistance") line_spacing); Check line spacing against above value (wcmatch (vlax-get-property obj "TextString") "{\\L*}"); Confirm that Mtext is not underlined ); end and Quote
KGehrels Posted March 1, 2024 Author Posted March 1, 2024 Thank you for the corrections. However, the behaviour hasn't changed. The lisp will run and nothing will happen. Could this have anything to do with the if statement kicking back a nil response if the mtext doesn't match? Quote
ronjonp Posted March 1, 2024 Posted March 1, 2024 Ooops ... try (not (wcmatch (vlax-get-property obj "TextString") "{\\L*}")) Quote
KGehrels Posted March 1, 2024 Author Posted March 1, 2024 Same result of no error but lack of action. Quote
Lee Mac Posted March 1, 2024 Posted March 1, 2024 A few points: 1. (= (vlax-get-property obj "Height") text_height) Always use the equal function with an appropriate tolerance when comparing doubles, as two arbitrary double values will rarely be exactly equal to every bit: (equal text_height (vla-get-height obj) 1e-8) 2. (= vlax-get-property obj "LineSpacingDistance" line_spacing) (/= vlax-get-property obj "TextString" "{\\L*}") Missing parentheses: (= (vlax-get-property obj "LineSpacingDistance") line_spacing) (/= (vlax-get-property obj "TextString") "{\\L*}") 3. (= vlax-get-property obj "LineSpacingDistance" line_spacing) The variable line_spacing is not defined; also, as above, use equal. 4. (/= vlax-get-property obj "TextString" "{\\L*}") Assuming the parentheses are fixed, unless you want to filter out objects whose content is exactly equal to "{\L*}" then you'll want to use wcmatch in place of an equality test. Quote
KGehrels Posted March 2, 2024 Author Posted March 2, 2024 Thankyou both Lee and ronjonp. Parenthesis and line_spacing mistakes aside is it most likely that the main issue was a combination of not using wcmatch and not using a tolerance when comparing the height and linespacing? Here's the code that is working: (defun c:t3 (/ acadObj doc text_style text_height selset idx obj); (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-activedocument acadObj)) (setq text_style "Balloon") (setq text_height 0.1875) (setq line_spacing 0.3125) (if (setq selset (ssget "_X" '((0 . "MText")))); Select All (progn (setq idx (sslength selset)) (while (> idx 0) (setq obj (vlax-ename->vla-object (ssname selset (setq idx (1- idx))))); decreases the object count by 1 each time the while loop happens (if (and (equal text_height (vlax-get-property obj "Height") 1e-8); Check text height against above value (equal line_spacing (vlax-get-property obj "LineSpacingDistance") 1e-8); Check line spacing against above value (not (wcmatch (vlax-get-property obj "TextString") "{\\L*}")); Confirm that Mtext is not underlined ); end and (vlax-put-property obj "StyleName" text_style); Change the text style to match what is stated above ); end if ); end while ); end progn ); end if (princ) );end Setprop 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.