Jump to content

Add Mtext to dim with formatting


Corro

Recommended Posts

Good Morning

I am trying to add addition text, as mtext, to a dimension.

The requirements are that the new mtext is below the dimension line and should be 1.3mm high and red in color. The original text is 1.8 high and white in color.

I have attached a sample of requirements, as a screen grab.

Thanks in advance.

Add Mtext 2 Dim.JPG

Link to comment
Share on other sites

There is some examples of editing mtext and set colours and height etc here. The way to approach would be do 3 line dim then click on dim via a lisp and it would change to the settings required. I am trying to remember the subject Iwill try to find I know lee-mac provided posts as well.

Link to comment
Share on other sites

I don't remember where I got this code but I use this all the time :


(defun c:txt2dim (/ edim text etxt vla_dim cmd1)
(prompt "\nText to Dimension")
(setq cmd1 (getvar 'cmdecho))
(setvar 'cmdecho 0)
(vl-load-com)
(while 
(or (initget 1)
 (not (setq edim (entsel "\nSelect dimension: ")))
 (/= (cdr (assoc 0 (entget (car edim)))) "DIMENSION")
)
(prompt "\n*** You must select a dimension. ***")
)
(while
(and 
 (not 
  (and (setq etxt (entsel "\nSelect text to add to override or enter to type: "))
   (= (cdr (assoc 0 (entget (car etxt)))) "TEXT")
  )
 )
 (or (initget 1)
  (not 
   (setq text (getstring t "\nType the text or ENTER to clear override: "))
  )
 )
)
)
(if etxt
(setq text (vla-get-textstring (vlax-ename->vla-object (car etxt))))
)
(setq vla_dim (vlax-ename->vla-object (car edim)))
(cond
((and text (/= text ""))
 (vla-put-textoverride vla_dim (strcat (chr 60)(chr 62) "[url="file://\\X"]\\X[/url]" text))
)
((and text (= text "")) ; clear the override
 (vla-put-textoverride vla_dim text)
)
)
(setvar 'cmdecho cmd1)
(princ)
)

Edited by nod684
wrong code
Link to comment
Share on other sites

Why don't you just add text to the dimension text, press ENTER for new line and format the text as any MTEXT objekt. You can do that in AutoCad 2016.

Link to comment
Share on other sites

Here is a very simple example:

(defun c:dimtest ( / e i s )
   (if (setq s (ssget "_:L" '((0 . "*DIMENSION") (1 . "~*?*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod (subst '(1 . "<>\\X{\\C1;This is a\\Ptest of text}") (assoc 1 e) e))
       )
   )
   (princ)
)

Link to comment
Share on other sites

Why don't you just add text to the dimension text, press ENTER for new line and format the text as any MTEXT objekt. You can do that in AutoCad 2016.

 

This would make all of the text to be above the line. I believe the functionality he wants is more along the lines of what Lee is doing by programatically adding the \X after in order to get to the next line.

Link to comment
Share on other sites

Here is a very simple example:
(defun c:dimtest ( / e i s )
   (if (setq s (ssget "_:L" '((0 . "*DIMENSION") (1 . "~*?*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod (subst '(1 . "<>\\X{\\C1;This is a\\Ptest of text}") (assoc 1 e) e))
       )
   )
   (princ)
)

 

Since were messing with it... Is there anyway for the dimtext to be left or right aligned? Not just having the textbox aligned, but the text inside the box aligned as well.

Edited by iconeo
CLARIFICATION
Link to comment
Share on other sites

Since were messing with it... Is there anyway for the dimtext to be left or right aligned? Not just having the textbox aligned, but the text inside the box aligned as well.

 

Not that I know of.

Link to comment
Share on other sites

Thanks guys

 

 

As per usual, you guys rule.

 

 

One question, can the added text be Mtext, as the added text will change for each insertion.

 

 

Thanks again

Link to comment
Share on other sites

Hi Guys

 

 

I have modified the supplied code trying to allow 3 lines a text.

 

 

I need help in getting it to work.

 

 

(defun c:dimtest ( / e i s )
 (setq txt1 (getstring "\nEnter Text line 1 to add to Dim: "))
 (setq txt2 (getstring "\nEnter Text line 2 to add to Dim: "))
 (setq txt3 (getstring "\nEnter Text line 3 to add to Dim: "))
   (if (setq s (ssget "_:L" '((0 . "*DIMENSION") (1 . "~*?*"))))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i)))))
           (entmod (subst '(1 . "<>\\X{\\C1;\\H1.3;[b]txt1[/b]}") (assoc 1 e) e))
       )
   )
   (princ)
)

Edited by SLW210
Added Code Tags!
Link to comment
Share on other sites

A better way to 1 line 2 3 4 or more lines would be to loop the txt2 getstring using a strcat to join the multiple input in the entmod. You could have a certain character also for a blank line.

 

txt1 85.67
txt2 this is a 
txt3 test of text
something like this not tested
(entmod (subst '((cons 1  (strcat "<>\\X{\\C1;" txt2 "[url="file://\\P"]\\P[/url]" "txt3" "}"))

Link to comment
Share on other sites

Hi Bigal

It will only insert the txt1, txt2 & txt3.

Are you able to explain the format to insert the value for each & not the txt number?

Thanks

Link to comment
Share on other sites

Try the following:

(defun c:dimtest ( / enx idx lne lst sel str )
   (setq lne 0)
   (while (/= "" (setq str (getstring t (strcat "\nSpecify text for line " (itoa (setq lne (1+ lne))) " <done>: "))))
       (setq lst (cons str lst))
   )
   (setq str (car lst))
   (foreach itm (cdr lst) (setq str (strcat itm "\\P" str)))
   (setq str (cons 1 (if str (strcat "<>\\X{\\C1;" str "}") "")))
   (if (setq sel (ssget "_:L" '((0 . "*DIMENSION") (1 . "~*?*"))))
       (repeat (setq idx (sslength sel))
           (setq enx (entget (ssname sel (setq idx (1- idx)))))
           (entmod (subst str (assoc 1 enx) enx))
       )
   )
   (princ)
)

  • Like 1
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...