protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gm = new GetObject(); gm.SetCommandPrompt("Select mesh"); gm.GeometryFilter = ObjectType.Mesh; gm.Get(); if (gm.CommandResult() != Result.Success) { return(gm.CommandResult()); } var gp = new GetObject(); gp.SetCommandPrompt("Select polyline"); gp.GeometryFilter = ObjectType.Curve; gp.EnablePreSelect(false, true); gp.DeselectAllBeforePostSelect = false; gp.Get(); if (gm.CommandResult() != Result.Success) { return(gp.CommandResult()); } var mesh = gm.Object(0).Mesh(); if (null == mesh) { return(Result.Failure); } var curve = gp.Object(0).Curve(); if (null == curve) { return(Result.Failure); } var polyline_curve = curve as PolylineCurve; if (null == polyline_curve) { RhinoApp.Write("Curve is not a polyline"); return(Result.Nothing); } int[] face_ids; var points = Rhino.Geometry.Intersect.Intersection.MeshPolyline(mesh, polyline_curve, out face_ids); if (points.Length > 0) { foreach (var pt in points) { doc.Objects.AddPoint(pt); } doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. bool layerAdded = AddLayer(doc); if (layerAdded) { RhinoApp.WriteLine("Layers are successfully added."); } bool directoryCreated = CreateDirectories(doc); if (directoryCreated) { RhinoApp.Write("Directories are successfully created."); } bool materialCopied = CopyMaterialFile(); if (materialCopied) { RhinoApp.Write("material.rad has been copied."); } bool epw2weaRun = SetWeatherFile(doc, @"C:\DIVA\WeatherData\USA_GA_Atlanta-Hartsfield-Jackson.Intl.AP.722190_TMY3.epw"); return(Result.Success); }
public static void log_NoEnter(string s) { if (!ENABLED) { return; } RhinoApp.Write(s); }
// add the action to redirect output to VS Code protected void PrintToVSCode(string m) { RhinoApp.Write(m); GotCodeFeedbackEventArgs arg = new GotCodeFeedbackEventArgs { Message = m }; OnGotCodeFeedBack(arg); }
public override void Write(byte[] buffer, int offset, int count) { string str = Encoding.Default.GetString(buffer, offset, count).Replace("\r", ""); this.sb.Append(str); if (str.EndsWith("\n")) { RhinoApp.Write(this.sb.ToString()); this.sb.Length = 0; } }
public static void PrintList <T>(ref List <T> list, string delimiter) { #if VERBOSE var lastItem = list.Last(); list.ForEach(x => RhinoApp.Write(x.Equals(lastItem) ? x.ToString() : x.ToString() + delimiter)); RhinoApp.WriteLine(); #else StackTrace stackTrace = new StackTrace(true); StackFrame frame = stackTrace.GetFrame(1); RhinoApp.WriteLine($"Stagnant log! {Utils.Debug.StackTraceInfo(frame)}"); #endif }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { try { // Go get the assembly through your preferred method. var assembly = typeof(TestsUsingRhinoAPI.RhinoCommonTest).Assembly; new AutoRun(assembly).Execute(new string[] { }, new RhinoConsoleTextWriter(), null); } catch (Exception e) { RhinoApp.Write(e.ToString()); return(Result.Failure); } return(Result.Success); }
public static void rawText(g group, string s) { if (!ENABLED) { return; } if (!Group.IsEnabled(group)) { return; } lock (Shared.RhinoLock) { RhinoApp.Write(s); } LogNumer++; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gp = new GetPoint(); string prompt; prompt = "select a point"; gp.SetCommandPrompt(prompt); gp.Get(); Result res = gp.CommandResult(); if (res != Result.Success) { return(gp.CommandResult()); } var point = gp.Point(); var format = string.Format("F{0}", doc.DistanceDisplayPrecision); var provider = System.Globalization.CultureInfo.InvariantCulture; var x = point.X.ToString(format); var y = point.Y.ToString(format); var z = point.Z.ToString(format); RhinoApp.Write("World coordinates: {0},{1},{2}" + Environment.NewLine, x, y, z); double number = 0.56; RhinoApp.WriteLine(number.ToString("F5", provider)); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //First, collect all the breps to split ObjRef[] obj_refs; var rc = RhinoGet.GetMultipleObjects("Select breps to split", false, ObjectType.Brep, out obj_refs); if (rc != Result.Success || obj_refs == null) { return(rc); } // Get the final plane Plane plane; rc = RhinoGet.GetPlane(out plane); if (rc != Result.Success) { return(rc); } //Iterate over all object references foreach (var obj_ref in obj_refs) { var brep = obj_ref.Brep(); var bbox = brep.GetBoundingBox(false); //Grow the boundingbox in all directions //If the boundingbox is flat (zero volume or even zero area) //then the CreateThroughBox method will fail. var min_point = bbox.Min; min_point.X -= 1.0; min_point.Y -= 1.0; min_point.Z -= 1.0; bbox.Min = min_point; var max_point = bbox.Max; max_point.X += 1.0; max_point.Y += 1.0; max_point.Z += 1.0; bbox.Max = max_point; var plane_surface = PlaneSurface.CreateThroughBox(plane, bbox); if (plane_surface == null) { //This is rare, it will most likely not happen unless either the plane or the boundingbox are invalid RhinoApp.WriteLine("Cutting plane could not be constructed."); } else { var breps = brep.Split(plane_surface.ToBrep(), doc.ModelAbsoluteTolerance); if (breps == null || breps.Length == 0) { RhinoApp.Write("Plane does not intersect brep (id:{0})", obj_ref.ObjectId); continue; } foreach (var brep_piece in breps) { doc.Objects.AddBrep(brep_piece); } doc.Objects.AddSurface(plane_surface); doc.Objects.Delete(obj_ref, false); } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string path = null; if (mode == RunMode.Interactive) { var dialog = new OpenFileDialog { Title = EnglishName, Filter = @"Text Documents|*.txt" }; if (dialog.ShowDialog() != DialogResult.OK) { return(Result.Cancel); } path = dialog.FileName; } else { var rc = RhinoGet.GetString("Name of file to embed", false, ref path); if (rc != Result.Success) { return(rc); } } path = path.Trim(); if (string.IsNullOrEmpty(path)) { return(Result.Nothing); } if (!File.Exists(path)) { RhinoApp.WriteLine("File not found."); return(Result.Nothing); } string text; try { text = File.ReadAllText(path); } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } if (string.IsNullOrEmpty(text)) { RhinoApp.WriteLine("File is empty."); return(Result.Nothing); } var fname = Path.GetFileName(path); doc.Strings.SetString(fname, text); RhinoApp.Write("Embedded {0} ({1} characters)", fname, text.Length); return(Result.Success); }
public bool Print(string message) { RhinoApp.Write(message); return(true); }
/// <summary> /// This example demonstrates how to construct a ON_Brep /// with the topology shown below. /// /// E-------C--------D /// | /\ | /// | / \ | /// | / \ | /// | e2 e1 | /// | / \ | /// | / \ | /// | / \ | /// A-----e0-------->B /// /// Things need to be defined in a valid brep: /// 1- Vertices /// 2- 3D Curves (geometry) /// 3- Edges (topology - reference curve geometry) /// 4- Surface (geometry) /// 5- Faces (topology - reference surface geometry) /// 6- Loops (2D parameter space of faces) /// 4- Trims and 2D curves (2D parameter space of edges) /// </summary> /// <returns>A Brep if successful, null otherwise</returns> public static Brep MakeTrimmedPlane() { // Define the vertices var points = new Point3d[5]; points[A] = new Point3d(0.0, 0.0, 0.0); // point A = geometry for vertex 0 (and surface SW corner) points[B] = new Point3d(10.0, 0.0, 0.0); // point B = geometry for vertex 1 (and surface SE corner) points[C] = new Point3d(5.0, 10.0, 0.0); // point C = geometry for vertex 2 points[D] = new Point3d(10.0, 10.0, 0.0); // point D (surface NE corner) points[E] = new Point3d(0.0, 10.0, 0.0); // point E (surface NW corner) // Create the Brep var brep = new Brep(); // Create three vertices located at the three points for (var vi = 0; vi < 3; vi++) { // This simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of BrepVertex. brep.Vertices.Add(points[vi], 0.0); } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.Curves3D.Add(CreateLinearCurve(points[A], points[B])); // line AB brep.Curves3D.Add(CreateLinearCurve(points[B], points[C])); // line BC brep.Curves3D.Add(CreateLinearCurve(points[A], points[C])); // line CD // Create edge topology for each curve in the brep CreateEdges(brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.AddSurface(CreatePlanarSurface(points[A], points[B], points[D], points[E])); // ABDE // Create face topology and 2d parameter space loops and trims CreateFaces(brep); #if DEBUG string tlog; var rc = brep.IsValidTopology(out tlog); if (!rc) { RhinoApp.WriteLine(tlog); return(null); } string glog; rc = brep.IsValidGeometry(out glog); if (!rc) { RhinoApp.WriteLine(glog); return(null); } #endif // Validate the results if (!brep.IsValid) { RhinoApp.Write("Trimmed Brep face is not valid."); return(null); } return(brep); }
/// <summary> /// This example demonstrates how to construct a ON_Brep /// with the topology shown below. /// /// D---------e2-----C /// | | /// | G----e6---H | /// | | | | /// e3 e5 e7 | /// | | | | /// | F----e4---E | /// | | /// A-------e0-------B /// /// Things need to be defined in a valid brep: /// 1- Vertices /// 2- 3D Curves (geometry) /// 3- Edges (topology - reference curve geometry) /// 4- Surface (geometry) /// 5- Faces (topology - reference surface geometry) /// 6- Loops (2D parameter space of faces) /// 4- Trims and 2D curves (2D parameter space of edges) /// </summary> /// <returns>A Brep if successful, null otherwise</returns> public static Brep MakeBrepFace() { // Define the vertices var points = new Point3d[8]; points[A] = new Point3d(0.0, 0.0, 0.0); // point A = geometry for vertex 0 points[B] = new Point3d(10.0, 0.0, 0.0); // point B = geometry for vertex 1 points[C] = new Point3d(10.0, 10.0, 0.0); // point C = geometry for vertex 2 points[D] = new Point3d(0.0, 10.0, 0.0); // point D = geometry for vertex 3 points[E] = new Point3d(8.0, 2.0, 0.0); // point E = geometry for vertex 4 points[F] = new Point3d(2.0, 2.0, 0.0); // point F = geometry for vertex 5 points[G] = new Point3d(2.0, 8.0, 0.0); // point G = geometry for vertex 6 points[H] = new Point3d(8.0, 8.0, 0.0); // point H = geometry for vertex 7 // Create the Brep var brep = new Brep(); // Create four vertices of the outer edges for (var vi = 0; vi < 8; vi++) { // This simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of BrepVertex. brep.Vertices.Add(points[vi], 0.0); } // Create 3d curve geometry of the outer boundary // The orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.Curves3D.Add(CreateLinearCurve(points[A], points[B])); // line AB brep.Curves3D.Add(CreateLinearCurve(points[B], points[C])); // line BC brep.Curves3D.Add(CreateLinearCurve(points[C], points[D])); // line CD brep.Curves3D.Add(CreateLinearCurve(points[A], points[D])); // line AD // Create 3d curve geometry of the hole brep.Curves3D.Add(CreateLinearCurve(points[E], points[F])); // line EF brep.Curves3D.Add(CreateLinearCurve(points[F], points[G])); // line GH brep.Curves3D.Add(CreateLinearCurve(points[G], points[H])); // line HI brep.Curves3D.Add(CreateLinearCurve(points[E], points[H])); // line EI // Create edge topology for each curve in the brep. CreateEdges(brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.AddSurface(CreateNurbsSurface(points[A], points[B], points[C], points[D])); // ABCD // Create face topology and 2d parameter space loops and trims. CreateFace(brep, ABCD); #if DEBUG string tlog; var rc = brep.IsValidTopology(out tlog); if (!rc) { RhinoApp.WriteLine(tlog); return(null); } string glog; rc = brep.IsValidGeometry(out glog); if (!rc) { RhinoApp.WriteLine(glog); return(null); } #endif // Validate the results if (!brep.IsValid) { RhinoApp.Write("Brep face is not valid."); return(null); } return(brep); }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { RhinoApp.Write(e.AddedItems.ToString()); }
/// <summary> /// This example demonstrates how to construct a Brep /// with the topology shown below. /// /// H-------e6-------G /// / /| /// / | / | /// / e7 / e5 /// / | / | /// / e10 | /// / | / | /// e11 E- - e4- -/- - - F /// / / / /// / / / / /// D---------e2-----C e9 /// | / | / /// | e8 | / /// e3 / e1 / /// | | / /// | / | / /// | |/ /// A-------e0-------B /// /// </summary> /// <returns>A Brep if successful, null otherwise</returns> public static Brep MakeTwistedCube() { // Define the vertices of the twisted cube var points = new Point3d[8]; points[A] = new Point3d(0.0, 0.0, 0.0); // point A = geometry for vertex 0 points[B] = new Point3d(10.0, 0.0, 0.0); // point B = geometry for vertex 1 points[C] = new Point3d(10.0, 8.0, -1.0); // point C = geometry for vertex 2 points[D] = new Point3d(0.0, 6.0, 0.0); // point D = geometry for vertex 3 points[E] = new Point3d(1.0, 2.0, 11.0); // point E = geometry for vertex 4 points[F] = new Point3d(10.0, 0.0, 12.0); // point F = geometry for vertex 5 points[G] = new Point3d(10.0, 7.0, 13.0); // point G = geometry for vertex 6 points[H] = new Point3d(0.0, 6.0, 12.0); // point H = geometry for vertex 7 // Create the Brep var brep = new Brep(); // Create eight Brep vertices located at the eight points for (var vi = 0; vi < points.Length; vi++) { // This simple example is exact - for models with // non-exact data, set tolerance as explained in // definition of BrepVertex. brep.Vertices.Add(points[vi], 0.0); } // Create 3d curve geometry - the orientations are arbitrarily chosen // so that the end vertices are in alphabetical order. brep.Curves3D.Add(TwistedCubeEdgeCurve(points[A], points[B])); // line AB brep.Curves3D.Add(TwistedCubeEdgeCurve(points[B], points[C])); // line BC brep.Curves3D.Add(TwistedCubeEdgeCurve(points[C], points[D])); // line CD brep.Curves3D.Add(TwistedCubeEdgeCurve(points[A], points[D])); // line AD brep.Curves3D.Add(TwistedCubeEdgeCurve(points[E], points[F])); // line EF brep.Curves3D.Add(TwistedCubeEdgeCurve(points[F], points[G])); // line FG brep.Curves3D.Add(TwistedCubeEdgeCurve(points[G], points[H])); // line GH brep.Curves3D.Add(TwistedCubeEdgeCurve(points[E], points[H])); // line EH brep.Curves3D.Add(TwistedCubeEdgeCurve(points[A], points[E])); // line AE brep.Curves3D.Add(TwistedCubeEdgeCurve(points[B], points[F])); // line BF brep.Curves3D.Add(TwistedCubeEdgeCurve(points[C], points[G])); // line CG brep.Curves3D.Add(TwistedCubeEdgeCurve(points[D], points[H])); // line DH // Create the 12 edges that connect the corners of the cube MakeTwistedCubeEdges(brep); // Create 3d surface geometry - the orientations are arbitrarily chosen so // that some normals point into the cube and others point out of the cube. brep.AddSurface(TwistedCubeSideSurface(points[A], points[B], points[C], points[D])); // ABCD brep.AddSurface(TwistedCubeSideSurface(points[B], points[C], points[G], points[F])); // BCGF brep.AddSurface(TwistedCubeSideSurface(points[C], points[D], points[H], points[G])); // CDHG brep.AddSurface(TwistedCubeSideSurface(points[A], points[D], points[H], points[E])); // ADHE brep.AddSurface(TwistedCubeSideSurface(points[A], points[B], points[F], points[E])); // ABFE brep.AddSurface(TwistedCubeSideSurface(points[E], points[F], points[G], points[H])); // EFGH // Create the Brep faces MakeTwistedCubeFaces(brep); #if DEBUG for (var fi = 0; fi < brep.Faces.Count; fi++) { TraverseBrepFace(brep, fi); } string tlog; var rc = brep.IsValidTopology(out tlog); if (!rc) { RhinoApp.WriteLine(tlog); return(null); } string glog; rc = brep.IsValidGeometry(out glog); if (!rc) { RhinoApp.WriteLine(glog); return(null); } #endif // Validate the results if (!brep.IsValid) { RhinoApp.Write("Twisted cube Brep is not valid."); return(null); } return(brep); }