Eto.Forms.SaveFileDialog strange behaviour

Hi,
this is my code for exporting a number of objects, each to its own file:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        bool isSolid = true;
        List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>();
        const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh | Rhino.DocObjects.ObjectType.Surface;

        

        List<Rhino.DocObjects.ObjRef> objrefs = new List<Rhino.DocObjects.ObjRef>();

        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select surfaces, polysurfaces, subDs or meshes to export");
        go.GeometryFilter = geometryFilter;
        go.GroupSelect = true;
        go.SubObjectSelect = false;
        go.DeselectAllBeforePostSelect = true;

        Rhino.Input.GetResult res = go.GetMultiple(1, 0);
        if (res == GetResult.Cancel) return Result.Failure;
        if (res == Rhino.Input.GetResult.Object)
        {

            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.DocObjects.ObjRef objref = go.Object(i);
                objrefs.Add(objref);

                
                if(objref.Brep() != null)
                    if (!objref.Brep().IsSolid) isSolid = false;
                
                else if (objref.Mesh() != null)
                    if (!objref.Mesh().IsSolid) isSolid = false;
                
                else if (objref.SubD() != null)
                    if (!objref.SubD().IsSolid) isSolid = false;
                
                else if (objref.Surface() != null)
                    if (!objref.Surface().IsSolid) isSolid = false;
                else
                    return Rhino.Commands.Result.Cancel;

            }
        }

        else if (res != Rhino.Input.GetResult.Object)
            return Rhino.Commands.Result.Cancel;

        if (!isSolid)
            Dialogs.ShowMessage("At least on object is not solid! Export might not be valid!", "Warning!");


        var ofd = new Eto.Forms.SaveFileDialog
        {
            Title = "Export",
            Filters =
            {

                new Eto.Forms.FileFilter
                {
                    Name = "STEP (stp,step)",
                    Extensions = new[] { "*.stp" }
                },
                new Eto.Forms.FileFilter
                {
                    Name = "STL (stl)",
                    Extensions = new[] { "*.stl" }
                },
                new Eto.Forms.FileFilter
                {
                    Name = "Rhino3dm (3dm)",
                    Extensions = new[] { "*.3dm" }
                }
            },
            CurrentFilterIndex = 0
            
        };

        
        
        var result = ofd.ShowDialog(RhinoEtoApp.MainWindow);
        if (result != Eto.Forms.DialogResult.Ok)
            return Result.Cancel;


        String path = ofd.FileName;
        String[] splipath = path.Split('.');

        doc.Objects.UnselectAll();
        Rhino.UI.ShowMessageResult fileRes;
        for (int i = 0; i < objrefs.Count; i++)
        {
            Rhino.DocObjects.RhinoObject ro = objrefs[i].Object();
            ro.Select(true);
            var filename = splipath[0] + "_00"+ (i+1) + "." + splipath[1];
            if (System.IO.File.Exists(filename))
            {
                fileRes = Dialogs.ShowMessage("Filename already exist! Overwrite existing file?", "Warning!", ShowMessageButton.OKCancel, ShowMessageIcon.Warning);
                if (fileRes == ShowMessageResult.Cancel)
                    continue;
            }
            doc.ExportSelected(filename);
            ro.Select(false);
        }

        // ---
        return Result.Success;
    }

When the code opens the ofd.ShowDialog(RhinoEtoApp.MainWindow); dialog i can choose from the list of file formats but it keeps the initial file extension after the file name.

Is there an option that i am missing?

To narrow this down a bit I tried this code in the script editor, and yes, I can confirm the same behaviour. I’m not aware that you’re missing anything, This may be a bug.

using Rhino;
using Rhino.UI;

var ofd = new Eto.Forms.SaveFileDialog
{
    Title = "Export",
    Filters =
    {
        new Eto.Forms.FileFilter
        {
            Name = "STEP (stp,step)",
            Extensions = new[] { "*.stp" }
        },
        new Eto.Forms.FileFilter
        {
            Name = "STL (stl)",
            Extensions = new[] { "*.stl" }
        },
        new Eto.Forms.FileFilter
        {
            Name = "Rhino3dm (3dm)",
            Extensions = new[] { "*.3dm" }
        }
    },
    CurrentFilterIndex = 0,
};

var result = ofd.ShowDialog(RhinoEtoApp.MainWindow);

RhinoApp.WriteLine(ofd.FileName);
1 Like

It’s a bug! I’ve created a ticket
https://mcneel.myjetbrains.com/youtrack/issue/RH-85223/Eto-SaveFileDialog-not-changing-extension