MoI discussion forum
MoI discussion forum

Full Version: Launching other applications from within MOI

From: pior (PIOR_O)
18 Feb 2021   [#1]
Hello all, Michael -

Here is a somewhat unusual question : is it possible to launch an .exe, or a .bat, or any application link in script directly from within MOI3D ? For instance launching notepad or running a .ahk script at the press of a CommandButton or MenuItem, or from a hotkey.

(I find that having such links to other applications reachable directly from within the application currently being used is a great way to maintain focus and flow. Of course one can always click an icon or make a system search, but I'd be curious to know if I can make my own little buttons for this as that is something I am doing already - to launch MOI from within Photoshop, to launch Photoshop from within Blender, and so on).

I hope this makes (some) sense :)

P.O.
From: Michael Gibson
18 Feb 2021   [#2] In reply to [#1]
Hi pior, yes you can launch an external program using:
moi.filesystem.shellExecute( Path, Parameters /*optional - command line parameters to pass to program*/, false /*optional - wait for process to finish*/ );

So for example to launch notepad:
moi.filesystem.shellExecute( 'notepad.exe' );

- Michael
From: Michael Gibson
18 Feb 2021   [#3] In reply to [#1]
Note that if you have any backslash \ characters in a string you'll need to put in 2 of them like: 'c:\\path\\program.exe' .

That's because the backslash is an escape character for Javascript code, like \n is the escape code for making a newline character. To do a backslash in a string you need \\ .

- Michael
From: Frenchy Pilou (PILOU)
18 Feb 2021   [#4]
You have also a Console ;)
http://sites.google.com/site/nakanosoramemo/software/moi3d/script-console

but alas seems not more existing! :(


From: pior (PIOR_O)
18 Feb 2021   [#5] In reply to [#3]
Hello Michael, thank you so much for the help ! This was perfectly clear and worked right away, thanks. It really makes for a nice uninterrupted workflow.



(BTW this custom UI revolves around the idea of every tool being available directly under the span of one single mouse scroll. Quite different from the default paradigm of expandable buttons, but maybe it can spark some ideas. And BTW the Set Style/Hide Style/Show Style commands turned out to be very useful, so thanks again for the code that you provided a few weeks ago).

Also, in passing : what would be the commands for the "Show Grid" and "Show Grid Axis" tickboxes ? I constantly have to toggle these on and off and having to go and reach them from the Gird Snap button and from the Preferences panel is a bit tiresome. So I'd like to put them within reach in my UI as well.

@FP : Sorry I do not quite understand what you mean. Is this console available in V4 ? And regardless I assume that it lets one run scripts/commands, which is handy of course ... but that's irrelevant here as I have no problem with running scripts in and of themselves - it is the specific command for launching exes that I was looking for ...

Image Attachments:
2021-02-19 02_14_16-Options.png  2021-02-19 02_19_02-MoI.png 


From: Michael Gibson
18 Feb 2021   [#6] In reply to [#5]
Hi Pior, for show grid and show grid axes try these:

moi.grid.display = !moi.grid.display;

moi.grid.showXYAxes = !moi.grid.showXYAxes;

- Michael
From: pior (PIOR_O)
19 Feb 2021   [#7] In reply to [#6]
That's brilliant - thank you so much as usual !