Jump to content

Recommended Posts

Posted

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

Posted

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.

Posted (edited)

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
Posted

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.

Posted

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

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

Posted (edited)
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
Posted
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.

Posted

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

Posted (edited)

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!
Posted

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" "}"))

Posted

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

Posted

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
Posted

Hey Lee

Works like a charm.

Thanks again

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