MoI discussion forum
MoI discussion forum

Full Version: Accessing moi programmatically

From: BurrMan
19 Feb 2021   [#1]
Hi Michael,
Was hoping for a quick simple answer. I didn't know where to start.

Lets see if i can explain. Looking to access moi from another app and wondering what that's called... So is it the "app domain" to access?

for instance, Dave Morrill Created and external app, then used it to pass MoI commands (Or access MoI commands) from his external app. Was wondering how.

Like passing this: script:moi.ui.createDialog( 'moi://ui/PluginGallery.htm', 'resizeable,defaultWidth:1000,defaultHeight:1000' );

From a different app, outside of MoI...

Is there a quick direction for how this is done? What it's called in programming etc...?

Thanks.
From: bemfarmer
19 Feb 2021   [#2] In reply to [#1]
If "nodeeditor" was running in python, with a "canvas", and passing MoI javascript API commands to MoI...?
-Brian
From: immortalx
19 Feb 2021   [#3]
BurrMan, Michael should of course answer that better than me, but I'll give it a shot:
MoI's UI is presented through a tiny web-browser. Just like any other browser it supports HTML/CSS/JavaScript. It's mainly through JavaScript that you can interface with it's internals.
Now I guess that Dave's app can communicate with MoI because it generates a popup window from within MoI's UI, so it's not actually a "different" app.
It's JavaScript (and some HTML/CSS) that's hosted inside MoI itself.
So I guess (and I could be wrong) that there's no way for a completely external app to communicate with MoI in an easy way.

The only thing I can come-up with, is that an app could be written in a specific way to make use of the clipboard, as a way to pass data from/to MoI.
That's the way MoI and Rhino can exchange data, but you can only do so much because you can't "affect" existing geometry this way.
Maybe another option would be to write an AutoHotkey script that target's MoI's window, but it depends on what you're trying to achieve for this to even be an option.
From: BurrMan
19 Feb 2021   [#4] In reply to [#3]
Hi immortalx,

Thanks for the response. I understand MoI's structure that you described.

My understanding of daves application was that it was his own, external app written and compiled in python, interacting with MoI's idl/api...

I could be mistaken.

But even the simple javascript, browser description can have many different clients and servers interacting, communicating and affecting actions on both sides... though that all happens in the tcp-ip/http realm...

Not the (moi.filesystem.xxx.xxxx;)
From: BurrMan
19 Feb 2021   [#5] In reply to [#4]
Probably a simplified version of the question would be how to get moi to "hear" another app spit out moi command of script syntax... (or the external app hear moi too)

Like an app domain imports or something..

So, can only moi.exe pass stuff to moi_command.... etc
From: Michael Gibson
19 Feb 2021   [#6] In reply to [#1]
HI Burr, well AppDomains are a construct of the .NET/CLR environment. MoI does not use that so it doesn't know anything about AppDomains.

I'm not sure how Dave Morrill set up his interface from Python to MoI. MoI is not really designed currently to be controlled from another application. It might have been possible in MoI v1 and v2 which were based off of the Microsoft "COM Automation" scripting environment. MoI v3 and v4 are not based off of that anymore, the script engine is now included along with Moi to help keep things more self contained and portable.

One thing that you can do though is to generate a .js script file, then you can launch MoI.exe from your other program and pass it the .js script file name as a command line parameter. When MoI starts up, it looks to see if it was given a .js file name as a command line parameter and if so it will load and execute that script before showing its main window. That's how the batch file processing method works:
http://kyticka.webzdarma.cz/3d/moi/#Batch

I can probably resurrect a COM Automation interface for MoI at some point here but it is not in there right now, not since the v3 switch off of mshtml/jscript.dll to webkit/javascriptcore.

- Michael
From: Michael Gibson
19 Feb 2021   [#7] In reply to [#1]
Hi Burr, or another thing that could work would be to set up a shortcut key in MoI, say Alt+R and for the shortcut key give it a full path to a .js script file including the file extension, like: c:\scripts\myfile.js

Then from the other app you can write out that .js file and then send the MoI main window an Alt+R keyboard message to trigger it.

You could use something like AutoHotkey to trigger the keyboard message to MoI if your other program doesn't have a convenient way to trigger keystroke messages to a window.

- Michael
From: bemfarmer
19 Feb 2021   [#8]
I'm still rooting for python:-)
But know very little about any of this.

Python subprocess.call, and pass an argument to MoI ???:
https://www.digitalocean.com/community/tutorials/how-to-use-subprocess-to-run-external-programs-in-python-3

also this link is trying to open notepad...:
https://stackoverflow.com/questions/204017/how-do-i-execute-a-program-from-python-os-system-fails-due-to-spaces-in-path

- Brian
From: immortalx
19 Feb 2021   [#9]
I've never seen Dave's app before and so I searched a bit and realized that it indeed was a standalone app!
So, sorry everyone for the confusion. My assumption was based on what Max did with NodeEditor, which seems to work the way I described.
From: BurrMan
20 Feb 2021   [#10] In reply to [#7]
Thanks Michael. I can move along from that...
From: wayne hill (WAYNEHILL5202)
20 Feb 2021   [#11]
FYI: Watching this thread with interest.