Insert MTEXT on line

Insert MTEXT on line

jermjmm
Enthusiast Enthusiast
1,115 Views
3 Replies
Message 1 of 4

Insert MTEXT on line

jermjmm
Enthusiast
Enthusiast

Good morning,

 

I have an old  lisp that inserts text on a line at the rotation of the line but I can't figure out how to do the same thing with MTEXT.  What I am wanting is it to insert the MTEXT on the line at the rotation of the line but also have the background mask of the MTEXT turned on.  The new text also doesn't need to break the line but that isn't my biggest problem.

As a place to start I tried to change the line: (command "TEXT" "M" "NEA" P1 A2 TX)

to this: (COMMAND "_MTEXT" P1 "J" "MC" "R" A2 "W" 0 TX)

just to get the mtext part in there but I keep getting an error of "bad argument type: 2d/3d point: nilmtext:"  if i just hit enter it inserts the mtext but I can't figure out what I'm doing wrong to get that error or how to add the background mask into it.

 

Thanks everyone!

 

Here is the orginal lisp:

"

;;; INSERTS TEXT ON LINE

(defun C:Ty (/ A1 A2 A3 E1 E2 E3 ENTNA LASTX OS1 P1 P4 P5 P6 P7 P8 P9 TX TX1)
(command "-color" "231")
(SETQ OLDL (GETVAR "CLAYER"))
(setq OS1 (getvar "osmode"))
(setvar "osmode" 512)
(if (or (nULL txold) (= txold ""))
(setq txold "1")
)
(setq TX (getstring (strcat "\nEnter text <" txold ">: ")))
(if (or (nULL tx) (= tx ""))
(setq tx TXOLD)
)
(setq txold tx)
(while (setq E1 (entsel "\nSelect Line: "))
(setq E2 (entget (car E1)))
(setq lay (cdr (assoc 8 E2)))
(command "-layer" "s" lay "")
(setq E3 (cdr (assoc 0 E2)))
(setq P1 (cadr E1))

(if (= E3 "POLYLINE")
(setq P2 (cadr E1)
P3 (getpoint "\nPick point for rotation: "))

(if (= E3 "CIRCLE")
(setq P2 (cadr E1)
P3 (cdr (assoc 10 E2)))

(if (= E3 "ARC")
(setq P2 (cadr E1)
P3 (cdr (assoc 10 E2)))

(setq P2 (cdr (assoc 10 E2))
P3 (cdr (assoc 11 E2)))
)
)
)

(if (= E3 "CIRCLE")
(setq A1 (+ (angle P2 P3) (/ pi 2)))

(if (= E3 "ARC")
(setq A1 (+ (angle P2 P3) (/ pi 2)))

(setq A1 (angle P2 P3))
)
)
(if
(and
(> A1 (/ pi 2))
(<= A1 (* pi 1.5))
)
(setq A1 (+ A1 pi))
)
(setq A2 (angtos A1 0 4))

(command "TEXT" "M" "NEA" P1 A2 TX)


(setq LASTX (entget (entlast)))
(setq TX1 (textbox LASTX))
(setq P4 (car TX1))
(setq P5 (cdr TX1))
(setq P5 (car P5))
(setq P6 (distance P4 P5))
(setq P7 (+ (/ P6 2) (* 0.04 (/ 1 (getvar 'cannoscalevalue)))))

(setq A3 (- A1 pi))
(setq p8 (polar P1 A1 P7))
(setq p9 (polar P1 A3 P7))
(command "ERASE" "L" "")
(command "BREAK" P1 "F" P8 P1)
(command "BREAK" P1 P9)
(command "OOPS")
)
(SETVAR "CLAYER" OLDL)
(setvar "osmode" OS1)
(command "-color" "BYLAYER")
(princ)
)"

0 Likes
Accepted solutions (1)
1,116 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant
Accepted solution
(COMMAND "_MTEXT" "_non" p1 "J" "MC" "R" a2 "W" 0 "hallo" "")
(setpropertyvalue (entlast) "BackgroundFill" 1)
(setpropertyvalue (entlast) "UseBackgroundColor" 1)

You need to set a background afterward.

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

If the reason for switching to Mtext is to get its masking capability, the same can be done with a Wipeout associated with ordinary Text, such as is done in LabelTextMask.lsp with its LTM command, available >here<.  It has several advantages over what you're using:  it works with many more entity types as "path" objects;  it uses a universal method of determing the angle they're running at where you pick, so it doesn't need to ask the User for any additional input [such as yours does with a Polyline];  you can pick as many things to label as you like, in one running of the command;  you can set the Style and/or Height and/or Width Factor of the Text inside the command, rather than needing to set such things ahead of time [and if you type a non-existent Style name, it asks again];  you can have the label on the Layer of each picked path object, or on the current Layer;  you can change any of the settings, including the Text content, within one running of the command;  it remembers all your choices and offers them as default values on subsequent use.

 

[Note that someone there asked in a comment for an Mtext version, which I haven't worked up yet, and if I do, I won't be able to post it there -- they're no longer taking user submissions or further comments.  If you sometimes still want one that actually breaks  a piece out of the path object(s), there's a link to LabelTextTrim.lsp with its LTT command at that LabelTextMask page.]

Kent Cooper, AIA
Message 4 of 4

jermjmm
Enthusiast
Enthusiast

Thanks BeekeeCZ got it!   With some some minor other revisions here is the final lisp:

 

;;; INSERTS TEXT ON LINE

(defun C:Ty (/ A1 A2 A3 E1 E2 E3 ENTNA LASTX OS1 P1 P4 P5 P6 P7 P8 P9 TX TX1)
(setq OS1 (getvar "osmode"))
(setvar "osmode" 512)
(if (or (nULL txold) (= txold ""))
(setq txold "1")
)
(setq TX (getstring (strcat "\nEnter text <" txold ">: ")))
(if (or (nULL tx) (= tx ""))
(setq tx TXOLD)
)
(setq txold tx)
(while (setq E1 (entsel "\nSelect Line: "))
(setq E2 (entget (car E1)))
(setq lay (cdr (assoc 8 E2)))
(command "-layer" "s" "G-Anno-Std-Note" "")
(setq E3 (cdr (assoc 0 E2)))
(setq P1 (cadr E1))

(if (= E3 "POLYLINE")
(setq P2 (cadr E1)
P3 (getpoint "\nPick point for rotation: "))

(if (= E3 "CIRCLE")
(setq P2 (cadr E1)
P3 (cdr (assoc 10 E2)))

(if (= E3 "ARC")
(setq P2 (cadr E1)
P3 (cdr (assoc 10 E2)))

(setq P2 (cdr (assoc 10 E2))
P3 (cdr (assoc 11 E2)))
)
)
)

(if (= E3 "CIRCLE")
(setq A1 (+ (angle P2 P3) (/ pi 2)))

(if (= E3 "ARC")
(setq A1 (+ (angle P2 P3) (/ pi 2)))

(setq A1 (angle P2 P3))
)
)
(if
(and
(> A1 (/ pi 2))
(<= A1 (* pi 1.5))
)
(setq A1 (+ A1 pi))
)
(setq A2 (angtos A1 0 4))

(COMMAND "_MTEXT" p1 "J" "MC" "R" a2 "W" 0 TX "")

(setpropertyvalue (entlast) "BackgroundFill" 1)
(setpropertyvalue (entlast) "UseBackgroundColor" 1)


)

(SETVAR "CLAYER" OLDL)
(setvar "osmode" OS1)
(princ)
)

0 Likes