I am trying to save a Mesh into an OBJ file, but I guess I am doing something wrong here… here is my code:
Rhino.RhinoDoc rc = Rhino.RhinoDoc.Create(“”);
rc.Objects.AddMesh(meshToSave);
Rhino.FileIO.FileObjWriteOptions options = new Rhino.FileIO.FileObjWriteOptions(new Rhino.FileIO.FileWriteOptions());
options.MapZtoY = true;
Rhino.PlugIns.WriteFileResult res = Rhino.FileIO.FileObj.Write(“PATH_TO_FILE/fromRhino.obj”, rc, options);
if (res == Rhino.PlugIns.WriteFileResult.Success)
{ MessageBox.Show(“File saved successfully”); }
else
{ MessageBox.Show(“Something went wrong :(”); }
When I create the new RhinoDoc, it is overriding the current ActiveDoc and Rhino is kind of reset. This same code works perfectly if I run it inside a C# node in Grasshopper.
Gotcha; that is all new functionality in the Rhino 7 WIP and can’t be added to Rhino 6. It was a pretty big project that required a good number of changes to Rhino.
@stevebaer@dale
Thanks for the replies. I am a bit confused here as well, there is no way of exporting a mesh to obj from Rhino 6? What is the use case of FileObj.Write then?
Just passing by here and thinking out loud… Do you need a new doc? Why not just use the active doc and set the FileWriteOptions to use the selected objects only option to export your mesh. Just delete the mesh after?
Writing an obj file by hand is like 10 lines of code, check the file format specification & you’ll see it is literally a set of XYZ coordinates, one on each line. Followed by a set of indices, one line per face (including ngons).
This can absolutely be done in Rhino 6, but only with the activedoc.
I was referring to the fact that you couldn’t create a temporary document that doesn’t replace the activedoc in Rhino 6 (which is something you can do in Rhino 7).