Site Tools

Open a 3DM file

Developer: C++
Summary: Demonstrates how to open a Rhino 3DM file from a plug-in command.


Does the Rhino C++ SDK have a way of opening a 3DM file, an STL file, or any other type of file?


As each type of file, support by Rhino for opening or importing, has a different set of options, it not possible to write a single, generic file open function and hope to support all formats. Thus, if you want to open or import a file from a plug-in command, then simply script either Rhino's Open or Import command using CRhinoApp::RunScript().

More Information


The following example command demonstrates how to open a Rhino 3DM file from a plug-in command. You can use this same technique to open other support file types, such as STL, IGES, DWG, and others.


CRhinoCommand::result CCommandTest::RunCommand( const CRhinoCommandContext& context )
  // Prompt the user for the name of a 3dm file to open
  ON_wString filename;
  CWnd* pParentWnd = CWnd::FromHandle( RhinoApp().MainWnd() );
  CRhinoGetFileDialog gf;
  gf.SetScriptMode( context.IsInteractive() ? FALSE : TRUE );
  BOOL rc = gf.DisplayFileDialog( CRhinoGetFileDialog::open_rhino_only_dialog, filename, pParentWnd );
  if( !rc )
    return CRhinoCommand::cancel;
  // Verify the file name string
  filename = gf.FileName();
  if( filename.IsEmpty() )
    return CRhinoCommand::nothing;
  // Verify the file
  if( !CRhinoFileUtilities::FileExists(filename) )
    RhinoApp().Print( L"File not found.\n" );
    return CRhinoCommand::failure;
  // Script Rhino's open command. Note, in case the file name
  // string contains spaces, we will want to surround the string
  // with double-quote characters so the command line parser
  // will deal with the string property.
  ON_wString script;
  script.Format( L"_-Open \"%s\"", filename );
  RhinoApp().RunScript( script, 0 );
  return CRhinoCommand::success;

developer/sdksamples/open3dm.txt ยท Last modified: 2015/09/14 (external edit)