Jump to content

Vlax-get-property not playing nice within a logic function


Recommended Posts

Posted

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

 

Posted

@KGehrels First off you're missing some parenthesis:

image.thumb.png.4179b29fef72e19abd141e90799eb5b5.png

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

 

Posted

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?

Posted

Ooops ... try (not (wcmatch (vlax-get-property obj "TextString") "{\\L*}"))

Posted

Same result of no error but lack of action.

Posted

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.

Posted

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

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...