Jump to content
ksperopoulos

Remove Character From MText

Recommended Posts

I am trying to remove a hyphen from mtext. The hyphen will not always be in the same location. This is an example of what I am trying to do:

 

12-1/4" to 12 1/4"

 

Could someone point me in the right direction of how to achieve this please? Thank you.

Share this post


Link to post
Share on other sites

  • Prompt user to select MText (entsel)
  • Retrieve the MText DXF data (entget)
  • Retrieve the MText content (DXF group 1: cdr / assoc)
  • Retrieve the position of the hyphen in the string if present (vl-string-search / vl-string-position)
  • Remove the hyphen from the string (substr)*
  • Update the DXF data with the new content (subst)
  • Modify the MText entity (entmod)

*There are several alternative methods to approach this step:

 

  • Substitute the hyphen for an empty string (vl-string-subst)

Or:

 

  • Convert the string to a list of ASCII characters (vl-string->list)
  • Remove the hyphen character (vl-remove)
  • Convert the list of ASCII characters back to a string (vl-list->string)

Share this post


Link to post
Share on other sites

Lee Mac - This seems to work. Thank you for the help!

 

(defun c:testsize ( / obj lay sz1 sz2)
(vl-load-com)
(setq obj (entget (car (entsel "\nSelect Object"))))
(setq lay (cdr (assoc 8 obj)))
(setq sz1 (cdr (nth 9 obj)))
(setq sz2 (vl-string-subst " " "-" sz1))
(command "clayer" (strcat lay "-SIZE"))
(command "mleader" pause pause (strcat sz2 "\""))
(princ)
)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×