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) { const ObjectType filter = ObjectType.AnyObject; ObjRef objref; var rc = RhinoGet.GetOneObject("Select object", false, filter, out objref); if (rc != Result.Success || null == objref) { return(rc); } var obj = objref.Object(); if (null == obj) { return(Result.Failure); } var ud = obj.Attributes.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null != ud) { var gs = new GetString(); gs.SetCommandPrompt("Modify object notes"); gs.GetLiteralString(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } ud.Notes = gs.StringResult(); } return(Result.Success); }
public static Result ReplaceHatchPattern(RhinoDoc doc) { 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; }
/// <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 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType filter = ObjectType.AnyObject; ObjRef objref; var rc = RhinoGet.GetOneObject("Select object", false, filter, out objref); if (rc != Result.Success || null == objref) { return(rc); } var obj = objref.Object(); if (null == obj) { return(Result.Failure); } var userdata = obj.Attributes.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null == userdata) { RhinoApp.WriteLine("SampleCsUserData not found."); return(Result.Nothing); } var gs = new GetString(); gs.SetCommandPrompt("Modify object notes"); gs.GetLiteralString(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } // To support undo, make a copy of the attributes // instead of modifying the attributes directly. var new_attributes = obj.Attributes.Duplicate(); userdata = new_attributes.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null == userdata) { return(Result.Failure); } userdata.Notes = gs.StringResult(); doc.Objects.ModifyAttributes(obj, new_attributes, true); 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); }
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); }
/// <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); }
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) { var layer_index = doc.Layers.FindByFullPath("Default", true); if (layer_index < 0) { RhinoApp.WriteLine("Default layer not found."); return(Result.Nothing); } var layer = doc.Layers[layer_index]; if (null == layer) { return(Result.Failure); } var ud = layer.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null == ud) { var gs = new GetString(); gs.SetCommandPrompt("Layer notes"); gs.GetLiteralString(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } ud = new SampleCsUserDataObject { Notes = gs.StringResult() }; layer.UserData.Add(ud); } else { RhinoApp.WriteLine("{0} = {1}", ud.Description, ud.Notes); } 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 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(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); }
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); }
//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) { 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(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) { 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(RhinoDoc doc, RunMode mode) { // Allow for picking of either a surface or a brep face var go = new GetObject(); go.SetCommandPrompt("Select surface to attach data"); go.GeometryFilter = ObjectType.Surface; go.SubObjectSelect = true; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } // Get first object reference. Note, this reference represents the picked // surface or face, not the top level brep. var obj_ref = go.Object(0); // Get brep face that was picked var face = obj_ref.Face(); if (null == face) { return(Result.Failure); } // Since the object reference only represents the picked surface or face, // we need to get the owning brep from the Rhino object. var brep_object = obj_ref.Object() as BrepObject; if (null == brep_object) { return(Result.Failure); } // Get the brep object's brep geometry var brep = brep_object.BrepGeometry; if (null == brep) { return(Result.Failure); } // Get the brep face's underlying surface var surface_index = face.SurfaceIndex; var srf = brep.Surfaces[surface_index]; if (null == srf) { return(Result.Failure); } // Query the surface for user data var ud = srf.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject; if (null != ud) { RhinoApp.WriteLine("{0} = {1}", ud.Description, ud.Notes); return(Result.Success); } // Prompt for a string var gs = new GetString(); gs.SetCommandPrompt("Surface notes"); gs.GetLiteralString(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } // Duplicate the brep var new_brep = brep.DuplicateBrep(); if (null != new_brep) { // Get the brep face's underlying surface srf = new_brep.Surfaces[surface_index]; if (null != srf) { // New up the user data ud = new SampleCsUserDataObject { Notes = gs.StringResult() }; // Attach the user data to the surface srf.UserData.Add(ud); // Replace object. Note, we cannot reuse obj_ref because it only references // the picked surface or face, not the top level brep. So, just pass the // Rhino object's id instead. doc.Objects.Replace(brep_object.Id, new_brep); } } doc.Views.Redraw(); 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) { 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); }