Jump to content

Remove Character From MText


ksperopoulos

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.

Link to comment
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)

Link to comment
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)
)

Link to comment
Share on other sites

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...