Best way to code Open File dialog

I’ve taken a look at Eto Forms, Rhino.UI, as well as System.Windows.

Which one of these would work best for creating a button that creates an Open File dialog that will allow users to view and alter DWG files in Rhino through a plugin? I’m using C#, and specifically not Python.

At what point do I use Eto Forms, and at what point do I use Rhino.UI?

Any examples would be helpful as well.

1 Like

Hi @Rebekah1,

Unless you want to prompt for .3dm files, I’d just use Eto.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  string filename = null;

  if (mode == RunMode.Interactive)
  {
    var ofd = new Eto.Forms.OpenFileDialog
    {
      MultiSelect = false,
      Title = "Open",
      Filters =
        {
          new Eto.Forms.FileFilter
          {
            Name = "AutoCAD Drawing (*.dwg)",
            Extensions = new[] { "*.dwg" }
          },
          new Eto.Forms.FileFilter
          {
            Name = "AutoCAD Drawing Exchange (*.dxf)",
            Extensions = new[] { "*.dxf" }
          }
        },
      CurrentFilterIndex = 0
    };

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

    filename = ofd.FileName;
  }
  else
  {
    var gs = new GetString();
    gs.SetCommandPrompt("Name of AutoCAD file to open");
    gs.Get();
    if (gs.CommandResult() != Result.Success)
      return gs.CommandResult();
    filename = gs.StringResult();
  }

  filename = filename.Trim();
  if (string.IsNullOrEmpty(filename))
    return Result.Nothing;

  if (!System.IO.File.Exists(filename))
  {
    RhinoApp.WriteLine("File not found.");
    return Result.Failure;
  }

  // TODO...

  return Result.Success;
}

– Dale

1 Like