redefine mleader command?

redefine mleader command?

spear_kevin_pe
Advisor Advisor
882 Views
8 Replies
Message 1 of 9

redefine mleader command?

spear_kevin_pe
Advisor
Advisor

Is there a way to redefine the mleader command to start by setting UCS View, and then when the command is finished reset to UCS W?

Thanks
Kevin

Kevin Spear, PE
0 Likes
Accepted solutions (1)
883 Views
8 Replies
Replies (8)
Message 2 of 9

ВeekeeCZ
Consultant
Consultant

Try this...

 

 

(command "_.UNDEFINE" "MLEADER")

(defun c:MLEADER nil
  (command "_.UCS" "_View"
	   ".MLEADER")
  (while (> (getvar 'CMDACTIVE) 0)
    (command PAUSE))
  (command "_.UCS" "_World")
  (princ)
)
Message 3 of 9

spear_kevin_pe
Advisor
Advisor

That's fantastic! I run the mleader command, it switches the UCS to VIEW, executes mleader and then resets to World!

 

I did encounter one issue. It creates the mtext object with a "\" and i do not get a chance to type the text.

SNAG-0046.png

 here's a screencast.

http://autode.sk/29GeRZO

 

 

Here's the code in my startup.lsp file:

SNAG-0047.png

 

Any ideas why i am getting those results? I am using Civil 3D 2017...

 

Thanks again for your help! Even if i have to edit the text, this is far better than selecting and editing rotation angle, etc.

Thanks
Kevin

Kevin Spear, PE
0 Likes
Message 4 of 9

ВeekeeCZ
Consultant
Consultant
Accepted solution

Hi, the following version was tested on vanilla 2015. Unfortunately 2017 treats texts little bit differently... so test it yourself.

 

Spoiler
(command "_.UNDEFINE" "MLEADER")

(defun c:MLEADER ( / p1 p2 *error*)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (command-s "_.UCS" "_World")
    (princ))
  
  (command "_.UCS" "_View")
  (if (and (setq p1 (getpoint "\Specify leader arrowhead location: "))
	   (setq p2 (getpoint p1 "\Specify leader landing location: "))
	   )
    (command ".MLEADER" "_none" p1 "_none" p2 ""))
  (command "_.TEXTEDIT" "_last")
  (command "_.UCS" "_World")
  (princ)
)
Message 5 of 9

spear_kevin_pe
Advisor
Advisor
Works great!

When i go to pick outside the text editor to finish typing, the command wants to continue, so hitting enter/spacebar completes the command. Small thing to fix what's otherwise a manual process for me. Thanks!
Thanks
Kevin

Kevin Spear, PE
0 Likes
Message 6 of 9

ВeekeeCZ
Consultant
Consultant

@spear_kevin_pe wrote:
Works great!

When i go to pick outside the text editor to finish typing, the command wants to continue, so hitting enter/spacebar completes the command. Small thing to fix what's otherwise a manual process for me. Thanks!

Glad you feel that way.

 

On my 2015 it works even by clicking outside. I found in HELP, that '17 has TEXTEDIT system variable. Let's try it!

 

Spoiler
(command "_.UNDEFINE" "MLEADER")

(defun c:MLEADER ( / p1 p2 ote *error*)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'TEXTEDIT ote)
    (command-s "_.UCS" "_World")
    (princ))

  (setq ote (getvar 'TEXTEDIT))
  (setvar 'TEXTEDIT 1)
	
  (command "_.UCS" "_View")
  (if (and (setq p1 (getpoint "\Specify leader arrowhead location: "))
	   (setq p2 (getpoint p1 "\Specify leader landing location: "))
	   )
    (command ".MLEADER" "_none" p1 "_none" p2 ""))
  (command "_.TEXTEDIT" "_last")
  (command "_.UCS" "_World")
  (setvar 'TEXTEDIT ote)
  (princ)
)
0 Likes
Message 7 of 9

spear_kevin_pe
Advisor
Advisor

Thanks for trying to debug this....

 

I still get an extra error. I noticed at the command line this happens when i click outside the text editor to finish the command:

SNAG-0048.png

Thanks
Kevin

Kevin Spear, PE
0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant

Ok, one more try... 

 

Spoiler
(command "_.UNDEFINE" "MLEADER")

(defun c:MLEADER ( / p1 p2 ote *error*)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nError: " errmsg)))
    (setvar 'TEXTEDITMODE ote)
    (command-s "_.UCS" "_World")
    (princ))

  (setq ote (getvar 'TEXTEDITMODE))
  (setvar 'TEXTEDITMODE 1)
	
  (command "_.UCS" "_View")
  (if (and (setq p1 (getpoint "\Specify leader arrowhead location: "))
	   (setq p2 (getpoint p1 "\Specify leader landing location: "))
	   )
    (command ".MLEADER" "_none" p1 "_none" p2 ""))
  (command "_.TEXTEDIT" "_last")
  (command "_.UCS" "_World")
  (setvar 'TEXTEDITMODE ote)
  (princ)
)
0 Likes
Message 9 of 9

spear_kevin_pe
Advisor
Advisor
That did the trick. thanks!
Thanks
Kevin

Kevin Spear, PE
0 Likes