Author Topic: Automatically add Mtext text string into Mtext editor  (Read 12509 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Automatically add Mtext text string into Mtext editor
« 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.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Automatically add Mtext text string into Mtext editor
« Reply #1 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?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Automatically add Mtext text string into Mtext editor
« Reply #2 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.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Automatically add Mtext text string into Mtext editor
« Reply #3 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:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Automatically add Mtext text string into Mtext editor
« Reply #4 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))

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Automatically add Mtext text string into Mtext editor
« Reply #5 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))
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Automatically add Mtext text string into Mtext editor
« Reply #6 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
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Automatically add Mtext text string into Mtext editor
« Reply #7 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: 

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Automatically add Mtext text string into Mtext editor
« Reply #8 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)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Automatically add Mtext text string into Mtext editor
« Reply #9 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: 
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Automatically add Mtext text string into Mtext editor
« Reply #10 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...

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Automatically add Mtext text string into Mtext editor
« Reply #11 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.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Automatically add Mtext text string into Mtext editor
« Reply #12 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)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Automatically add Mtext text string into Mtext editor
« Reply #13 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)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Automatically add Mtext text string into Mtext editor
« Reply #14 on: September 24, 2009, 06:25:51 AM »
Yes, that was running what you posted  :wink: