protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Cook up an unused layer name string unused_name = doc.Layers.GetUnusedLayerName(false); // Prompt the user to enter a layer name Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString(); gs.SetCommandPrompt("Name of layer to add"); gs.SetDefaultString(unused_name); gs.AcceptNothing(true); gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) { return(gs.CommandResult()); } // Was a layer named entered? string layer_name = gs.StringResult().Trim(); if (string.IsNullOrEmpty(layer_name)) { Rhino.RhinoApp.WriteLine("Layer name cannot be blank."); return(Rhino.Commands.Result.Cancel); } // Is the layer name valid? if (!Rhino.DocObjects.Layer.IsValidName(layer_name)) { Rhino.RhinoApp.WriteLine(layer_name + " is not a valid layer name."); return(Rhino.Commands.Result.Cancel); } // Does a layer with the same name already exist? int layer_index = doc.Layers.Find(layer_name, true); if (layer_index >= 0) { Rhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", layer_name); return(Rhino.Commands.Result.Cancel); } // Add a new layer to the document layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.IndianRed); if (layer_index < 0) { Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", layer_name); return(Rhino.Commands.Result.Failure); } return(Rhino.Commands.Result.Success); return(Result.Success); }
public static Rhino.Commands.Result AddLayer(Rhino.RhinoDoc doc) { // Cook up an unused layer name string unused_name = doc.Layers.GetUnusedLayerName(false); // Prompt the user to enter a layer name Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString(); gs.SetCommandPrompt("Name of layer to add"); gs.SetDefaultString(unused_name); gs.AcceptNothing(true); gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) return gs.CommandResult(); // Was a layer named entered? string layer_name = gs.StringResult().Trim(); if (string.IsNullOrEmpty(layer_name)) { Rhino.RhinoApp.WriteLine("Layer name cannot be blank."); return Rhino.Commands.Result.Cancel; } // Is the layer name valid? if (!Rhino.DocObjects.Layer.IsValidName(layer_name)) { Rhino.RhinoApp.WriteLine(layer_name + " is not a valid layer name."); return Rhino.Commands.Result.Cancel; } // Does a layer with the same name already exist? int layer_index = doc.Layers.Find(layer_name, true); if (layer_index >= 0) { Rhino.RhinoApp.WriteLine("A layer with the name {0} already exists.", layer_name); return Rhino.Commands.Result.Cancel; } // Add a new layer to the document layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black); if (layer_index < 0) { Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", layer_name); return Rhino.Commands.Result.Failure; } return Rhino.Commands.Result.Success; }
protected override GH_GetterResult Prompt_Singular(ref IGH_Goo value) { var bPlane = Plane.WorldXY; MainMenu: var go = new Rhino.Input.Custom.GetString(); go.SetCommandPrompt("Set default robot."); go.AcceptNothing(true); go.AddOption("Default"); go.AddOption("IRB_120"); go.AddOption("IRB_6620"); go.AddOption("SetBasePlane", $"O({bPlane.OriginX.ToString("0.00")},{bPlane.OriginY.ToString("0.00")},{bPlane.OriginZ.ToString("0.00")}) " + $"Z({bPlane.ZAxis.X.ToString("0.00")},{bPlane.ZAxis.Y.ToString("0.00")}, {bPlane.ZAxis.Z.ToString("0.00")})"); switch (go.Get()) { case Rhino.Input.GetResult.Option: if (go.Option().EnglishName == "Default") { var rob = Abb6DOFRobot.Default; rob.ChangeBasePlane(bPlane); value = rob; } if (go.Option().EnglishName == "IRB_120") { var rob = Abb6DOFRobot.IRB120; rob.ChangeBasePlane(bPlane); value = rob; } if (go.Option().EnglishName == "IRB_6620") { var rob = Abb6DOFRobot.IRB6620; rob.ChangeBasePlane(bPlane); value = rob; } if (go.Option().EnglishName == "SetBasePlane") { GetBPlane(out bPlane); goto MainMenu; } return(GH_GetterResult.success); case Rhino.Input.GetResult.Nothing: return(GH_GetterResult.cancel); default: return(GH_GetterResult.cancel); } }
public static Rhino.Commands.Result AddChildLayer(Rhino.RhinoDoc doc) { // Get an existing layer string default_name = doc.Layers.CurrentLayer.Name; // Prompt the user to enter a layer name Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString(); gs.SetCommandPrompt("Name of existing layer"); gs.SetDefaultString(default_name); gs.AcceptNothing(true); gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) { return(gs.CommandResult()); } // Was a layer named entered? string layer_name = gs.StringResult().Trim(); int index = doc.Layers.Find(layer_name, true); if (index < 0) { return(Rhino.Commands.Result.Cancel); } Rhino.DocObjects.Layer parent_layer = doc.Layers[index]; // Create a child layer string child_name = parent_layer.Name + "_child"; Rhino.DocObjects.Layer childlayer = new Rhino.DocObjects.Layer(); childlayer.ParentLayerId = parent_layer.Id; childlayer.Name = child_name; childlayer.Color = System.Drawing.Color.Red; index = doc.Layers.Add(childlayer); if (index < 0) { Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", child_name); return(Rhino.Commands.Result.Failure); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result AddChildLayer(Rhino.RhinoDoc doc) { // Get an existing layer string default_name = doc.Layers.CurrentLayer.Name; // Prompt the user to enter a layer name Rhino.Input.Custom.GetString gs = new Rhino.Input.Custom.GetString(); gs.SetCommandPrompt("Name of existing layer"); gs.SetDefaultString(default_name); gs.AcceptNothing(true); gs.Get(); if (gs.CommandResult() != Rhino.Commands.Result.Success) return gs.CommandResult(); // Was a layer named entered? string layer_name = gs.StringResult().Trim(); int index = doc.Layers.Find(layer_name, true); if (index<0) return Rhino.Commands.Result.Cancel; Rhino.DocObjects.Layer parent_layer = doc.Layers[index]; // Create a child layer string child_name = parent_layer.Name + "_child"; Rhino.DocObjects.Layer childlayer = new Rhino.DocObjects.Layer(); childlayer.ParentLayerId = parent_layer.Id; childlayer.Name = child_name; childlayer.Color = System.Drawing.Color.Red; index = doc.Layers.Add(childlayer); if (index < 0) { Rhino.RhinoApp.WriteLine("Unable to add {0} layer.", child_name); return Rhino.Commands.Result.Failure; } return Rhino.Commands.Result.Success; }
/// <summary> /// Called when the command is in scripted mode /// </summary> /// <param name="model"></param> /// <returns></returns> static Result RunScript(TextViewModel model) { var height = new Rhino.Input.Custom.OptionDouble(model.textHeight); var bold = new Rhino.Input.Custom.OptionToggle(model.bold, Localization.LocalizeCommandOptionValue("No", 396), Localization.LocalizeCommandOptionValue("Yes", 397)); var italic = new Rhino.Input.Custom.OptionToggle(model.italic, Localization.LocalizeCommandOptionValue("No", 398), Localization.LocalizeCommandOptionValue("Yes", 399)); var mask = new Rhino.Input.Custom.OptionToggle(model.maskEnabled, Localization.LocalizeCommandOptionValue("No", 400), Localization.LocalizeCommandOptionValue("Yes", 401)); var masksource = new Rhino.Input.Custom.OptionToggle(model.maskUsesViewportColor, Localization.LocalizeCommandOptionValue("No", 402), Localization.LocalizeCommandOptionValue("Yes", 403)); var maskcolor = new Rhino.Input.Custom.OptionColor(model.maskColor); var maskborder = new Rhino.Input.Custom.OptionDouble(model.maskOffset, true, 0); string facename = model.Font.FaceName; string newtext = ""; var go = new Rhino.Input.Custom.GetString(); var get_rc = Rhino.Input.GetResult.Cancel; var rc = Rhino.Commands.Result.Cancel; while (get_rc != Rhino.Input.GetResult.Nothing && get_rc != Rhino.Input.GetResult.String) { go.ClearCommandOptions(); go.AcceptNothing(true); go.SetCommandPrompt(LOC.STR("Text string")); int faceopt = go.AddOption(LOC.CON("Font")); go.AddOptionDouble(LOC.CON("Height"), ref height, LOC.STR("Text height")); go.AddOptionToggle(LOC.CON("Italic"), ref italic); go.AddOptionToggle(LOC.CON("Mask"), ref mask); go.AddOptionToggle(LOC.CON("UseBackgroundColor"), ref masksource); go.AddOptionColor(LOC.CON("MaskColor"), ref maskcolor); go.AddOptionDouble(LOC.CON("MaskMargin"), ref maskborder); get_rc = go.Get(); switch (get_rc) { case Rhino.Input.GetResult.Cancel: return Rhino.Commands.Result.Cancel; case Rhino.Input.GetResult.String: newtext = go.StringResult(); break; case Rhino.Input.GetResult.Option: if( go.OptionIndex() == faceopt ) { string oldname = facename; rc = Rhino.Input.RhinoGet.GetString(LOC.STR("Font name"), true, ref facename); if( rc!=Rhino.Commands.Result.Success) return rc; if (string.IsNullOrWhiteSpace(facename)) facename = oldname; } break; } } if (string.IsNullOrWhiteSpace(newtext)) return Rhino.Commands.Result.Cancel; // update default settings model.text = newtext; int fontindex = model.Doc.Fonts.FindOrCreate(facename, bold.CurrentValue, italic.CurrentValue); model.fontIndex = fontindex; model.textHeight = height.CurrentValue; model.maskEnabled = mask.CurrentValue; model.maskUsesViewportColor = masksource.CurrentValue; model.maskColor = maskcolor.CurrentValue; model.maskOffset = maskborder.CurrentValue; return Result.Success; }