Click or drag to resize

RhinoGetGetFileName Method (GetFileNameMode, String, String, Object, RhinoGetBitmapFileTypes)

[Missing <summary> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

Namespace:  Rhino.Input
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 6.0
Syntax
public static string GetFileName(
	GetFileNameMode mode,
	string defaultName,
	string title,
	Object parent,
	RhinoGetBitmapFileTypes fileTypes
)

Parameters

mode
Type: Rhino.Input.CustomGetFileNameMode

[Missing <param name="mode"/> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

defaultName
Type: SystemString

[Missing <param name="defaultName"/> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

title
Type: SystemString

[Missing <param name="title"/> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

parent
Type: SystemObject

[Missing <param name="parent"/> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

fileTypes
Type: Rhino.InputRhinoGetBitmapFileTypes

[Missing <param name="fileTypes"/> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

Return Value

Type: String

[Missing <returns> documentation for "M:Rhino.Input.RhinoGet.GetFileName(Rhino.Input.Custom.GetFileNameMode,System.String,System.String,System.Object,Rhino.Input.RhinoGet.BitmapFileTypes)"]

Examples
using Rhino;
using Rhino.Commands;
using Rhino.Input;
using Rhino.Input.Custom;
using System;
using System.Windows;
using System.Windows.Controls;

namespace examples_cs
{
  public class ExtractThumbnailCommand : Command
  {
    public override string EnglishName { get { return "csExtractThumbnail"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var gf = RhinoGet.GetFileName(GetFileNameMode.OpenImage, "*.3dm", "select file", null);
      if (gf == string.Empty || !System.IO.File.Exists(gf))
        return Result.Cancel;

      var bitmap = Rhino.FileIO.File3dm.ReadPreviewImage(gf);
      // convert System.Drawing.Bitmap to BitmapSource
      var image_source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero,
        Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

      // show in WPF window
      var window = new Window();
      var image = new Image {Source = image_source};
      window.Content = image;
      window.Show();

      return Result.Success;
    }
  }
}
Python
import Rhino
import rhinoscriptsyntax as rs
from scriptcontext import doc

import clr
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms

def RunCommand():

  fn = rs.OpenFileName(title="select file", filter="Rhino files|*.3dm||")
  if fn == None:
    return

  bitmap = doc.ExtractPreviewImage(fn)

  f = System.Windows.Forms.Form()
  f.Height = bitmap.Height
  f.Width = bitmap.Width
  pb = System.Windows.Forms.PictureBox()
  pb.Image = bitmap
  pb.Height = bitmap.Height  #SizeMode = System.Windows.Forms.PictueBoxSizeMode.AutoSize
  pb.Width = bitmap.Width
  f.Controls.Add(pb);
  f.Show();

if __name__ == "__main__":
  RunCommand()
See Also