Plugin providing Multiple Import File Types

Our plugin provides support for 11 different filetypes for various CNC / machine formats.
So far this all happens with our own GUI.
I would like to expose these filetypes to the Rhino Open / Import lists.

To do this i understand i need to create 11 classes which descend from FileImportPlugIn.

However i see that there is a restriction on there being only 1 class descending from Plugin in each Plugin.

Does that mean i need to create 11 new dll’s which can live in the same Plugin or 11 new plugins which the user would have to install indivdually?

How do other people do this?

You can use 1 FileImportPlugIn and register multiple file types.

1 Like

That’s interesting, would i need to change the type of my main plugin to being a FileImportPlugIn rather than just PlugIn - does that have any other implications?

What I typically did was to have three plug-ins

  • 1 utility plug-in with all commands;
  • 1 file import plug-in with all import code;
  • 1 file export plug-in with all export code.
  • Support these with a central DLL file that all three plug-ins could use.

Multiple file formats can be supported like so:

    protected override Rhino.PlugIns.FileTypeList AddFileTypes(Rhino.FileIO.FileReadOptions options)
    {
      var result = new Rhino.PlugIns.FileTypeList();
      result.AddFileType("Stem File (*.stm)", "stm");
      result.AddFileType("Branch File (*.brn)", "brn");
      return result;
    }

    protected override Rhino.PlugIns.ReadFileResult WriteFile(string filename, int index, RhinoDoc doc, Rhino.FileIO.FileWriteOptions options)
    {
      if (index == 0)
      {
        return ReadSTMFile(filename, doc, options);
      }
      else if (index == 1)
      {
        return ReadBRNFile(filename, doc, options);
      }
      return Rhino.PlugIns.WriteFileResult.Failure; 
    }
2 Likes

Thanks @menno that sounds a good plan.

Is it possible to add custom import options for a given file type?

Not directly, but you could ask for user input on the commandline with GetOption during import, or show the user a dialog with options.

1 Like

Thanks @menno

Well that was pretty painless :slight_smile:
image

Found a sneaky tricky to put our imports at the top of the list :laughing:

1 Like