public Result Execute(ExternalCommandData data, ref string message, ElementSet elements) { var MainWindow = Rhino.UI.RhinoEtoApp.MainWindow; if (MainWindow.Visible) { var doc = Rhino.RhinoDoc.ActiveDoc; if (doc.Modified) { string docTitle = doc.Name ?? "Untitled"; switch (Eto.Forms.MessageBox.Show("Save changes to " + docTitle + "?", Rhino.RhinoApp.Name, Eto.Forms.MessageBoxButtons.YesNoCancel)) { case Eto.Forms.DialogResult.Yes: var docFileName = doc.Path; if (docFileName == null) { using (var dialog = new Eto.Forms.SaveFileDialog()) { dialog.FileName = docTitle; dialog.Filters.Add(new Eto.Forms.FileFilter("Rhino 3D Model", new string[] { "3dm" })); if (dialog.ShowDialog(MainWindow) != Eto.Forms.DialogResult.Ok) { return(Result.Cancelled); } if (Path.HasExtension(dialog.FileName)) { docFileName = dialog.FileName; } else { docFileName = Path.ChangeExtension(dialog.FileName, dialog.CurrentFilter.Extensions[0]); } } } Rhino.RhinoDoc.ActiveDoc.WriteFile(docFileName, new Rhino.FileIO.FileWriteOptions()); break; case Eto.Forms.DialogResult.No: break; case Eto.Forms.DialogResult.Cancel: return(Result.Cancelled); } } // We want to keep Grasshopper visible in this case. //try { MainWindow.WindowState = Eto.Forms.WindowState.Minimized; } //catch (NotImplementedException) { } MainWindow.Visible = false; var newDoc = Rhino.RhinoDoc.Create(null); ResetDocumentUnits(newDoc, data.Application.ActiveUIDocument?.Document); } else { MainWindow.Visible = true; try { MainWindow.WindowState = Eto.Forms.WindowState.Normal; } catch (NotImplementedException) { } ResetDocumentUnits(Rhino.RhinoDoc.ActiveDoc, data.Application.ActiveUIDocument?.Document); } return(Result.Succeeded); }
void Export() { var saveDlg = new Eto.Forms.SaveFileDialog(); saveDlg.Filters.Add(new Eto.Forms.FileFilter("HTML file", new string[] { "html" })); var parent = Rhino.UI.Runtime.PlatformServiceProvider.Service.GetEtoWindow(Grasshopper.Instances.DocumentEditor.Handle); var ghDocPath = OnPingDocument()?.FilePath; if (!string.IsNullOrWhiteSpace(ghDocPath)) { string path = System.IO.Path.GetDirectoryName(ghDocPath); string filename = System.IO.Path.GetFileNameWithoutExtension(ghDocPath); path = System.IO.Path.Combine(path, filename + ".html"); saveDlg.FileName = path; } if (saveDlg.ShowDialog(parent) == Eto.Forms.DialogResult.Ok) { _model.ExportToHtml(saveDlg.FileName, this); } }