protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var filename = string.Empty; if (mode == Rhino.Commands.RunMode.Interactive) { filename = RhinoGet.GetFileName(GetFileNameMode.OpenRhinoOnly, null, "Open", RhinoApp.MainWindowHandle()); } else { RhinoGet.GetString("Name of Rhino file to open", false, ref filename); } filename = filename.Trim(); if (string.IsNullOrEmpty(filename)) { return(Result.Cancel); } if (!System.IO.File.Exists(filename)) { RhinoApp.WriteLine("File not found."); return(Result.Failure); } // Make sure to surround filename string with double-quote characters // in case the path contains spaces. var script = string.Format("_-Open \"{0}\"", filename); RhinoApp.RunScript(script, false); return(Result.Success); }
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); }