Corro Posted April 27, 2016 Share Posted April 27, 2016 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
nod684 Posted April 28, 2016 Share Posted April 28, 2016 (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 April 28, 2016 by nod684 wrong code Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 28, 2016 Share Posted April 28, 2016 have a look at this also http://www.cadtutor.net/forum/showthread.php?92585-HELP-Change-only-the-colour-of-numbers-in-an-mtext&highlight=mtext Quote Link to comment Share on other sites More sharing options...
guran Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 28, 2016 Share Posted April 28, 2016 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) ) Quote Link to comment Share on other sites More sharing options...
iconeo Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
iconeo Posted April 28, 2016 Share Posted April 28, 2016 (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 April 28, 2016 by iconeo CLARIFICATION Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 28, 2016 Share Posted April 28, 2016 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. Quote Link to comment Share on other sites More sharing options...
Corro Posted April 28, 2016 Author Share Posted April 28, 2016 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 Quote Link to comment Share on other sites More sharing options...
Corro Posted April 28, 2016 Author Share Posted April 28, 2016 (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 April 29, 2016 by SLW210 Added Code Tags! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted April 29, 2016 Share Posted April 29, 2016 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" "}")) Quote Link to comment Share on other sites More sharing options...
Corro Posted April 29, 2016 Author Share Posted April 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 29, 2016 Share Posted April 29, 2016 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) ) 1 Quote Link to comment Share on other sites More sharing options...
Corro Posted May 1, 2016 Author Share Posted May 1, 2016 Hey Lee Works like a charm. Thanks again Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 2, 2016 Share Posted May 2, 2016 You're welcome. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.