TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Matt__W on September 23, 2009, 11:25:43 AM
-
Does anyone have a quick and easy way to automatically add a predefined text string to mtext? I've got a routine in which we're placing schematic symbols (AutoCAD MEP) and after a certain symbol is placed, a note needs to be added so it isn't "accidentally" left off the drawings. What I'm envisioning is the user picking the two corners for the mtext then having the note automatically inserted into the mtext editor and then closed. I've got the first part (picking the corners), but I'm not sure how I'd go about automatically adding the text.
-
Can you just create the text with the string you want, and then edit it with ' ddedit ', that way the text will be there?
-
Can you just create the text with the string you want, and then edit it with ' ddedit ', that way the text will be there?
I want it to be mtext so we can adjust the width if need be.
-
Can you just create the text with the string you want, and then edit it with ' ddedit ', that way the text will be there?
I want it to be mtext so we can adjust the width if need be.
I know. Same process though. Just didn't feel like putting the ' m ' in front of it all the time. :wink:
-
Just thought I'd throw something together, but now I am driving myself crazy trying to find the error in this... :ugly:
(defun c:test (/ str p1 p2)
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(entmake
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)))
(not (initdia))
(command "_.ddedit" (entlast) pause))
(princ))
-
If I comment out this line (see below) it does exactly what I was looking for. Now all I need to do is tweak it for the correct text size/style and I'll be set.
Thanks, Lee Mac!
P.S. I don't get ANY kind of error when I run this. :|
Just thought I'd throw something together, but now I am driving myself crazy trying to find the error in this... :ugly:
(defun c:test (/ str p1 p2)
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(entmake
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)))
(not (initdia))
[color=green]; (command "_.ddedit" (entlast) pause)[/color])
(princ))
-
I wrote this the other day for my CopyText routine. Should give you an idea.
;;; Edit text box (Old Mtext editor)
;;; Returns typed in textstring
;;; Alan J. Thompson, 09.18.09
(defun AT:EditTextBox (/ *error* #Cmdecho #Mtexted #Mtext #String)
(setq *error* (lambda (msg)
(and #Mtext (entdel #Mtext))
(and #Cmdecho (setvar "cmdecho" #Cmdecho))
(and #Mtexted (setvar "mtexted" #Mtexted))
) ;_ lambda
#Cmdecho (getvar "cmdecho")
#Mtexted (getvar "mtexted")
) ;_ setq
(setvar "cmdecho" 0)
(vl-catch-all-apply 'setvar (list "mtexted" "OldEditor"))
(setq #Mtext (entmakex (list
'(0 . "MTEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbMText")
(cons 10 (trans (cadr (grread t 4 4)) 1 0))
) ;_ list
) ;_ entmakex
) ;_ setq
(vl-cmdf "_.mtedit" #Mtext)
(setq #String (vla-get-textstring (vlax-ename->vla-object #Mtext)))
(*error* nil)
(if (/= #String "")
#String
) ;_ if
) ;_ defun
-
Matt, if you just wanted to create the MTEXT, this would suffice:
(defun c:test (/ str p1 p2)
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(entmake
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str))))
(princ))
But everytime I try to get the Text Editor up, using either ddedit, or mtedit, I get this error:
Specify First Corner:
Specify Second Corner: _.ddedit
Select an annotation object or [Undo]: Application ERROR: irfcld
Select an annotation object or [Undo]:
Command: ; error: invalid AutoCAD command: <Entity name: 7ec1f6d8>
Can't for the life of me work out why :ugly:
-
Matt, if you just wanted to create the MTEXT, this would suffice:
That's it and that's all. Thanks again!
Now if I could only remember how to code CONDs. (man, it's been a while since I've done this stuff)
-
Why not use entmakex and assign it a variable.
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str))))
(command "_.mtedit" txt))
(princ))
Matt, if you just wanted to create the MTEXT, this would suffice:
(defun c:test (/ str p1 p2)
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(entmake
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str))))
(princ))
But everytime I try to get the Text Editor up, using either ddedit, or mtedit, I get this error:
Specify First Corner:
Specify Second Corner: _.ddedit
Select an annotation object or [Undo]: Application ERROR: irfcld
Select an annotation object or [Undo]:
Command: ; error: invalid AutoCAD command: <Entity name: 7ec1f6d8>
Can't for the life of me work out why :ugly:
-
I think I tried that and got the same thing :| so I switched to entlast, to see if it made a difference...
But the weird thing is, I have never in all my experience in errors (there have been a few) come across that error before...
-
I think I tried that and got the same thing :| so I switched to entlast, to see if it made a difference...
But the weird thing is, I have never in all my experience in errors (there have been a few) come across that error before...
Worked fine for me.
-
Just tried it and put an error handler with vl-bt (not used that too much), but got this:
Command: Backtrace:
[0.54] (VL-BT)
[1.50] (*ERROR* "invalid AutoCAD command: <Entity name: 7ef036a8>") LAP+7
[2.44] (_call-err-hook #<USUBR @12b0a280 *ERROR*> "invalid AutoCAD command:
<Entity name: 7ef036a8>")
[3.38] (sys-error "invalid AutoCAD command: <Entity name: 7ef036a8>")
:ERROR-BREAK.33 "invalid AutoCAD command: <Entity name: 7ef036a8>"
[4.30] (sys-acmd-err-hook <Entity name: 7ef036a8>)
[5.25] (ads-cmd <Entity name: 7ef036a8>)
[6.20] (C:TEST) LAP+278
[7.15] (#<SUBR @12b0a2bc -rts_top->)
[8.12] (#<SUBR @0fe3a35c veval-str-body> "(C:TEST)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
-
Did you try what I posted?
Command: (defun *error* (msg) (vl-bt))
*ERROR*
Command: test
Specify First Corner:
Specify Second Corner: _.mtedit Select an MTEXT object:
Just tried it and put an error handler with vl-bt (not used that too much), but got this:
Command: Backtrace:
[0.54] (VL-BT)
[1.50] (*ERROR* "invalid AutoCAD command: <Entity name: 7ef036a8>") LAP+7
[2.44] (_call-err-hook #<USUBR @12b0a280 *ERROR*> "invalid AutoCAD command:
<Entity name: 7ef036a8>")
[3.38] (sys-error "invalid AutoCAD command: <Entity name: 7ef036a8>")
:ERROR-BREAK.33 "invalid AutoCAD command: <Entity name: 7ef036a8>"
[4.30] (sys-acmd-err-hook <Entity name: 7ef036a8>)
[5.25] (ads-cmd <Entity name: 7ef036a8>)
[6.20] (C:TEST) LAP+278
[7.15] (#<SUBR @12b0a2bc -rts_top->)
[8.12] (#<SUBR @0fe3a35c veval-str-body> "(C:TEST)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
-
Yes, that was running what you posted :wink:
-
Yes, that was running what you posted :wink:
Oh ok, were you reporting the error with the use of (entlast)?
-
This is what I used, and this is what I got :wink:
(defun c:test (/ *error* str p1 p2 txt)
(defun *error* (e)
(vl-bt))
(setq str "Matt W")
(and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str))))
(command "_.mtedit" txt))
(princ))
Command: test
Specify First Corner:
Specify Second Corner: _.mtedit Select an MTEXT object: Application ERROR:
irfcld
Command:
Command: Backtrace:
[0.54] (VL-BT)
[1.50] (*ERROR* "invalid AutoCAD command: <Entity name: 7ef038a0>") LAP+7
[2.44] (_call-err-hook #<USUBR @12bdacbc *ERROR*> "invalid AutoCAD command:
<Entity name: 7ef038a0>")
[3.38] (sys-error "invalid AutoCAD command: <Entity name: 7ef038a0>")
:ERROR-BREAK.33 "invalid AutoCAD command: <Entity name: 7ef038a0>"
[4.30] (sys-acmd-err-hook <Entity name: 7ef038a0>)
[5.25] (ads-cmd <Entity name: 7ef038a0>)
[6.20] (C:TEST) LAP+278
[7.15] (#<SUBR @12bdacf8 -rts_top->)
[8.12] (#<SUBR @0f06a35c veval-str-body> "(C:TEST)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)
-
Remove the error handler & run from VLIDE, where does it stop?
-
I wonder why it crashes for you. :?
-
Reading back post I see it's the editor causing or reportint the error.
My suspicion is that the mText entity is missing some dxf code that the editor is looking for.
Just a guess.
Do a dump on the new object & one with an existing mtext object to compare.
(defun c:myentget( / ent)
(and (setq ent (car (entsel "\nSelect entity to list.")))
(setq ent (entget ent)))
(mapcar 'print ent)
(princ)
)
-
Created by Routine:
(-1 . <Entity name: 7eb4c5b8>)
(0 . "MTEXT")
(330 . <Entity name: 7ef01cf8>)
(5 . "3FC97")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbMText")
(10 31.6891 0.897154 0.0)
(40 . 2.5)
(41 . 22.1367)
(46 . 0.0)
(71 . 1)
(72 . 5)
(1 . "Matt W")
(7 . "Verdana")
(210 0.0 0.0 1.0)
(11 1.0 0.0 0.0)
(42 . 11.7915)
(43 . 2.55205)
(50 . 0.0)
(73 . 1)
(44 . 1.0)
Created by Me:
(-1 . <Entity name: 7eb4c5c0>)
(0 . "MTEXT")
(330 . <Entity name: 7ef01cf8>)
(5 . "3FC98")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbMText")
(10 -5.32893 0.897154 0.0)
(40 . 2.5)
(41 . 22.1367)
(46 . 0.0)
(71 . 1)
(72 . 5)
(1 . "Matt W")
(7 . "Verdana")
(210 0.0 0.0 1.0)
(11 1.0 0.0 0.0)
(42 . 11.7915)
(43 . 2.55205)
(50 . 0.0)
(73 . 1)
(44 . 1.0)
I used a copied rectangle to get the same MText Width.
-
The weird thing is, if I use MTEdit on the newly created object, after the routine has crashed - I can edit it normally.. :|
-
What does this do?
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(if (and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)
)
)
)
)
(progn
(vla-update (vlax-ename->vla-object txt))
(command "_.mtedit" txt)
)
)
(princ)
)
-
The weird thing is, if I use MTEdit on the newly created object, after the routine has crashed - I can edit it normally.. :|
Odd.
It can't be because you are in 2010.
-
I get this CAB with that code:
Command:
Command: test
Specify First Corner:
Specify Second Corner: _.mtedit Select an MTEXT object: Application ERROR:
irfcld
Command:
Command: ; error: invalid AutoCAD command: <Entity name: 7ef03698>
-
How about this one Lee, then dump the object again after mtext will edit it.
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(if (and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)
)
)
)
)
(progn
(vlax-dump-object (vlax-ename->vla-object txt) t)
(command "_.mtedit" txt)
)
)
(princ)
)
-
Dump provided by code:
Command: test
Specify First Corner:
Specify Second Corner: ; IAcadMText: AutoCAD MText Interface
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 009791b4>
; AttachmentPoint = 1
; BackgroundFill = 0
; Document (RO) = #<VLA-OBJECT IAcadDocument 0efa6ab0>
; DrawingDirection = 5
; Handle (RO) = "23FC0"
; HasExtensionDictionary (RO) = 0
; Height = 2.5
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0f2eef9c>
; InsertionPoint = (1.87874 1.41485 0.0)
; Layer = "0"
; LineSpacingDistance = 4.16667
; LineSpacingFactor = 1.0
; LineSpacingStyle = 1
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 2128006592
; ObjectName (RO) = "AcDbMText"
; OwnerID (RO) = 2129665272
; PlotStyleName = "ByLayer"
; Rotation = 0.0
; StyleName = "Verdana"
; TextString = "Matt W"
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13da70>
; Visible = -1
; Width = 1.55443
; Methods supported:
; ArrayPolar (3)
; ArrayRectangular (6)
; Copy ()
; Delete ()
; FieldCode ()
; GetBoundingBox (2)
; GetExtensionDictionary ()
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetXData (_.mtedit Select an MTEXT object: Application ERROR: irfcld
Command:
Command: 2)
; TransformBy (1)
; Update ()
; error: invalid AutoCAD command: <Entity name: 7ed6cdc0>
Dump After running code:
Command: dump
Select entity to get object data:
; IAcadMText: AutoCAD MText Interface
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 009791b4>
; AttachmentPoint = 1
; BackgroundFill = 0
; Document (RO) = #<VLA-OBJECT IAcadDocument 0efa6ab0>
; DrawingDirection = 5
; Handle (RO) = "23FC0"
; HasExtensionDictionary (RO) = 0
; Height = 2.5
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 19d6abcc>
; InsertionPoint = (1.87874 1.41485 0.0)
; Layer = "0"
; LineSpacingDistance = 4.16667
; LineSpacingFactor = 1.0
; LineSpacingStyle = 1
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 2128006592
; ObjectName (RO) = "AcDbMText"
; OwnerID (RO) = 2129665272
; PlotStyleName = "ByLayer"
; Rotation = 0.0
; StyleName = "Verdana"
; TextString = "Matt W"
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13db60>
; Visible = -1
; Width = 1.55443
; Methods supported:
; ArrayPolar (3)
; ArrayRectangular (6)
; Copy ()
; Delete ()
; FieldCode ()
; GetBoundingBox (2)
; GetExtensionDictionary ()
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetXData (2)
; TransformBy (1)
; Update ()
-
Works here in both '06 and '09. Sorry. Don't know what it could be Lee.
-
What's up with this?
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13da70> ; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13db60>
The color is different! Is the first an invalid color?
-
This (http://discussion.autodesk.com/forums/thread.jspa;jsessionid=hZFYK7tWXjJsp4FsdvWTY828Gvr1THLf2RT8kzkpsj22ntv24ZyR!1777889114?messageID=6202915�) is the only other reference to that error that I could find, but even they don't know what it is...
-
What's up with this?
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13da70> ; TrueColor = #<VLA-OBJECT IAcadAcCmColor 1c13db60>
The color is different! Is the first an invalid color?
The TrueColor object number is always a different hex I think.
-
Test this:
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(if (and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)
)
)
)
)
(mtedit txt)
)
(princ)
)
-
Thanks for your effort Alan, but I get:
Command:
Command: test
Specify First Corner:
Specify Second Corner: ; error: no function definition: MTEDIT
-
(mtedit txt)
How'd you find this one?!?!?!!
Test this:
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(if (and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)
)
)
)
)
(mtedit txt)
)
(princ)
)
-
That's a secrete. 8-)
Typing the command in VLIDE you will see valid lisp calls when they turn blue.
You have to figure out what the arguments are though. :evil:
-
I would say it's an arx that isn't loaded, but once you mtedit something, it would work.
Thanks for your effort Alan, but I get:
Command:
Command: test
Specify First Corner:
Specify Second Corner: ; error: no function definition: MTEDIT
-
That's a secrete. 8-)
Typing the command in VLIDE you will see valid lisp calls when they turn blue.
You have to figure out what the arguments are though. :evil:
Well that's not fare. :cry: :cry:
-
Maybe this?
(defun c:test (/ str p1 p2 txt)
(setq str "Matt W")
(if (and (setq p1 (getpoint "\nSpecify First Corner: "))
(setq p2 (getcorner p1 "\nSpecify Second Corner: "))
(setq txt (entmakex
(list
(cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 100 "AcDbMText")
(cons 10 p1)
(cons 40 (getvar "TEXTSIZE"))
(cons 41 (abs (- (car p2) (car p1))))
(cons 7 (getvar "TEXTSTYLE"))
(cons 1 str)
)
)
)
)
(progn
(command ".mtedit") (command)
(command ".mtedit" txt)
)
)
(princ)
)
-
Alan, here is a helper.
(defun GetAtoms (pattern)
(setq pattern (strcase pattern))
(vl-remove-if-not
'(lambda (name) (wcmatch name pattern))
(atoms-family 1)
)
)
_$ (getAtoms "mt*")
("MTPROP" "MTEDIT")
_$
-
LoL
I was actually looking at it with almost the same method. Thanks Alan. :-)
Alan, here is a helper.
(defun GetAtoms (pattern)
(setq pattern (strcase pattern))
(vl-remove-if-not
'(lambda (name) (wcmatch name pattern))
(atoms-family 1)
)
)
_$ (getAtoms "mt*")
("MTPROP" "MTEDIT")
_$
-
Alan, the "mtedit" does not appear blue in my VLIDE... :| I tried (vl-arx-import 'mtedit) and still nothing :|
I tried your most recent code and received this:
Command: test
Specify First Corner:
Specify Second Corner: .mtedit Select an MTEXT object:
Command: .mtedit Select an MTEXT object: Application ERROR: irfcld
Command:
Command: ; error: invalid AutoCAD command: <Entity name: 7ef03698>
Could it be that I am using a Student Version?
-
For what ever reason your Mtext command is different from ours :ugly: