Author Topic: Change MText to a desired layer  (Read 2671 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Change MText to a desired layer
« on: December 12, 2007, 06:01:10 PM »
Hi guys,
I am a bit stumped.  I'm thinking this should be easy, but perhaps I am wrong (as usual).

So, I want MText to run just as it is.  Let the user decide how they want MText justification or what have you, but I want the text to go to a desired layer when the command is executed.
So if the user is on the PLAN layer and they type in "MTEXT", the current layer will go to the NOTES layer and the user will type in what they want and click OK.  Then the current layer will go back to the PLAN layer.
Or, the user is on the PLAN layer and they type in "MTEXT" and type away.  When they finish and click OK, the text is then taken and placed on the NOTES layer.

I've looked at Darryl's post, MText in Lisp (http://www.theswamp.org/index.php?topic=1925.0) and tried unsuccessfully to make it work.  I can't have the (setq txt (getstring "\n Put text here: ")) involved,
the user has to put the text in as it is typed in at the dialog box on the screen.

I've also looked at CAB's Entmake MText post (http://www.theswamp.org/index.php?topic=949.0).
Is this the only way to do this ??

Thank you for your help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Change MText to a desired layer
« Reply #1 on: December 12, 2007, 06:15:27 PM »
You need to use reactors...lemme see if I can find a thread.

Here ya go:
http://www.theswamp.org/index.php?topic=19949.msg242928#msg242928
« Last Edit: December 12, 2007, 06:21:25 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Change MText to a desired layer
« Reply #2 on: December 13, 2007, 10:53:49 AM »
Hi,..

there is an example...

Guru, feel free to put some comment..
Code: [Select]
;;capture variables
(setq Clayer (getvar 'clayer))
(setq Cecolor (getvar 'cecolor))

;;capture info
(setq Nlayer (getstring "Text Layer :"))
(setq Ncolor (getstring "Text Color :"))
(vl-load-com)


;;create layer if not
(if (not (tblsearch "LAYER" Nlayer))
  (progn
    (setq VLAlayers (vla-get-Layers
      (vla-get-ActiveDocument (vlax-get-Acad-Object))
    )
    )
    (vla-Add VLAlayers Nlayer)
    (setq Slayer (vla-item VLAlayers Nlayer))
;(vla-put-lock Slayer :vlax-false)
    (vla-put-color Slayer Ncolor)
;(vla-put-linetype Slayer LTYPE)
;(vla-put-plottable Slayer PLOTL)
  )
)



;;reset variables and reactors
(defun ResetVAR (/ *startTextCommand*
*endTextCommand* *cancelTextCommand*
*failedTextCommand*
)
  (if *startTextCommand*
    (vlr-remove *startTCommand*)
  )

  ;;On command Ended
  (if *endTextCommand*
    (vlr-remove *endTextCommand*)
  )

  ;;On command Cancelled
  (if *cancelTextCommand*
    (vlr-remove *cancelTextCommand*)
  )

  ;;On command Cancelled
  (if *failedTextCommand*
    (vlr-remove *failedTextCommand*)
  )

  (setvar 'Clayer clayer)
  (setvar 'Cecolor cecolor)
  (princ)
)




 ;| ;;
LOAD REACTEUR ;;
|;
(defun loadTextreactor ()

;On command Start
  (setq *startTextCommand*
(vlr-command-reactor
   nil
   '((:vlr-commandWillStart . startTextCommand))
)
  )

;On command Ended
  (setq *endTextCommand*
(vlr-command-reactor
   nil
   '((:vlr-commandEnded . endTextCommand))
)
  )

;On command Cancelled
  (setq *cancelTextCommand*
(vlr-command-reactor
   nil
   '((:vlr-commandCancelled . *cancelTextCommand*))
)
  )

;On command Cancelled
  (setq *failedTextCommand*
(vlr-command-reactor
   nil
   '((:vlr-commandFailed . *failedTextCommand*))
)
  )
)



;;START reactor function
(defun startTextCommand (callReactor startcommandInfo / BGN)
  (setq BGN (nth 0 startcommandInfo))
  (cond
    ;;exemples....
    ((= BGN "TEXT")
     (progn (setvar "CLAYER" Nlayer) (Setvar "CECOLOR" Ncolor))
    )
    ((= BGN "MTEXT")
     (progn (setvar "CLAYER" "0") (Setvar "CECOLOR" "1"))
    )
    ((= BGN "DTEXT")
     (progn (setvar "CLAYER" Nlayer)
    (Setvar "CECOLOR" "bylayer")
     )
    )
  ) ;cond
) ;defun


;;END reactor function
(defun endTCommand (callReactor endcommandInfo / EXT)
  (setq EXT (nth 0 endcommandInfo))
  (cond
    ((= EXT "TEXT") (ResetVAR))
    ((= EXT "MTEXT") (ResetVAR))
    ((= EXT "DTEXT") (ResetVAR))
  ) ;cond
) ;defun

;;CANCEL reactor function
(defun cancelTCommand (callReactor cancelcommandInfo / CNL)
  (setq CNL (nth 0 cancelcommandInfo))
  (cond

    ((= CNL "TEXT") (ResetVAR))
    ((= CNL "MTEXT") (ResetVAR))
    ((= CNL "DTEXT") (ResetVAR))
  ) ;cond
) ;defun

;;FAILED reactor function
(defun failedTCommand (callReactor failedcommandInfo / FLD)
  (setq FLD (nth 0 failedcommandInfo))
  (cond
    ((= FLD "TEXT") (ResetVAR))
    ((= FLD "MTEXT") (ResetVAR))
    ((= FLD "DTEXT") (ResetVAR))
  ) ;cond
) ;defun



;;load the reactor
(loadTextreactor)
Keep smile...

Hangman

  • Swamp Rat
  • Posts: 566
Re: Change MText to a desired layer
« Reply #3 on: December 17, 2007, 04:15:18 PM »
Holy Shnikees Batman !!!
A, ...  yeah, ...  that's a lot of work just to change to a specific layer.

Thank you guys for your help, I've learned something here.  I'm definately going to have to rethink my thinking.

That's an excellent example Andrea, thank you.

(feeling a bit overwhelmed)
Ooophfff !!  :|
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

grush

  • Guest
Re: Change MText to a desired layer
« Reply #4 on: December 18, 2007, 01:30:00 PM »
Create a cui with a pull down so when the user selects mtext, it sets the current layer to your standard or whatever layer you want.
This is mine -

^C^C-LAYER;S;FA-NOTE;;MTEXT 

Pete

GDF

  • Water Moccasin
  • Posts: 2081
Re: Change MText to a desired layer
« Reply #5 on: December 18, 2007, 02:33:26 PM »
This is what I use...


Place this in your startup proceedure:

(princ (load (strcat "" "" "ARCH_VLR_COMMAND")
               "\n*** --- Layer Reactor file not loaded. --- ***")))

Gary


Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

daron

  • Guest
Re: Change MText to a desired layer
« Reply #6 on: December 18, 2007, 03:52:15 PM »
There may be an easier way. If you use a version of autocad that has tool palettes, you may have a palette called commands. If you do, you can make copies of it for different schemes. Then, right-click each one and select properties. You can change lots of options there, such as layer, color, linetype, etc. and each time it's used the mtext will be placed on the correct layer and the current layer will not be affected at all by this. If you set this up on a custom palette, you can set it on your network and have everyone load it and use it.