TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Matt__W on September 23, 2009, 11:25:43 AM

Title: Automatically add Mtext text string into Mtext editor
Post 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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: T.Willey on September 23, 2009, 11:39:18 AM
Can you just create the text with the string you want, and then edit it with ' ddedit ', that way the text will be there?
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Matt__W on September 23, 2009, 11:42:17 AM
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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: T.Willey on September 23, 2009, 11:44:30 AM
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:
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 23, 2009, 12:50:48 PM
Just thought I'd throw something together, but now I am driving myself crazy trying to find the error in this...  :ugly:

Code: [Select]
(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))
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Matt__W on September 23, 2009, 01:21:58 PM
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:

Code: [Select]
(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))
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 23, 2009, 01:39:39 PM
I wrote this the other day for my CopyText routine. Should give you an idea.

Code: [Select]
;;; 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
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 23, 2009, 01:44:22 PM
Matt, if you just wanted to create the MTEXT, this would suffice:

Code: [Select]
(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:

Code: [Select]
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: 
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Matt__W on September 23, 2009, 01:48:44 PM
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)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 23, 2009, 01:58:41 PM
Why not use entmakex and assign it a variable.

Code: [Select]
(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:

Code: [Select]
(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:

Code: [Select]
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: 
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 23, 2009, 06:08:19 PM
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...
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 23, 2009, 06:26:43 PM
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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 23, 2009, 06:38:42 PM
Just tried it and put an error handler with vl-bt (not used that too much), but got this:

Code: [Select]
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)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 23, 2009, 07:12:08 PM
Did you try what I posted?
Code: [Select]
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:

Code: [Select]
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)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 06:25:51 AM
Yes, that was running what you posted  :wink:
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 09:37:09 AM
Yes, that was running what you posted  :wink:
Oh ok, were you reporting the error with the use of (entlast)?
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 09:50:23 AM
This is what I used, and this is what I got  :wink:

Code: [Select]
(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))

Code: [Select]
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)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 11:01:58 AM
Remove the error handler & run from VLIDE, where does it stop?
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 11:05:39 AM
I wonder why it crashes for you.  :?
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 11:08:04 AM
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.

Code: [Select]
(defun c:myentget( / ent)
(and (setq ent (car (entsel "\nSelect entity to list.")))
       (setq ent (entget ent)))
  (mapcar 'print ent)
  (princ)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 11:12:38 AM
Created by Routine:

Code: [Select]
(-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:

Code: [Select]
(-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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 11:13:55 AM
The weird thing is, if I use MTEdit on the newly created object, after the routine has crashed - I can edit it normally..  :|
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 11:20:24 AM
What does this do?
Code: [Select]
(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)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 11:30:00 AM
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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 12:38:30 PM
I get this CAB with that code:

Quote
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>
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 01:46:22 PM
How about this one Lee, then dump the object again after mtext will edit it.
Code: [Select]
(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)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 01:53:16 PM
Dump provided by code:

Code: [Select]
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:

Code: [Select]
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 ()
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: T.Willey on September 24, 2009, 02:14:07 PM
Works here in both '06 and '09.  Sorry.  Don't know what it could be Lee.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 02:16:21 PM
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?


Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 06:08:24 PM
This (http://discussion.autodesk.com/forums/thread.jspa;jsessionid=hZFYK7tWXjJsp4FsdvWTY828Gvr1THLf2RT8kzkpsj22ntv24ZyR!1777889114?messageID=6202915&#6202915) is the only other reference to that error that I could find, but even they don't know what it is...
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 06:10:12 PM
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.
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 07:01:43 PM
Test this:
Code: [Select]
(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)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 24, 2009, 07:05:17 PM
Thanks for your effort Alan, but I get:

Quote
Command:
Command: test

Specify First Corner:
Specify Second Corner: ; error: no function definition: MTEDIT
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 07:11:15 PM
(mtedit txt)
How'd you find this one?!?!?!!

Test this:
Code: [Select]
(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)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 07:15:32 PM
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:
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 07:16:58 PM
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:

Quote
Command:
Command: test

Specify First Corner:
Specify Second Corner: ; error: no function definition: MTEDIT
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 08:05:31 PM
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:
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 08:10:48 PM
Maybe this?
Code: [Select]
(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)
)
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 24, 2009, 09:12:43 PM
Alan, here is a helper.
Code: [Select]
    (defun GetAtoms (pattern)
        (setq pattern (strcase pattern))
        (vl-remove-if-not
            '(lambda (name) (wcmatch  name pattern))
            (atoms-family 1)
        )
    )

_$ (getAtoms "mt*")
("MTPROP" "MTEDIT")
_$
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: alanjt on September 24, 2009, 09:20:25 PM
LoL
I was actually looking at it with almost the same method. Thanks Alan. :-)

Alan, here is a helper.
Code: [Select]
    (defun GetAtoms (pattern)
        (setq pattern (strcase pattern))
        (vl-remove-if-not
            '(lambda (name) (wcmatch  name pattern))
            (atoms-family 1)
        )
    )

_$ (getAtoms "mt*")
("MTPROP" "MTEDIT")
_$
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: Lee Mac on September 25, 2009, 06:28:59 AM
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:

Quote
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?
Title: Re: Automatically add Mtext text string into Mtext editor
Post by: CAB on September 25, 2009, 08:30:26 AM
For what ever reason your Mtext command is different from ours    :ugly: