RhinoApp.Runscript Invoke from event stream

Hi, I have problems scripting the -_Import command inside of a plugIn.

I have read through multiple posts with similar issues, the typical solutions where to

  • Write a Command and
  • Set the CommandStyle to ScriptRunner

my problem is a bit different though:

I run a server that listens for pings on a port and fires events from which i want to to a file import.
Since the file format -(for now)- is .fbx, which can only be imported via script I need to call RhinoApp.Runscript().

The approach i tried

  • Create a Command in my PlugIn: XXImportFBX with CommandStyle set to Scriptrunner
  • Give the Command a backing field for the FilePath
  • Insice the Command call RhinoApp.Runscript($"-_Import \"{path}\" ")
  • When I catch an Import event, set the backing field to the appropriate FilePath and call RhinoApp.ExecuteCommand(_doc, "XXImportFBX")

This does not work, the command runs but RhinoApp.RunScript just returns false, which I assume is related to this:

When I just type the command name in the commandline, after the FilePath field has been populated everything works fine, so it seems Rhino prohibits calling commands like I try to do it here.

No errors are thrown at any point, RhinoApp.Runscript() returns false, and RhinoApp.ExecuteCommand() returns Result.Success.

Is there any way I can achieve command execution from a non-command-class?
Since the event stream comes from another application I would rather not have the user run a blocking command inside of rhino which freezes the UI until they click something in said other application.

Since you helped in many other posts related to RhinoApp.Runscript() problems I’m pinging you directly @dale, I hope you don’t mind.

Also the zipped files in this post, seemed like they might also be related to the problem I’m having here, as the UI is also on another thread and can’t be a command class:

Thanks in advance,
Lando

Hi @lando.schumpich,

Your import script should be run Rhino’s main UI thread.

RhinoApp.InvokeOnUiThread

– Dale

Thanks, that works just fine.