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;
    }

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