How to Export/Import stp files without using RhinoApp.RunScript()?

plugin
grasshopper

#1

Hi all.
I am developing .Net plugin for Grasshopper. I need to convert rhino geometry to STEP representation, and then send the content of .stp file to server.
I am using now RhinoApp.RunScript() to access the STEP Import/Export plug-ins and convert rhino geometry. But it works through the rhino command line. The problem is that RhinoApp.RunScript() works only in main rhino.exe thread, and all background threads have to wait until main thread will be available to run the script.
Is there any other possible way to call import/export functions ?

I will be great to have possibility to get the step representation of rhino geometry without writing third-party files, and to create geometry from step representation, received from server.
Does anybody has any ideas?
Any help would be appreciated.
Thank you.


(Menno Deij - van Rijswijk) #2

Is there any other possible way to call import/export functions ?

In short: No, there is no other way. Unless you write your own STEP export routine, but that is not easy.


#3

Thanks for the answer @menno
One more question. How can I save geometry in 3dm format? Is there other way to do this, except of using RunScript method? I need to have a possibility to save rhino geometry, referenced in Grasshopper.
As far as I know to save a specific object in 3dm format, we have to use Export command, then select required geometry and do export.
Unfortunately it works only through command line.


(Menno Deij - van Rijswijk) #4

For 3dm the situation is different, because you can use the File3dm class to save geometry.

http://4.rhino3d.com/5/rhinocommon/html/T_Rhino_FileIO_File3dm.htm

The best way is to have an empty 3dm template file for saving the content, instead of creating a 3dm file ‘from scratch’, because then you can set up units, tolerances, layers, etc. once. Doing that from code is cumbersome.

What we did here was to make such a template, and then add it to the Rhino plug-in or Grasshopper add-on as a file resource.
Then, when you want to save, write the template to disk in a temporary location, open it, add the content and write it to the final location.

byte[] template = Resources.File3dmTemplate;
File.WriteAllBytes(temp, template);
using (File3dm f = File3dm.Read(temp))
{
    // f.Objects.Add<Curve|Brep>(...) add geometry here 
    f.Write(destination, 5); //write in RH5 format to destination
}

if (File.Exists(temp))
    File.Delete(temp); // remove the intermediate file



#5

You helped me, Thank you a lot!


(Bryan T Jones) #6

Menno/Valeria,

Thank you for the clarification. I have banging at this problem for a while and ended up going the RunScript route Valeria mentioned above. The problem with this approach is that when you send a Rhino.RhinoApp.RunScript("-Save " with .stp extension to the command line the Rhino Client responds with a follow up asking for export options and blocks your GH thread until the user hits enter on Rhino client. If automation is needed, which is always the case in an iterative optimization problem, one way to keep the automation running is to create another thread and start it prior to the RunScript("-Save… stp") command. The second thread should have a Thread.Sleep and then a Rhino.RhinoApp.SendKeystrokes("", true). This will basically provide a quick user enter to accept default export options, thus releasing the Rhino client and unblocking your main GH thread.

Below are attachments of the definition with the C# component for stepping out geometry!

Regards,

Bryan T Jones!

BTJ%20GH%20STEP%20Export|690x365

BTJ GH STEP Export.gh (15.8 KB)