Trying to run two commands with one toolbar pick

Trying to run two commands with one toolbar pick

jjcrocco
Enthusiast Enthusiast
1,322 Views
6 Replies
Message 1 of 7

Trying to run two commands with one toolbar pick

jjcrocco
Enthusiast
Enthusiast

I have a lisp routine (c2textlyr) that turns the last object made to be on the text layer for that particular trade based on the current layer.  It works good by itself, or after a batch of commands and is preloaded within the acaddoc.lsp.  I am having issues running it after for the Mleader command that is a standard toolbar pick.  I want to run c2textlyr right after the mleader, but the mleader command doesn't finish before my LISP command takes over. I have tried using various pauses within, but cant get it to work.  Should be simple for a pro I would think, which I am not. 🙂

 

^C^C_mleader, c2textlyr

 

Any help is appreciated.

0 Likes
Accepted solutions (1)
1,323 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant

@jjcrocco wrote:

I have a lisp routine (c2textlyr) ....  I am having issues running it after for the Mleader command that is a standard toolbar pick.  I want to run c2textlyr right after the mleader, but the mleader command doesn't finish before my LISP command takes over. ....


[That comma in the macro is inappropriate, but in any case....]

 

That may require definition of another command name combining the two, to be called via the Toolbar/Tool Palette button, rather than having it directly in the button.  It probably needs the indefinite-quantity-of-inputs wait-for-the-command-to-finish approach, to complete the Mleader before going on to c2textlyr, which approach doesn't seem to work in a command macro as some AutoLisp functions do.  Try something like this, defining the combination command not in the button:

 

(defun C:YourCommandName ()
  (command "_.mleader")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (c:c2textlyr)
)

 

and then, with that loaded, put this command macro in the button:

 

^C^CYourCommandName

 

That approach also has the advantage that the User can just type in the command name if they prefer, rather than always needing to get at it via the button, if the appropriate Toolbar/Tool Palette doesn't happen to be up at the time.

Kent Cooper, AIA
0 Likes
Message 3 of 7

jjcrocco
Enthusiast
Enthusiast

Yes, I think that may work.  Thank you, I will try it and let you know along with a kudos.

0 Likes
Message 4 of 7

jjcrocco
Enthusiast
Enthusiast

Hi Kent, that worked pretty good.  There is one issue I cant explain.  When using the standard mleader command, it gives me mtext where I can type more than one word and have multiple lines.  When I run it within my command, it all works the same except it only prompts me for text, and if more than one word the space ends the command, and it is not mtext.  Any ideas?

 

(defun c:mleader-cke ()
  (command "_.mleader")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (c:c2textlyr)
)

 

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@jjcrocco wrote:

....  When using the standard mleader command, it gives me mtext where I can type more than one word and have multiple lines.  When I run it within my command, it all works the same except it only prompts me for text, and if more than one word the space ends the command, and it is not mtext.  Any ideas? ....


That seems to be the result of calling MLEADER from within an AutoLisp (command) function.  That uses the command-line version [when there is one] of whatever the command is, the difference in most cases being that certain normally dialog-box-based commands can be used without bringing up the dialog box, which is often preferred in AutoLisp routines.  So it's taking text input at the command line, not in the in-the-drawing Mtext editor that MLEADER normally uses, and I think therein lies the problem.  Preceding it with (initdia) to force the dialog box [as one sometimes want to do in other commands] doesn't work here [I tried it], because it seems the in-drawing editor unfortunately isn't the same kind of thing as a dialog box.  I haven't found a way to get it to transfer over to the in-drawing editor, even if I remove the followup other command and leave the MLEADER as the last thing in the routine, but maybe someone else knows how to do that.

Kent Cooper, AIA
Message 6 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Only other way left to try...

 

(defun c:mleader-cke ()
  (initcommandversion)
  (command "_.mleader")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (c:c2textlyr)
)
Message 7 of 7

jjcrocco
Enthusiast
Enthusiast

That worked, thank you BOTH!

0 Likes