/// <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); }
/// <summary> /// Called by Rhino when the user wants to run the command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var message = "Hello Rhino!"; rc = RhinoGet.GetString("String to echo", false, ref message); if (rc != Result.Success) { return(rc); } try { RockfishClientPlugIn.ServerHostName(); using (var channel = new RockfishClientChannel()) { channel.Create(); message = channel.Echo(message); } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } RhinoApp.WriteLine(message); 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 rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var go = new GetObject(); go.SetCommandPrompt("Select two surfaces or polysurfaces to intersect"); go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go.SubObjectSelect = false; go.GetMultiple(2, 2); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var brep0 = go.Object(0).Brep(); var brep1 = go.Object(1).Brep(); if (null == brep0 || null == brep1) { return(Result.Failure); } var in_brep0 = new RockfishGeometry(brep0); var in_brep1 = new RockfishGeometry(brep1); RockfishGeometry[] out_curves; try { RockfishClientPlugIn.ServerHostName(); using (var channel = new RockfishClientChannel()) { channel.Create(); out_curves = channel.IntersectBreps(in_brep0, in_brep1, doc.ModelAbsoluteTolerance); } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } foreach (var out_curve in out_curves) { if (null != out_curve?.Curve) { var object_id = doc.Objects.AddCurve(out_curve.Curve); var rhino_object = doc.Objects.Find(object_id); rhino_object?.Select(true); } } 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 rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var go = new GetObject(); go.SetCommandPrompt("Select points for polyline creation"); go.GeometryFilter = ObjectType.Point; go.SubObjectSelect = false; go.GetMultiple(2, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var in_points = new List <RockfishPoint>(go.ObjectCount); foreach (var obj_ref in go.Objects()) { var point = obj_ref.Point(); if (null != point) { in_points.Add(new RockfishPoint(point.Location)); } } if (in_points.Count < 2) { return(Result.Cancel); } RockfishGeometry out_curve; try { RockfishClientPlugIn.ServerHostName(); using (var channel = new RockfishClientChannel()) { channel.Create(); out_curve = channel.PolylineFromPoints(in_points.ToArray(), doc.ModelAbsoluteTolerance); } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } if (null != out_curve?.Curve) { doc.Objects.AddCurve(out_curve.Curve); 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 rc = RockfishClientPlugIn.VerifyServerHostName(); if (rc != Result.Success) { return(rc); } var go = new GetObject(); go.SetCommandPrompt("Select surfaces or polysurfaces mesh"); go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var breps = new List <Brep>(); foreach (var obj_ref in go.Objects()) { if (ObjectType.Brep == obj_ref.Geometry().ObjectType) { var brep = obj_ref.Brep(); if (null != brep) { breps.Add(brep); } } else if (ObjectType.Extrusion == obj_ref.Geometry().ObjectType) { var extrusion = obj_ref.Geometry() as Extrusion; var brep = extrusion?.ToBrep(true); if (null != brep) { breps.Add(brep); } } } if (0 == breps.Count) { return(Result.Cancel); } try { using (var channel = new RockfishClientChannel()) { channel.Create(); foreach (var brep in breps) { var in_brep = new RockfishGeometry(brep); var out_mesh = channel.CreateMeshFromBrep(in_brep, false); if (null != out_mesh?.Mesh) { var object_id = doc.Objects.AddMesh(out_mesh.Mesh); var rhino_object = doc.Objects.Find(object_id); rhino_object?.Select(true); } } } } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } doc.Views.Redraw(); return(Result.Success); }