Saving OBJ using c# API (FileObj.Write)

When writing an obj I am being prompted on the Rhino command line for PolygonDensity.
I have asked it not to show dialogs, but it still asks for this. How do I stop it from asking anything and just write the obj file? Thanks!

    public bool writeObjFile(string filename)
    {
        RhinoDoc doc = RhinoDoc.ActiveDoc;
        Rhino.FileIO.FileWriteOptions writeOptions =
            new Rhino.FileIO.FileWriteOptions()
        {
            SuppressDialogBoxes      = true,
            WriteSelectedObjectsOnly = true
        };

        Rhino.Geometry.MeshingParameters meshingParameters = 
            Rhino.Geometry.MeshingParameters.QualityRenderMesh;

        Rhino.FileIO.FileObjWriteOptions objWriteOptions =
            new Rhino.FileIO.FileObjWriteOptions(writeOptions)
        {
            CreateNgons                    = false,
            CullUnnecessaryVertexesInNgons = true,
            ExportNormals                  = true,
            ExportOpenMeshes           = true,
            ExportTcs                      = true,
            ExportVcs                      = true,
            MeshParameters                 = meshingParameters,
            MeshType = Rhino.FileIO.FileObjWriteOptions.VertexWelding.Welded,
            UnderbarMaterialNames          = true,
            ExportMaterialDefinitions      = false,
            ObjectType = Rhino.FileIO.FileObjWriteOptions.GeometryType.Mesh,
            UseSimpleDialog                = false,
            WrapLongLines                  = false,
        };



        }

        bool rc = false;

        {
            var res = Rhino.FileIO.FileObj.Write(filename, doc,
                                                 objWriteOptions);
            rc = (res == Rhino.PlugIns.WriteFileResult.Success);

        } catch (Exception e) {
            if (e is System.IO.IOException) {

                RhinoApp.WriteLine("Write OBJ IO error: {0}",
                                   e.Message);
            } 
            return false;
        }

        return rc;
    }
1 Like

Hi Ian,

If you’re using V5, then your only option is to script the Export command.

If you’re using V6, in order to get absolutely no UI, you will need to mesh the objects first (and add them to the document). See Rhino.DocObjects.RhinoObject.MeshObjects, “uiStyle”. Then select those meshes and run your code. This will keep the meshing dialog or command options from appearing. Later you’ll have to go back and delete the temp meshes you added.

In V7, there’s is a new property on Rhino.FileIO.FileWriteOptions called SuppressAllInput that obj export pays attention to. If you add that to your code, and run it in V7, you can get what you want.

Rhino.FileIO.FileWriteOptions writeOptions = new Rhino.FileIO.FileWriteOptions() { SuppressDialogBoxes = true, SuppressAllInput = true, WriteSelectedObjectsOnly = true };

Tim

1 Like

Thanks Tim – I have everything working well on Rhino 6, but now we find out that our client has Rhino 5, not 6. I’ve found the example code to get ETO forms to work in R5. My question is; we have several floating licences for R6, but how can I run R5 for just a few weeks to get this working?

Hi @ian4,

Is this what you need?

– Dale

I’ve got it running in trial mode for 90 days – that should be enough time to see if I can get an ETO dockable panel working in Rhino 5. I have the SampleCsETO you put together – hopefully I can get that working and put in my UI code and see what happens…

Hi @tim, I’ve tried what you suggest (V6) and it does not work. After adding the mesh to the document, i select it and run this code:

write_options = Rhino.FileIO.FileWriteOptions()
write_options.WriteSelectedObjectsOnly = True
write_options.SuppressDialogBoxes = True
    
obj_options = Rhino.FileIO.FileObjWriteOptions(write_options)
obj_options.UseSimpleDialog = False
obj_options.ExportMaterialDefinitions = False
obj_options.ExportNormals = True
obj_options.ExportObjectNames = Rhino.FileIO.FileObjWriteOptions.ObjObjectNames.NoObjects
obj_options.ExportGroupNameLayerNames = Rhino.FileIO.FileObjWriteOptions.ObjGroupNames.NoGroups
obj_options.ExportOpenMeshes = True
obj_options.ExportTcs = True
obj_options.ExportVcs = True
obj_options.MapZtoY = False
obj_options.MeshType = Rhino.FileIO.FileObjWriteOptions.VertexWelding.Normal
obj_options.ObjectType = Rhino.FileIO.FileObjWriteOptions.GeometryType.Mesh
obj_options.SignificantDigits = 16
obj_options.EolType = Rhino.FileIO.FileObjWriteOptions.AsciiEol.Crlf
obj_options.WrapLongLines = False

rc = Rhino.FileIO.FileObj.Write(file_path_name, scriptcontext.doc, obj_options)

The result is a command prompt:

Choose meshing option (DetailedOptions PolygonDensity=50):

Can i get rid of this prompt ? (since i only have a mesh, it does not make sense to adjust any meshing options).

thanks,
c.

Hi Clement,

I see that it happens in V7 too. It’s not going to get fixed for V6 but I’m going to try to figure it out for V7. I’ll make a YT issue in a bit and post it here.

Tim

Follow this YT issue to track progress.
https://mcneel.myjetbrains.com/youtrack/issue/RH-66271

Thanks @tim, can you suppress it in V7 using SuppressAllInput = True ? (This is not available in V6) Anyway, if there is only a single mesh, i think it could safely skip asking for mesh settings.
_
c.

It’s already done and no settings were necessary. It uses the same flag that prevents the meshing dialog from appearing when there is nothing to mesh. It was not being applied to the command line version.

1 Like

thanks @tim for the quick fix.

_
c.