/// <summary> /// Get name of an image file. /// </summary> private string GetImageFileName(RunMode mode) { string path; if (mode == RunMode.Interactive) { var dialog = new Eto.Forms.OpenFileDialog(); string[] all = { ".bmp", ".gif", ".jpg", ".jpeg", ".png", ".tif", ".tiff" }; dialog.Filters.Add(new Eto.Forms.FileFilter("All image files", all)); dialog.Filters.Add(new Eto.Forms.FileFilter("Bitmap", ".bmp")); dialog.Filters.Add(new Eto.Forms.FileFilter("GIF", ".gif")); string[] jpeg = { ".jpg", ".jpe", ".jpeg" }; dialog.Filters.Add(new Eto.Forms.FileFilter("JPEG", jpeg)); dialog.Filters.Add(new Eto.Forms.FileFilter("PNG", ".png")); string[] tiff = { ".tif", ".tiff" }; dialog.Filters.Add(new Eto.Forms.FileFilter("TIFF", tiff)); var res = dialog.ShowDialog(RhinoEtoApp.MainWindow); if (res != Eto.Forms.DialogResult.Ok) { return(null); } path = dialog.FileName; } else { var gs = new GetString(); gs.SetCommandPrompt("Name of image file to open"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(null); } path = gs.StringResult(); } if (!string.IsNullOrEmpty(path)) { path = path.Trim(); } if (string.IsNullOrEmpty(path)) { return(null); } if (!File.Exists(path)) { RhinoApp.WriteLine("The specified file cannot be found."); return(null); } return(path); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { #if DEBUG /* * setting the document as a globally accessible member, so that the converters can accsess and add * intermediate geometry to the document for examination */ RhinoV6PipeConverter.DebugUtil.Document = doc; #endif string pipeIdentifier; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the name/url for the pipe"); if (_prevPipeName != null) { getter.SetDefaultString(_prevPipeName); } if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input"); return(getter.CommandResult()); } pipeIdentifier = getter.StringResult(); _prevPipeName = pipeIdentifier; } if (PipeDataUtil.IsValidUrl(pipeIdentifier)) { _pipe = new MyWebPipe(pipeIdentifier); } else { _pipe = new LocalNamedPipe(pipeIdentifier); } _pipe.SetEmitter(this); try { _pipe.Update(); } catch (Exception e) { Rhino.UI.Dialogs.ShowMessage(e.Message, "Error"); } if (_objectsReceived.Count > 0) { DeletePulledObjects(pipeIdentifier, ref doc); } List <Guid> received = new List <Guid>(); foreach (var geom in _objectsReceived) { Guid id = doc.Objects.Add(geom); received.Add(id); } doc.Views.Redraw(); SavePulledObjects(pipeIdentifier, received, ref doc); return(Result.Success); }
protected Result AddOption() { var gs = new GetString(); gs.SetCommandPrompt("String to add"); gs.AcceptNothing(true); switch (gs.Get()) { case GetResult.String: break; case GetResult.Nothing: return(Result.Nothing); default: return(Result.Cancel); } var str = gs.StringResult().Trim(); if (string.IsNullOrEmpty(str)) { return(Result.Nothing); } var plugin = SampleCsUserDataPlugIn.Instance; if (plugin.StringDocumentDataTable.Add(str) < 0) { RhinoApp.WriteLine("Unable to add string."); } return(Result.Success); }
/// <summary> /// Show the mobile construction plane axes. /// </summary> private Result ShowOption(RhinoDoc doc, RhinoObject obj) { if (null == doc || null == obj) { return(Result.Failure); } var data = SampleCsMobilePlaneUserData.DataFromObject(obj); if (null == data) { RhinoApp.WriteLine("No mobile plane attached."); return(Result.Success); } var conduit = new SampleCsMobilePlaneConduit(data.Plane); doc.Views.Redraw(); var gs = new GetString(); gs.SetCommandPrompt("Press <Enter> when done."); gs.Get(); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
//this is where the logic of the command is defined protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string filterStr; using (GetString getter = new GetString()) { getter.AcceptString(true); getter.SetCommandPrompt("Enter the boolean filter statement (in quotes)"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input for tag"); return(getter.CommandResult()); } filterStr = getter.StringResult(); } Stopwatch watch = new Stopwatch(); watch.Start(); List <Guid> filtered = TagUtil.Evaluate(filterStr, ref doc); Debug.WriteLine(watch.ElapsedMilliseconds, "Time"); watch.Stop(); doc.Objects.UnselectAll(); doc.Objects.Select(filtered); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Called by Rhino when the user wants to run the command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var server_host_name = RockfishClientPlugIn.ServerHostName(); for (var i = 0; i < 3; i++) { var gs = new GetString(); gs.SetCommandPrompt("Server host name or IP address"); gs.SetDefaultString(server_host_name); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var name = gs.StringResult().Trim(); if (string.IsNullOrEmpty(name)) { RhinoApp.WriteLine("Server host name or IP address cannot be empty."); continue; } var host_name = RockfishClientPlugIn.LookupHostName(name); if (string.IsNullOrEmpty(host_name)) { RhinoApp.WriteLine("Unable to resolve host name \"{0}\".", host_name); continue; } var found = false; try { using (var channel = new RockfishClientChannel()) { channel.Create(); var echo = channel.Echo("Echo"); found = !string.IsNullOrEmpty(echo); } } catch { // ignored } if (!found) { RhinoApp.WriteLine("Unable to connect to server \"{0}\".", host_name); continue; } RockfishClientPlugIn.ThePlugIn.SetServerHostName(host_name); break; } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string pipeIdentifier; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the name/url for the pipe"); if (_prevPipeName != null) { getter.SetDefaultString(_prevPipeName); } if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input"); return(getter.CommandResult()); } pipeIdentifier = getter.StringResult(); _prevPipeName = pipeIdentifier; } if (PipeDataUtil.IsValidUrl(pipeIdentifier)) { _pipe = new MyWebPipe(pipeIdentifier); } else { _pipe = new LocalNamedPipe(pipeIdentifier); } _pipe.SetEmitter(this); try { _pipe.Update(); } catch (Exception e) { Rhino.UI.Dialogs.ShowMessageBox(e.Message, "Error"); } if (_objectsReceived.Count > 0) { DeletePulledObjects(pipeIdentifier, ref doc); } List <Guid> received = new List <Guid>(); foreach (var geom in _objectsReceived) { Guid id = doc.Objects.Add(geom); received.Add(id); } doc.Views.Redraw(); SavePulledObjects(pipeIdentifier, received, ref doc); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string path; if (mode == RunMode.Interactive) { var savefile = new SaveFileDialog { FileName = "Untitled.3ds", Filter = @"3D Studio (*.3ds)|*.3ds||" }; if (savefile.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } path = savefile.FileName.Trim(); } else { var gs = new GetString(); gs.SetCommandPrompt("Name of 3D Studio file to save"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } path = gs.StringResult().Trim(); } if (string.IsNullOrEmpty(path)) { return(Result.Nothing); } // Ensure the path has a ".3ds" extension if (!Path.HasExtension(path)) { path = Path.ChangeExtension(path, ".3ds"); } // Script Rhino's SaveAs command. Note, in case the path // string contains spaces, we will want to surround the string // with double-quote characters so the command line parser // will deal with it property. var script = $"_-SaveAs \"{path}\" _Enter"; RhinoApp.RunScript(script, false); return(Result.Success); }
public override string EnterString(string prompt = "Enter string", string defaultValue = null) { GetString gS = new GetString(); if (defaultValue != null) { gS.SetDefaultString(defaultValue); } gS.SetCommandPrompt(prompt); if (gS.Get() == GetResult.Cancel) { throw new OperationCanceledException("Operation cancelled by user"); } return(gS.StringResult()); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var conduit = new SampleCsDrawRightAlignedTextConduit(); conduit.Enabled = true; doc.Views.Redraw(); var gs = new GetString(); gs.SetCommandPrompt("Press <Enter> to continue"); gs.AcceptNothing(true); gs.Get(); conduit.Enabled = false; doc.Views.Redraw(); return(Result.Success); }
public static Result SetActiveView(RhinoDoc doc) { // view and view names var active_view_name = doc.Views.ActiveView.ActiveViewport.Name; var non_active_views = doc.Views .Where(v => v.ActiveViewport.Name != active_view_name) .ToDictionary(v => v.ActiveViewport.Name, v => v); // get name of view to set active var gs = new GetString(); gs.SetCommandPrompt("Name of view to set active"); gs.AcceptNothing(true); gs.SetDefaultString(active_view_name); foreach (var view_name in non_active_views.Keys) { gs.AddOption(view_name); } var result = gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var selected_view_name = result == GetResult.Option ? gs.Option().EnglishName : gs.StringResult(); if (selected_view_name != active_view_name) { if (non_active_views.ContainsKey(selected_view_name)) { doc.Views.ActiveView = non_active_views[selected_view_name]; } else { RhinoApp.WriteLine("\"{0}\" is not a view name", selected_view_name); } } return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string filename; if (mode == RunMode.Interactive) { var savefile = new SaveFileDialog { FileName = "Untitled.txt", Filter = @"Text files (*.txt)|*.txt|All files (*.*)|*.*" }; if (savefile.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } filename = savefile.FileName.Trim(); } else { var gs = new GetString(); gs.SetCommandPrompt("Name of text file to save"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } filename = gs.StringResult().Trim(); } if (string.IsNullOrEmpty(filename)) { return(Result.Nothing); } // TODO: do something with 'filename' RhinoApp.WriteLine(filename); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <RhinoObject> objs = new List <RhinoObject>(); using (GetObject getter = new GetObject()) { getter.EnablePreSelect(true, false); getter.SetCommandPrompt("Select all the objects you want to tag"); getter.AcceptColor(false); getter.AcceptString(false); getter.GroupSelect = true; getter.GetMultiple(1, 0); if (getter.CommandResult() != Result.Success) { return(getter.CommandResult()); } for (int i = 0; i < getter.ObjectCount; i++) { objs.Add(getter.Object(i).Object()); } } string tagName; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the tag"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input for tag"); return(getter.CommandResult()); } tagName = getter.StringResult(); } TagUtil.AddTag(objs, tagName, true); doc.Modified = true; doc.Objects.UnselectAll(); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { if (!serverManager.IsRunning) { RhinoApp.WriteLine("Server is not running"); return(Result.Cancel); } GetString getString = new GetString(); getString.SetCommandPrompt("Send the message"); GetResult result = getString.Get(); if (getString.CommandResult() != Result.Success) { return(getString.CommandResult()); } serverManager.Broadcast(getString.StringResult()); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select hatches to replace", false, ObjectType.Hatch, out obj_refs); if (rc != Result.Success || obj_refs == null) { return(rc); } var gs = new GetString(); gs.SetCommandPrompt("Name of replacement hatch pattern"); gs.AcceptNothing(false); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var hatch_name = gs.StringResult(); var pattern_index = doc.HatchPatterns.Find(hatch_name, true); if (pattern_index < 0) { RhinoApp.WriteLine("The hatch pattern \"{0}\" not found in the document.", hatch_name); return(Result.Nothing); } foreach (var obj_ref in obj_refs) { var hatch_object = obj_ref.Object() as HatchObject; if (hatch_object.HatchGeometry.PatternIndex != pattern_index) { hatch_object.HatchGeometry.PatternIndex = pattern_index; hatch_object.CommitChanges(); } } doc.Views.Redraw(); return(Result.Success); }
//this is where the logic of the command is defined protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <RhinoObject> objs = new List <RhinoObject>(); using (GetObject getter = new GetObject()) { getter.EnablePreSelect(true, false); getter.SetCommandPrompt("Select the objects whose tags you need to delete"); getter.GroupSelect = true; getter.GetMultiple(1, 0); if (getter.CommandResult() != Result.Success) { return(getter.CommandResult()); } for (int i = 0; i < getter.ObjectCount; i++) { objs.Add(getter.Object(i).Object()); } } string tagName; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the tag"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input for tag"); return(getter.CommandResult()); } tagName = getter.StringResult(); //Debug.WriteLine(tagName, "Tag"); } doc.Objects.UnselectAll(); TagUtil.DeleteTag(ref objs, tagName, true); //marking the document as dirty - i.e. modified so that it prompts the user to save when closed without saving doc.Modified = true; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); go.SetCommandPrompt("Select curves for direction display"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } doc.Objects.UnselectAll(); SampleCsCurveDirectionConduit conduit = new SampleCsCurveDirectionConduit(go); conduit.Enabled = true; doc.Views.Redraw(); GetString gs = new GetString(); gs.SetCommandPrompt("Press <Enter> to continue"); gs.AcceptNothing(true); gs.Get(); conduit.Enabled = false; if (go.ObjectsWerePreselected) { for (int i = 0; i < go.ObjectCount; i++) { go.Object(i).Object().Select(true); } } doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Prompts the user for the name of a file to save /// </summary> private Result GetSaveFileName(string prompt, ref string fileName) { Result rc = Result.Cancel; if (string.IsNullOrEmpty(prompt)) { prompt = "File name"; } GetString gs = new GetString(); gs.SetCommandPrompt(prompt); gs.AddOption(new Rhino.UI.LocalizeStringPair("Browse", "Browse")); if (!string.IsNullOrEmpty(fileName)) { gs.SetDefaultString(fileName); } GetResult res = gs.Get(); if (res == GetResult.String) { fileName = gs.StringResult(); rc = Result.Success; } else if (res == GetResult.Option) { SaveFileDialog fileDialog = new SaveFileDialog(); fileDialog.Filter = "Text Documents|*.txt"; fileDialog.Title = "Save As"; if (fileDialog.ShowDialog() == DialogResult.OK) { fileName = fileDialog.FileName; rc = Result.Success; } } return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (Panel_TagManager.CurrentFilter == null) { #if RhinoV5 Rhino.UI.Dialogs.ShowMessageBox("Current filter is not set.", "Cannot Save Filter"); #elif RhinoV6 Rhino.UI.Dialogs.ShowMessage("Current filter is not set.", "Cannot Save Filter"); #endif return(Result.Nothing); } string filterName; using (GetString getter = new GetString()) { getter.AcceptString(true); getter.SetCommandPrompt("Enter a name for the current filter"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input"); return(getter.CommandResult()); } filterName = getter.StringResult(); } string filterText = Panel_TagManager.CurrentFilter.ToString(); if (Panel_TagManager.SavedFilters.ContainsKey(filterName)) { Panel_TagManager.SavedFilters[filterName] = filterText; } else { Panel_TagManager.SavedFilters.Add(filterName, filterText); } TagUtil.AddSavedFiltersToDocument(doc); doc.Modified = true; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Name of block to import var gs = new GetString(); gs.SetCommandPrompt("Name of block to import"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var idef_name = gs.StringResult().Trim(); if (string.IsNullOrEmpty(idef_name)) { return(Result.Nothing); } if (null != doc.InstanceDefinitions.Find(idef_name, true)) { RhinoApp.WriteLine("Block already exists."); return(Result.Nothing); } // Name of file to import block from gs.SetCommandPrompt("Name of file to import block from"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var idef_filename = gs.StringResult().Trim(); if (string.IsNullOrEmpty(idef_filename)) { return(Result.Nothing); } if (!File.Exists(idef_filename)) { RhinoApp.WriteLine("File not found."); return(Result.Failure); } using (var file = File3dm.Read(idef_filename)) { // Find the instance defintion named "idef_name" var idef_index = -1; for (var i = 0; i < file.InstanceDefinitions.Count; i++) { if (string.Equals(idef_name, file.InstanceDefinitions[i].Name, StringComparison.OrdinalIgnoreCase)) { idef_index = i; break; } } if (idef_index < 0) { RhinoApp.WriteLine("Block not found in file."); return(Result.Failure); } // Find and duplicate all of the instance definition geometry // Note, this sample only imports the geoemtry, not the geometry's // attributes (layer, material, etc.). var idef = file.InstanceDefinitions[idef_index]; var iref_objects = idef.GetObjectIds(); var geometry = new List <GeometryBase>(iref_objects.Length); foreach (var obj_id in iref_objects) { foreach (var obj in file.Objects) { if (obj_id == obj.Attributes.ObjectId) { geometry.Add(obj.Geometry.Duplicate()); } } } if (geometry.Count == 0) { return(Result.Failure); } // Add (e.g. import) the instance defintion idef_index = doc.InstanceDefinitions.Add(idef_name, idef.Description, Point3d.Origin, geometry); if (idef_index < 0) { RhinoApp.WriteLine("Unable to import block from file."); return(Result.Failure); } } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select objects to export"); go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } string path; if (mode == RunMode.Interactive) { var savefile = new SaveFileDialog { FileName = @"Untitled.dxf", Filter = @"AutoCAD Drawing Exchange (*.dxf)|*.dxf||" }; if (savefile.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } path = savefile.FileName.Trim(); } else { var gs = new GetString(); gs.SetCommandPrompt("Name of AutoCAD Drawing Exchange file to save"); gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } path = gs.StringResult().Trim(); } if (string.IsNullOrEmpty(path)) { return(Result.Nothing); } // Ensure the path has a ".dxf" extension if (!Path.HasExtension(path)) { path = Path.ChangeExtension(path, ".dxf"); } // Script Rhino's Export command. Note, in case the path // string contains spaces, we will want to surround the string // with double-quote characters so the command line parser // will deal with it property. var script = $"_-Export \"{path}\" _Enter"; RhinoApp.RunScript(script, false); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { (PlugIn as Plugin)?.InitialiseCSycles(); var numDevices = Device.Count; var endS = numDevices != 1 ? "s" : ""; RhinoApp.WriteLine("Possible devices to select from:"); HashSet <int> allowedIds = new HashSet <int>(); foreach (var dev in Device.Devices) { if (dev.IsCpu || dev.IsCuda) { RhinoApp.WriteLine($" Device {dev.Id}: {dev.Name} ({dev.Description})"); allowedIds.Add((int)dev.Id); } } if (allowedIds.Count < 2) { RhinoApp.WriteLine("Not enough devices to create a multi-device from"); return(Result.Nothing); } var getString = new GetString(); getString.SetCommandPrompt($"Enter comma-delimited string"); var getRc = getString.Get(); if (getString.CommandResult() != Result.Success) { return(getString.CommandResult()); } if (getRc == GetResult.String) { var res = getString.StringResult(); var set = Device.IdSetFromString(res); set.IntersectWith(allowedIds); List <int> idList = new List <int>(); foreach (var s in set) { idList.Add(s); } idList.Sort(); if (idList.Count < 2) { RhinoApp.WriteLine("A multi-device needs to have at least 2 devices"); return(Result.Failure); } List <Device> devList = new List <Device>(); foreach (var id in idList) { devList.Add(Device.GetDevice(id)); } var multiDevice = Device.CreateMultiDevice(devList); RhinoApp.WriteLine($" Device {multiDevice.Id}: {multiDevice.Name} ({multiDevice.Description}), {multiDevice.SubdeviceCount} devices"); foreach (var sd in multiDevice.SubdevicesIndex) { RhinoApp.WriteLine($" {sd.Item1} {sd.Item2}"); } return(Result.Success); } return(Result.Nothing); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { int portNumber = 8181; string hostnameString = "127.0.0.1"; bool activate = serverManager.IsRunning; GetString gp = new GetString(); gp.SetCommandPrompt("Websocket Server"); gp.SetDefaultString(hostnameString); Rhino.Input.Custom.OptionInteger portNumberOption = new Rhino.Input.Custom.OptionInteger(portNumber); OptionToggle activeOption = new OptionToggle(activate, "Off", "On"); gp.AddOptionToggle("Activate", ref activeOption); gp.AddOptionInteger("Port", ref portNumberOption); while (true) { GetResult get_rc = gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } if (get_rc == GetResult.String) { hostnameString = gp.StringResult(); } else if (get_rc == GetResult.Option) { continue; } break; } portNumber = portNumberOption.CurrentValue; activate = activeOption.CurrentValue; if (activate) { serverManager.Setup(hostnameString, portNumber); serverManager.Start(socket => { socket.OnOpen = () => RhinoApp.WriteLine("Open"); socket.OnClose = () => RhinoApp.WriteLine("Close!"); socket.OnMessage = (message) => { try { var obj = JObject.Parse(message); if (obj.ContainsKey("action") && obj.GetValue("action").ToString() == "broadcast") { serverManager.Broadcast(obj.GetValue("data").ToString(), socket); return; } } catch (JsonReaderException exception) { } //socket.Send(message); }; }); } else { RhinoApp.WriteLine("Closing server"); serverManager.Dispose(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string family = ""; // Get family from user var getFamily = new GetString(); getFamily.SetCommandPrompt("Enter Family name"); getFamily.Get(); family = getFamily.StringResult(); if (string.IsNullOrEmpty(family.Trim())) { return(Result.Nothing); } // get point selection in and create blocks from each group var getObj = new GetObject(); getObj.SetCommandPrompt("Select points in order"); getObj.SubObjectSelect = false; getObj.GeometryFilter = ObjectType.Point; getObj.OneByOnePostSelect = true; List <RhinoObject> selectedObjects = new List <RhinoObject>(); for (; ;) { GetResult res = getObj.GetMultiple(3, 0); if (res == GetResult.Object) { //make block from points and assign adaptive component schema var blockName = $"AdaptiveComponent-{Guid.NewGuid()}"; // Gather all of the selected objects var geometry = new List <Rhino.Geometry.GeometryBase>(); var attributes = new List <ObjectAttributes>(); for (int i = 0; i < getObj.ObjectCount; i++) { var rhinoObject = getObj.Object(i).Object(); if (rhinoObject != null) { geometry.Add(rhinoObject.Geometry); attributes.Add(rhinoObject.Attributes); } } var basePoint = geometry.First() as Rhino.Geometry.Point; // Use first selected point as basepoint // Gather all of the selected objects and make definition int definitionIndex = doc.InstanceDefinitions.Add(blockName, string.Empty, basePoint.Location, geometry, attributes); if (definitionIndex < 0) { RhinoApp.WriteLine("Unable to create block definition ", blockName); return(Result.Failure); } // add the objects to a block instance var transform = Rhino.Geometry.Transform.Translation(basePoint.Location - doc.ModelBasepoint); Guid instanceId = doc.Objects.AddInstanceObject(definitionIndex, transform); if (instanceId == Guid.Empty) { RhinoApp.WriteLine("Unable to create block instance ", blockName); return(Result.Failure); } var instance = doc.Objects.FindId(instanceId) as InstanceObject; // attach user string to block instance ApplyAdaptiveComponent(instance, family, family, doc); // clear everything for next selection selectedObjects.Clear(); getObj.ClearObjects(); continue; } else if (res == GetResult.Cancel) { break; } break; } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetOption go = new GetOption(); go.SetCommandPrompt("Set Faro scan settings"); Rhino.Input.Custom.GetString gs = new GetString(); gs.SetCommandPrompt("Set Faro IP address."); gs.SetDefaultString("127.0.0.1"); gs.AddOption("Scanner IP"); gs.Get(); string val = gs.StringResult(); Rhino.RhinoApp.WriteLine("IP: " + val); // set up the options Rhino.Input.Custom.OptionInteger intOption = new Rhino.Input.Custom.OptionInteger(1, 1, 99); Rhino.Input.Custom.OptionDouble dblOption = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9); Rhino.Input.Custom.OptionToggle boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On"); string[] resolutionValues = new string[] { "Full", "Half", "Quarter", "Eighth", "Sixsteenth" }; string[] measurementValues = new string[] { "Low", "Medium", "High" }; string[] noiseValues = new string[] { "Low", "Medium", "High" }; go.AddOptionInteger("Integer", ref intOption); go.AddOptionDouble("Double", ref dblOption); go.AddOptionToggle("Boolean", ref boolOption); int resolutionIndex = 2; int measurementIndex = 1; int noiseIndex = 1; int resolutionList = go.AddOptionList("Resolution", resolutionValues, resolutionIndex); int measurementList = go.AddOptionList("MeasurementRate", measurementValues, measurementIndex); int noiseList = go.AddOptionList("NoiseCompression", noiseValues, noiseIndex); while (true) { // perform the get operation. This will prompt the user to input a point, but also // allow for command line options defined above Rhino.Input.GetResult get_rc = go.Get(); Rhino.RhinoApp.WriteLine(get_rc.ToString()); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } if (get_rc == Rhino.Input.GetResult.Nothing) { //doc.Objects.AddPoint(go.Point()); doc.Views.Redraw(); Rhino.RhinoApp.WriteLine("Command line option values are"); Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Measurement rate = {0}", measurementValues[measurementIndex]); Rhino.RhinoApp.WriteLine(" Resolution = {0}", resolutionValues[resolutionIndex]); } else if (get_rc == Rhino.Input.GetResult.Option) { if (go.OptionIndex() == resolutionList) { resolutionIndex = go.Option().CurrentListOptionIndex; } else if (go.OptionIndex() == measurementList) { measurementIndex = go.Option().CurrentListOptionIndex; } continue; } break; } return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string pipeIdentifier; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the name/url for the pipe"); if (_prevPipeName != null) { getter.SetDefaultString(_prevPipeName); } if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input"); return(getter.CommandResult()); } pipeIdentifier = getter.StringResult(); _prevPipeName = pipeIdentifier; } if (_pipe != null) { _pipe.ClosePipe(); _pipe = null; } if (PipeDataUtil.IsValidUrl(pipeIdentifier)) { _pipe = new MyWebPipe(pipeIdentifier); } else { _pipe = new LocalNamedPipe(pipeIdentifier); } _pipe.SetCollector(this); _objectsToSend = new List <RhinoObject>(); using (GetObject getter = new GetObject()) { getter.EnablePreSelect(true, false); getter.SetCommandPrompt("Select all the objects to be pushed through the pipe"); getter.GroupSelect = true; getter.GetMultiple(1, 0); if (getter.CommandResult() != Result.Success) { return(getter.CommandResult()); } for (int i = 0; i < getter.ObjectCount; i++) { _objectsToSend.Add(getter.Object(i).Object()); } } try { _pipe.Update(); } catch (Exception e) { Rhino.UI.Dialogs.ShowMessageBox(e.Message, "Error"); } doc.Views.Redraw(); return(Result.Success); }