public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements) { if (Instances.ActiveCanvas?.Document is GH_Document definition) { using (var modal = new Rhinoceros.ModalScope()) { if (GH_Document.EnableSolutions) { definition.NewSolution(true); } else { GH_Document.EnableSolutions = true; try { definition.NewSolution(false); } finally { GH_Document.EnableSolutions = false; } } do { var result = modal.Run(false, false); if (result == Result.Failed) { return(result); } } while (definition.ScheduleDelay >= GH_Document.ScheduleRecursive); if (definition.SolutionState == GH_ProcessStep.PostProcess) { return(Result.Succeeded); } } } return(Result.Failed); }
public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements) { using (var modal = new Rhinoceros.ModalScope()) { return(modal.Run(true)); } }
public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements) { using (var modal = new Rhinoceros.ModalScope()) { if (!Rhino.RhinoApp.RunScript("!_-Grasshopper _W _S ENTER", false)) { return(Result.Failed); } return(modal.Run(false)); } }
public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements) { using (var modal = new Rhinoceros.ModalScope()) { GH.Guest.Script.ShowEditor(); if (!GH.Guest.Script.IsEditorLoaded()) { return(Result.Failed); } return(modal.Run(false)); } }
public static MenuBarManager.CallbackStatus Execute ( string filePath, ref string message ) { var result = MenuBarManager.CallbackStatus.Error; if ((result = ReadFromFile(filePath, out var definition)) == MenuBarManager.CallbackStatus.Continue) { using (definition) { bool enableSolutions = GH_Document.EnableSolutions; try { GH_Document.EnableSolutions = true; definition.Enabled = true; definition.ExpireSolution(); var inputs = GetInputParams(definition); result = PromptForInputs(inputs, out var values); if (result != MenuBarManager.CallbackStatus.Continue) { return(result); } foreach (var value in values) { value.Key.AddVolatileDataList(new global::Grasshopper.Kernel.Data.GH_Path(0), value.Value); } using (var modal = new Rhinoceros.ModalScope()) { definition.NewSolution(false, GH_SolutionMode.Silent); do { if (modal.Run(false, false) == MenuBarManager.CallbackStatus.Error) { return(MenuBarManager.CallbackStatus.Error); } } while (definition.ScheduleDelay >= GH_Document.ScheduleRecursive); } if (definition.SolutionState == GH_ProcessStep.Aborted) { message = $"Solution aborted by user after ~{ definition.SolutionSpan.TotalSeconds} seconds"; return(MenuBarManager.CallbackStatus.Cancel); } else { var ss = definition.Objects; Logger.Info($"Definition SolutionState:{definition.SolutionState}"); foreach (var item in ss) { Console.WriteLine(item.GetType()); } } } catch (Exception e) { message = e.Message; return(MenuBarManager.CallbackStatus.Error); } finally { GH_Document.EnableSolutions = enableSolutions; } } } return(result); }
public static Result Execute ( UIApplication app, View view, IDictionary <string, string> JournalData, string filePath, ref string message ) { var result = Result.Failed; if ((result = ReadFromFile(filePath, out var definition)) == Result.Succeeded) { using (definition) { bool enableSolutions = GH_Document.EnableSolutions; var currentCulture = Thread.CurrentThread.CurrentCulture; try { using (var transGroup = new TransactionGroup(app.ActiveUIDocument.Document)) { transGroup.Start(Path.GetFileNameWithoutExtension(definition.Properties.ProjectFileName)); GH_Document.EnableSolutions = true; definition.Enabled = true; definition.ExpireSolution(); var inputs = GetInputParams(definition); result = PromptForInputs(app.ActiveUIDocument, inputs, out var values); if (result != Result.Succeeded) { return(result); } // Update input volatile data values foreach (var value in values) { value.Key.AddVolatileDataList(new Grasshopper.Kernel.Data.GH_Path(0), value.Value); } Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; using (var modal = new Rhinoceros.ModalScope()) { definition.NewSolution(false, GH_SolutionMode.Silent); do { if (modal.Run(false, false) == Result.Failed) { return(Result.Failed); } } while (definition.ScheduleDelay >= GH_Document.ScheduleRecursive); } Thread.CurrentThread.CurrentCulture = currentCulture; if (definition.SolutionState == GH_ProcessStep.Aborted) { message = $"Solution aborted by user after ~{ definition.SolutionSpan.TotalSeconds} seconds"; return(Result.Cancelled); } transGroup.Assimilate(); } } catch (Exception e) { message = e.Message; return(Result.Failed); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; GH_Document.EnableSolutions = enableSolutions; } } } return(result); }
public override Result Execute(ExternalCommandData data, ref string message, Autodesk.Revit.DB.ElementSet elements) { var result = Result.Failed; string rhinoTab = Addin.RhinoVersionInfo?.ProductName ?? "Rhinoceros"; if (RhinoCommand.Availability.Available) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { return(Rhinoceros.RunCommandAbout()); } using (var modal = new Rhinoceros.ModalScope()) result = modal.Run(false, true); // If no windows are visible we show the Ribbon tab if (result == Result.Cancelled) { result = data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed; } return(result); } result = Addin.CheckSetup(); if (result != Result.Succeeded) { return(result); } result = Revit.OnStartup(Revit.ApplicationUI); if (RhinoCommand.Availability.Available = result == Result.Succeeded) { // Update Rhino button Tooltip Button.ToolTip = $"Restores previously visible Rhino windows on top of Revit window"; Button.LongDescription = $"Use CTRL key to open a Rhino model"; // Register UI on Revit data.Application.CreateRibbonTab(rhinoTab); var RhinocerosPanel = data.Application.CreateRibbonPanel(rhinoTab, "Rhinoceros"); HelpCommand.CreateUI(RhinocerosPanel); RhinocerosPanel.AddSeparator(); CommandRhino.CreateUI(RhinocerosPanel); CommandPython.CreateUI(RhinocerosPanel); var GrasshopperPanel = data.Application.CreateRibbonPanel(rhinoTab, "Grasshopper"); CommandGrasshopper.CreateUI(GrasshopperPanel); CommandGrasshopperPlayer.CreateUI(GrasshopperPanel); CommandGrasshopperPreview.CreateUI(GrasshopperPanel); CommandGrasshopperRecompute.CreateUI(GrasshopperPanel); CommandGrasshopperBake.CreateUI(GrasshopperPanel); var SamplesPanel = data.Application.CreateRibbonPanel(rhinoTab, "Samples"); Samples.Sample1.CreateUI(SamplesPanel); Samples.Sample4.CreateUI(SamplesPanel); Samples.Sample6.CreateUI(SamplesPanel); Samples.Sample8.CreateUI(SamplesPanel); } if (result == Result.Succeeded) { // Activate Rhinoceros Tab result = data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed; } else { // No more loads in this session Button.Enabled = false; Button.ToolTip = "Failed to load."; } return(result); }