Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:open3dm [2015/09/14] (current)
Line 1: Line 1:
 +======Open a 3DM file======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to open a Rhino 3DM file from a plug-in command.//
  
 +=====Question=====
 +Does the Rhino C++ SDK have a way of opening a 3DM file, an STL file, or any other type of file?
 +
 +=====Answer=====
 +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=====
 +[[developer:​runrhinocommandfromplugincommand|How to run a Rhino command from a plug-in command]]
 +
 +===== Example =====
 +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.
 +
 +==== C++ ====
 +<code c++>
 +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();​
 +  filename.TrimLeftAndRight();​
 +  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;​
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
developer/sdksamples/open3dm.txt ยท Last modified: 2015/09/14 (external edit)