public static Mesh ConvertBrepToMesh(Brep brep, List <Curve> curves, List <Point3d> points, double meshSize, List <Parameters.GsaMember1d> mem1ds = null, List <Parameters.GsaNode> nodes = null) { Brep in_brep = brep.DuplicateBrep(); in_brep.Faces.ShrinkFaces(); // set up unroller Unroller unroller = new Unroller(in_brep); List <Curve> memcrvs = new List <Curve>(); if (mem1ds != null) { memcrvs = mem1ds.ConvertAll(x => (Curve)x.PolyCurve); unroller.AddFollowingGeometry(memcrvs); } List <Point3d> nodepts = new List <Point3d>(); if (nodes != null) { nodepts = nodes.ConvertAll(x => x.Point); unroller.AddFollowingGeometry(nodepts); } unroller.AddFollowingGeometry(points); unroller.AddFollowingGeometry(curves); unroller.RelativeTolerance = 10 ^ 32; //unroller.AbsoluteTolerance = 1000; // create list of flattened geometry Point3d[] inclPts; Curve[] inclCrvs; TextDot[] unused; // perform unroll Brep[] flattened = unroller.PerformUnroll(out inclCrvs, out inclPts, out unused); // create 2d member from flattened geometry Parameters.GsaMember2d mem = new Parameters.GsaMember2d(flattened[0], inclCrvs.ToList(), inclPts.ToList()); mem.Member.MeshSize = meshSize; // add to temp list for input in assemble function List <Parameters.GsaMember2d> mem2ds = new List <Parameters.GsaMember2d>(); mem2ds.Add(mem); if (mem1ds != null) { for (int i = 0; i < mem1ds.Count; i++) { Parameters.GsaMember1d mem1d = new Parameters.GsaMember1d(inclCrvs[i]); mem1d.Member.MeshSize = mem1ds[i].Member.MeshSize; mem1ds[i] = mem1d; } } if (nodes != null) { for (int i = 0; i < nodes.Count; i++) { nodes[i].Point = inclPts[i]; } } // assemble temp model Model model = Util.Gsa.ToGSA.Assemble.AssembleModel(null, mem2ds, mem1ds, nodes); // call the meshing algorithm model.CreateElementsFromMembers(); // extract elements from model Tuple <List <Parameters.GsaElement1dGoo>, List <Parameters.GsaElement2dGoo>, List <Parameters.GsaElement3dGoo> > elementTuple = Util.Gsa.FromGSA.GetElements(model.Elements(), model.Nodes(), model.Sections(), model.Prop2Ds()); List <Parameters.GsaElement2dGoo> elem2dgoo = elementTuple.Item2; Mesh mesh = elem2dgoo[0].Value.Mesh; Surface flat = flattened[0].Surfaces[0]; Surface orig = in_brep.Surfaces[0]; MeshVertexList vertices = mesh.Vertices; for (int i = 0; i < vertices.Count; i++) { flat.ClosestPoint(vertices.Point3dAt(i), out double u, out double v); Point3d mapVertex = orig.PointAt(u, v); vertices.SetVertex(i, mapVertex); } mesh.Faces.ConvertNonPlanarQuadsToTriangles(GhSA.Units.Tolerance, Rhino.RhinoMath.DefaultAngleTolerance, 0); return(mesh); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; Stopwatch watch = new Stopwatch(); GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } Rhino.DocObjects.ObjRef my_objref = gbrep.Object(0); Rhino.DocObjects.RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); GetObjectPosition gp = new GetObjectPosition(brep, my_mesh); gp.SetCommandPrompt("Get the object position on mesh: "); gp.Constrain(my_mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Brep moved_brep = brep.DuplicateBrep(); Point3d Origin = brep.UserDictionary.GetPoint3d("CurrentPosition"); Vector3d OriginVector = brep.UserDictionary.GetVector3d("CurrentDirection"); Point3d new_position = gp.Point(); Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0)); if (OriginVector.IsParallelTo(normal_on_mesh) == 0) { double RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh); Vector3d RoationAxis = Vector3d.CrossProduct(OriginVector, normal_on_mesh); moved_brep.Rotate(RotationAngle, RoationAxis, Origin); } moved_brep.Translate(new_position - Origin); moved_brep.UserDictionary.Set("CurrentPosition", new_position); moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color")); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; watch.Start(); //delete all old paths IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } watch.Stop(); RhinoApp.WriteLine("time 1: {0}", watch.Elapsed); ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; Guid pin_1_id = moved_brep.UserDictionary.GetGuid("PinID"); MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0); watch.Restart(); List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint); watch.Stop(); RhinoApp.WriteLine("time 2: {0}", watch.Elapsed); watch.Restart(); for (int i = 0; i < new_path_list.Count; i++) { doc.Objects.Add(new_path_list[i], path_attributes); } doc.Objects.Delete(my_objref, true); brep.Dispose(); doc.Objects.AddBrep(moved_brep, my_attributes); doc.Views.Redraw(); watch.Stop(); RhinoApp.WriteLine("time 3: {0}", watch.Elapsed); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (TimePanel.Instance.Restarted && TimePanel.Instance.TrackbarValue == 0) { ObjRef[] objrefs; Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the polysurfaces for the union", false, ObjectType.Brep, out objrefs); if (rc != Result.Success) { return(rc); } if (objrefs == null || objrefs.Length <= 1) { Dialogs.ShowMessage("You have to select 2 or more shapes.", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Failure); } List <Brep> in_breps0 = new List <Brep>(); for (int i = 0; i < objrefs.Length; i++) { int index = RigidBodyManager.GuidList.IndexOf(objrefs[i].ObjectId); //Avoid to create a compound from another compound if (RigidBodyManager.RigidBodies[index].Shape is CompoundShape) { Dialogs.ShowMessage("You cannot create compound shape from another compound shape. Try to create it at once.", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Failure); } //Accept shapes only if they intersect to each other Brep brep = objrefs[i].Brep(); if (brep != null) { in_breps0.Add(brep); } RhinoDoc.ActiveDoc.Objects.Delete(objrefs[i], true); } //Create the rhino compound shape double tolerance = doc.ModelAbsoluteTolerance; Brep[] breps = Brep.CreateBooleanUnion(in_breps0, tolerance); if (breps.Length > 1) { Dialogs.ShowMessage("You cannot create more than a compound shape in once time.", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Failure); } Brep rhinoCompound = breps[0]; // If the user create zero or more than 1 compound the command fails if (breps.Length != 1) { return(Rhino.Commands.Result.Nothing); } Brep copyToAdd = rhinoCompound.DuplicateBrep(); //Create the rigid compound shape CompoundShape.TransformedShape[] transformedShapes = new CompoundShape.TransformedShape[in_breps0.Count]; for (int i = 0; i < in_breps0.Count; i++) { Guid guid = objrefs[i].ObjectId; int indexRigidBody = RigidBodyManager.GuidList.IndexOf(guid); transformedShapes[i] = new CompoundShape.TransformedShape(RigidBodyManager.RigidBodies[indexRigidBody].Shape, RigidBodyManager.RigidBodies[indexRigidBody].Orientation, RigidBodyManager.RigidBodies[indexRigidBody].Position); } CompoundShape jCompound = new CompoundShape(transformedShapes); RigidBody jCompoundBody = new RigidBody(jCompound); //Move the center of mass of Jitter shape on the center of the BBox of rhino shape Point3d centerBbox = rhinoCompound.GetBoundingBox(true).Center; jCompoundBody.Position = RigidBodyManager.Point3dtoJVector(centerBbox); //Find the difference between rhino bbx center and jitter bbox center JVector bboxjitter = jCompoundBody.BoundingBox.Center; JVector diff = bboxjitter - RigidBodyManager.Point3dtoJVector(centerBbox); //Align the center of both bboxes jCompoundBody.Position -= diff; //Translate the center of the Bbox to 0,0,0 and save it to geometry list Point3d bboxDoc = rhinoCompound.GetBoundingBox(true).Center; rhinoCompound.Translate(new Vector3d(-bboxDoc.X, -bboxDoc.Y, -bboxDoc.Z)); RigidBodyManager.RigidBodies.Add(jCompoundBody); RigidBodyManager.GeometryList.Add(rhinoCompound); Guid guidToAdd = doc.Objects.Add(copyToAdd); RigidBodyManager.GuidList.Add(guidToAdd); doc.Views.Redraw(); return(Result.Success); } else { Dialogs.ShowMessage("Press Restart before use other commands", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Success); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { MaterialProperties mp = null; Brep BBrep = new Brep(); Curve spCrv = null; int N = 0; double scale = 0; if (!DA.GetData(0, ref mp)) { return; } if (!DA.GetData(1, ref BBrep)) { return; } if (!DA.GetData(2, ref spCrv)) { return; } if (!DA.GetData(3, ref N)) { return; } if (!DA.GetData(4, ref scale)) { return; } if (N < 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input n must be an integer greater than 1"); return; } //Copy to each analysis plugin - extracts material properties from MP input double fc = mp.fC; double Ec = mp.EC; double ec = mp.eC; double rhoc = mp.rhoC; double EEc = mp.EEC; double fy = mp.fY; double Es = mp.ES; double es = mp.eS; double rhos = mp.rhoS; double EEs = mp.EES; if (spCrv.PointAtStart.X > spCrv.PointAtEnd.X) { spCrv.Reverse(); } //double tStart = 0; //spCrv.ClosestPoint(spCrv.PointAtEnd, out tStart); //Extract perpendicular planes to segment Brep Double[] spCrvDiv = spCrv.DivideByCount(N, false); Plane[] splitPls = spCrv.GetPerpendicularFrames(spCrvDiv); double L = spCrv.GetLength(); double dl = L / (N); BoundingBox boundBBrep = BBrep.GetBoundingBox(Plane.WorldXY); List <Brep> splitPlns = new List <Brep>(); List <Brep> splitBBreps = new List <Brep>(); Brep smallBBrep = BBrep.DuplicateBrep(); Brep add = new Brep(); List <double> qw = new List <double>(); List <Point3d> qwPts = new List <Point3d>(); List <Point3d> spCrvPts = new List <Point3d>(); //qw.Add(0); //qwPts.Add(spCrv.PointAtStart); for (int i = 0; i < splitPls.Length; i++) { PlaneSurface plSrf = PlaneSurface.CreateThroughBox(splitPls[i], boundBBrep); splitPlns.Add(plSrf.ToBrep()); } Brep[] splitBBrep = smallBBrep.Split(splitPlns, DocumentTolerance()); double[] sortSplit = new double[splitBBrep.Length]; for (int i = 0; i < splitBBrep.Length; i++) { splitBBrep[i] = splitBBrep[i].CapPlanarHoles(DocumentTolerance()); double xLoc = VolumeMassProperties.Compute(splitBBrep[i]).Centroid.X; sortSplit[i] = xLoc; } Array.Sort(sortSplit, splitBBrep); //for (int i = 1; i <= splitPls.Length - 1; i++) //{ // PlaneSurface plSrf = PlaneSurface.CreateThroughBox(splitPls[i], boundBBrep); // splitPlns.Add(plSrf.ToBrep()); // Brep[] split = smallBBrep.Split(plSrf.ToBrep(), DocumentTolerance()); // if (split.Length > 0) // { // if (split[0].GetVolume() < split[1].GetVolume()) // { // add = split[0].CapPlanarHoles(DocumentTolerance()); // smallBBrep = split[1].CapPlanarHoles(DocumentTolerance()); // } // else if (split[0].GetVolume() > split[1].GetVolume()) // { // add = split[1].CapPlanarHoles(DocumentTolerance()); // smallBBrep = split[0].CapPlanarHoles(DocumentTolerance()); // } // splitBBreps.Add(add); // } // //foreach(Brep b in split) { splitBBreps.Add(b.CapPlanarHoles(DocumentTolerance())); } //} //qwPts.Add(spCrv.PointAtEnd); //Point3d qwPt0 = spCrv.PointAt(edge0div[0] * 0.5); qwPts.Add(qwPt0); for (int i = 0; i < splitBBrep.Length; i++) { Point3d pt = new Point3d(); if (i < splitBBrep.Length - 1) { pt = spCrv.PointAt(spCrvDiv[i] + spCrvDiv[0] * 0.5); } else if (i == splitBBrep.Length - 1) { pt = spCrv.PointAt(spCrvDiv[0] * 0.5); } spCrvPts.Add(pt); double dqw = Math.Abs(splitBBrep[i].GetVolume()) * rhoc * 0.00980665 / dl; qw.Add(dqw); Point3d qwPt = new Point3d(pt.X, pt.Y, dqw * scale); qwPts.Add(qwPt); } List <Curve> graphActual = new List <Curve>(); //Curve qwCrv = null; Curve qwCrv = Curve.CreateInterpolatedCurve(qwPts, 1); graphActual.Add(qwCrv); for (int i = 0; i < qwPts.Count; i++) { Line crv = new Line(qwPts[i], spCrvPts[i]); graphActual.Add(crv.ToNurbsCurve()); } double qwSum = 0; foreach (double qwi in qw) { qwSum += qwi; } double qwAve = qwSum / qw.Count; List <Point3d> qwAvePts = new List <Point3d>(); for (int i = 0; i < qw.Count; i++) { //Point3d pt = spCrv.PointAt((spCrvDiv[i] + spCrvDiv[1] * 0.5)); // spCrv.GetLength()); Point3d pt = spCrvPts[i]; Point3d qwAvePt = new Point3d(pt.X, pt.Y, qwAve * scale); qwAvePts.Add(qwAvePt); } List <Curve> graphAverage = new List <Curve>(); Curve qwAveCrv = Curve.CreateInterpolatedCurve(qwAvePts, 1); graphAverage.Add(qwAveCrv); for (int i = 0; i < qwPts.Count; i++) { Line crv = new Line(qwAvePts[i], spCrvPts[i]); graphAverage.Add(crv.ToNurbsCurve()); } List <Vector3d> Pw = new List <Vector3d>(); foreach (double q in qw) { Pw.Add(new Vector3d(0, 0, -q * dl)); } //Brep[] splitBBrep = BBrep.Split(splitPlns, DocumentTolerance()); Double[] PwSpCrvDiv = spCrv.DivideByCount(2 * N, true); Curve[] PwSpCrvSplit = spCrv.Split(PwSpCrvDiv); Double[] qwSpCrvDiv = spCrv.DivideByCount(N, true); Curve[] qwSpCrvSplit = spCrv.Split(qwSpCrvDiv); List <Curve> qwGraphActual = new List <Curve>(); List <Curve> qwGraphAverage = new List <Curve>(); Curve crvAct = null; Curve crvAve = null; for (int i = 0; i < qwSpCrvSplit.Length; i++) { Transform moveAct = Transform.Translation(0, 0, qw[i] * scale); Transform moveAve = Transform.Translation(0, 0, qwAve * scale); crvAct = qwSpCrvSplit[i].DuplicateCurve(); crvAct.Transform(moveAct); qwGraphActual.Add(crvAct); crvAve = qwSpCrvSplit[i].DuplicateCurve(); crvAve.Transform(moveAve); qwGraphAverage.Add(crvAve); } //Curve[] spCrvTEST = new Curve[1] { spCrv}; for (int i = 0; i < qw.Count; i++) { qw[i] *= -1; } DA.SetDataList(0, qw); DA.SetDataList(1, qwSpCrvSplit); //DA.SetDataList(2, Pw); //DA.SetDataList(3, PwSpCrvSplit); //DA.SetDataList(4, spCrvPts); DA.SetDataList(2, qwGraphActual); DA.SetDataList(3, qwGraphAverage); DA.SetDataList(4, splitBBrep); }
public GetObjectPosition(Brep brep, Mesh mesh) { new_brep = brep.DuplicateBrep(); base_mesh = mesh; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { double span = 0; List <VariableSection> vSect = new List <VariableSection>(); if (!DA.GetData(0, ref span)) { return; } if (!DA.GetDataList(1, vSect)) { return; } int N = vSect.Count; if (N < 2) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "VSect needs at least 2 inputs"); return; } Transform mirrorYZ = Transform.Mirror(Plane.WorldYZ); Transform mirrorXZ = Transform.Mirror(Plane.WorldZX); Point3d spPtA = new Point3d(-span * 0.5, 0, 0); Curve spCrv = new Line(spPtA, Plane.WorldXY.XAxis, span).ToNurbsCurve(); Curve spCrvHlf = new Line(spPtA, Plane.WorldXY.XAxis, span * 0.5).ToNurbsCurve(); //if (N < 2) { N = 3; } double[] spCrvDiv = spCrv.DivideByCount(N - 1, true); Plane[] spCrvPln = spCrv.GetPerpendicularFrames(spCrvDiv); for (int i = 0; i < spCrvPln.Length; i++) //reorient planes to align with z-axis { Plane pl = spCrvPln[i]; pl.Rotate(-Math.PI * 0.5, Plane.WorldXY.XAxis); spCrvPln[i] = pl; } List <Point3d> allPts = new List <Point3d>(); List <Curve> crvs = new List <Curve>(); int ptCnt = vSect[0].sctPts.Count; Point3d[,] crvPts = new Point3d[ptCnt, vSect.Count]; //for(int i = 0; i < vSect.Count; i++) { Point3d[] crvPt = new Point3d[vSect.Count]; } for (int i = 0; i < vSect.Count; i++) //moves and reorients points from input i indicates number section, j number curve/point in section { List <Point3d> sctPts = vSect[i].sctPts; Plane sctPln = vSect[i].sctPln; if (sctPts.Count != ptCnt) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Each section needs the same number of points"); return; } Transform reorient = Transform.PlaneToPlane(sctPln, spCrvPln[i]); //foreach (Point3d pt in sctPts) { pt.Transform(reorient); allPts.Add(pt); } //remove when workaround is figured out for (int j = 0; j < sctPts.Count; j++) //separate points to each "row" in a list of arrays { Point3d pt = sctPts[j]; pt.Transform(reorient); crvPts[j, i] = pt; } } int degree = 3; for (int i = 0; i < crvPts.GetLength(0); i++) //creates curves through points { Point3d[] aCrvPts = new Point3d[vSect.Count]; for (int j = 0; j < crvPts.GetLength(1); j++) { aCrvPts[j] = crvPts[i, j]; } Curve crv = Curve.CreateInterpolatedCurve(aCrvPts, degree); crvs.Add(crv); } List <Brep> faces = new List <Brep>(); Brep[] loftFace = Brep.CreateFromLoft(crvs, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); //Brep face1 = new Brep(); //foreach(Brep face in loftFace) { face1 = face.DuplicateBrep(); } Brep face1 = loftFace[0].DuplicateBrep(); Brep face2 = face1.DuplicateBrep(); face2.Transform(mirrorXZ); faces.Add(face1); faces.Add(face2); Curve[] naked1 = face1.DuplicateNakedEdgeCurves(true, false); Curve[] naked2 = face2.DuplicateNakedEdgeCurves(true, false); Curve[] loftCrv1 = new Curve[] { naked1[1], naked2[1] }; Curve[] loftCrv2 = new Curve[] { naked1[3], naked2[3] }; Brep[] face3 = Brep.CreateFromLoft(loftCrv1, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); Brep[] face4 = Brep.CreateFromLoft(loftCrv2, Point3d.Unset, Point3d.Unset, LoftType.Straight, false); faces.Add(face3[0]); faces.Add(face4[0]); Brep[] beamBreps = Brep.JoinBreps(faces, DocumentTolerance()); Brep beam = beamBreps[0].CapPlanarHoles(DocumentTolerance()); int intersects = 0; int a = crvs.Count; for (int i = 0; i < (a - 1); i++) { for (int j = (i + 1); j < a; j++) { Rhino.Geometry.Intersect.CurveIntersections crvCheck = Rhino.Geometry.Intersect.Intersection.CurveCurve( crvs[i], crvs[j], DocumentTolerance(), 0.0); intersects += crvCheck.Count; } } if (intersects > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Beam volume is invalid."); return; } DA.SetDataList(0, spCrvPln); DA.SetDataList(1, crvPts); DA.SetDataList(2, crvs); DA.SetData(3, beam); DA.SetData(4, spCrv); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { if (TimePanel.Instance.Restarted && TimePanel.Instance.TrackbarValue == 0) { RhinoApp.WriteLine("Now it's time to draw a box"); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("First corner of the base"); if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No corner point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); if (pt0.Z != 0) { RhinoApp.WriteLine("The base of the square is not on the plane XY"); return(getPointAction.CommandResult()); } } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Other corner of the base"); getPointAction.SetBasePoint(pt0, true); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(pt0, new Point3d(pt0.X, e.CurrentPoint.Y, 0), Color.Black); e.Display.DrawLine(pt0, new Point3d(e.CurrentPoint.X, pt0.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, e.CurrentPoint.Y, 0), e.CurrentPoint, Color.Black); e.Display.DrawLine(new Point3d(e.CurrentPoint.X, pt0.Y, 0), e.CurrentPoint, Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No corner point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); if (pt1.Z != 0) { RhinoApp.WriteLine("The base of the square is not on the plane XY"); return(getPointAction.CommandResult()); } if (pt1.Equals(pt0)) { RhinoApp.WriteLine("The second point is the same of the first"); return(getPointAction.CommandResult()); } } Point3d pt2; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Height"); getPointAction.SetBasePoint(pt1, true); var line = new Rhino.Geometry.Line(pt1, new Point3d(pt1.X, pt1.Y, 1)); getPointAction.Constrain(line); getPointAction.DynamicDraw += (sender, e) => { e.Display.DrawLine(pt0, new Point3d(pt0.X, pt1.Y, 0), Color.Black); e.Display.DrawLine(pt0, new Point3d(pt1.X, pt0.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, 0), pt1, Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, 0), pt1, Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), e.CurrentPoint, Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), e.CurrentPoint, Color.Black); e.Display.DrawLine(pt0, new Point3d(pt0.X, pt0.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(pt1, new Point3d(pt1.X, pt1.Y, e.CurrentPoint.Z), Color.Black); e.Display.DrawLine(new Point3d(pt0.X, pt1.Y, e.CurrentPoint.Z), new Point3d(pt0.X, pt1.Y, 0), Color.Black); e.Display.DrawLine(new Point3d(pt1.X, pt0.Y, e.CurrentPoint.Z), new Point3d(pt1.X, pt0.Y, 0), Color.Black); }; if (getPointAction.Get() != GetResult.Point) //getPointAction.Get() rimane in attesa del punto { RhinoApp.WriteLine("No Height point was selected."); return(getPointAction.CommandResult()); } pt2 = getPointAction.Point(); if (pt2.Z == 0) { RhinoApp.WriteLine("The height of the box must be different of 0"); return(getPointAction.CommandResult()); } } //Find center of the box Point3d middleDiagonal = new Point3d((pt0.X + pt1.X) / 2, (pt0.Y + pt1.Y) / 2, 0); Point3d middleHeight = new Point3d(0, 0, (pt1.Z + pt2.Z) / 2); Point3d centerBox = new Point3d(middleDiagonal.X, middleDiagonal.Y, middleHeight.Z); //Find dimension of the box Shape boxShape = new BoxShape((float)Math.Abs(pt1.X - pt0.X), (float)Math.Abs(pt1.Y - pt0.Y), (float)Math.Abs(pt2.Z)); RigidBody rigidBox = new RigidBody(boxShape); rigidBox.Position = new JVector((float)centerBox.X, (float)centerBox.Y, (float)centerBox.Z); Box box = new Box(new BoundingBox(RigidBodyManager.JVectorToPoint3d(boxShape.BoundingBox.Min), RigidBodyManager.JVectorToPoint3d(boxShape.BoundingBox.Max))); //Original one with the center in 0,0,0 Brep brepBox = box.ToBrep(); //Copy to translate and rotate Brep copyToAdd = brepBox.DuplicateBrep(); //Move the box to the correct position copyToAdd.Translate(centerBox.X, centerBox.Y, centerBox.Z); RigidBodyManager.RigidBodies.Add(rigidBox); RigidBodyManager.GeometryList.Add(brepBox); RigidBodyManager.GuidList.Add(doc.Objects.Add(copyToAdd)); doc.Views.Redraw(); return(Result.Success); } else { Dialogs.ShowMessage("Press Restart before use other commands", "Warning", ShowMessageButton.OK, ShowMessageIcon.Warning); return(Result.Success); } }
public static Brep MoveBrep(Brep brep, Mesh base_mesh, Point3d current_point, out List <Sphere> pin_ball_list) { Brep new_brep = brep.DuplicateBrep(); Point3d original_position = My_object_functions.GetPosition(new_brep); Vector3d original_direction = My_object_functions.GetZ(new_brep); Vector3d normal_on_mesh = base_mesh.NormalAt(base_mesh.ClosestMeshPoint(current_point, 0.1)); My_object_functions.RotateVerticallyTo(new_brep, normal_on_mesh); My_object_functions.TranslateTo(new_brep, current_point); int pin_quantity = My_object_functions.GetPinQuantity(new_brep); List <double> pin_to_mesh_distance = new List <double>(); List <Vector3d> pin_to_mesh_direction = new List <Vector3d>(); List <Sphere> pin_ball = new List <Sphere>(); for (int i = 0; i < pin_quantity; i++) { Point3d pin_position = My_object_functions.GetPinPosition(new_brep, i); //Sphere pin_ball_i = new Sphere(pin_position, 2); //pin_ball.Add(pin_ball_i); Line line1 = new Line(pin_position, -20 * normal_on_mesh); Line line2 = new Line(pin_position, 10 * normal_on_mesh); int[] faceids; Point3d[] i_p_1 = Intersection.MeshLine(base_mesh, line1, out faceids); Point3d[] i_p_2 = Intersection.MeshLine(base_mesh, line2, out faceids); foreach (Point3d p_1 in i_p_1) { pin_to_mesh_distance.Add(pin_position.DistanceTo(p_1)); pin_to_mesh_direction.Add(p_1 - pin_position); } foreach (Point3d p_2 in i_p_2) { pin_to_mesh_distance.Add(pin_position.DistanceTo(p_2)); pin_to_mesh_direction.Add(p_2 - pin_position); } } int min = 0; double min_d = double.MaxValue; for (int i = 0; i < pin_to_mesh_distance.Count; i++) { if (min_d > pin_to_mesh_distance[i]) { min_d = pin_to_mesh_distance[i]; min = i; } } original_position = My_object_functions.GetPosition(new_brep); My_object_functions.TranslateTo(new_brep, original_position + pin_to_mesh_direction[min]); /* * for (int i = 0; i < pin_quantity; i ++) * { * Point3d pin_position = My_object_functions.GetPinPosition(new_brep, i); * Sphere pin_ball_i = new Sphere(pin_position, 2); * pin_ball.Add(pin_ball_i); * } */ pin_ball_list = pin_ball; return(new_brep); }
public override Feature Duplicate() { return(new Surfacing(Name, Surface.DuplicateBrep())); }
private static void CreateFinGeometry(RhinoDoc doc, double parentRadius, double xStart, double xEnd, ref Result result, int count, PositionType positionType, double position, double cant, double thickness, double rootChord, double tabHeight, ref double tabLength, RelativePositionType tabPositionType, List <Point3d> points) { if (tabHeight * tabLength > 0) { List <Point3d> tabPts = new List <Point3d>(); // add points from aft end of fin. double remainingLength = rootChord - tabLength; if (remainingLength < 0) { tabLength = rootChord; remainingLength = 0; } switch (tabPositionType) { case RelativePositionType.Front: tabPts.Add(new Point3d(points[0].X + tabLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X, 0, 0)); break; case RelativePositionType.Center: remainingLength /= 2; tabPts.Add(new Point3d(points[0].X + tabLength + remainingLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, 0, 0)); tabPts.Add(new Point3d(points[0].X, 0, 0)); break; case RelativePositionType.End: tabPts.Add(new Point3d(points[0].X + tabLength, 0, 0)); tabPts.Add(new Point3d(points[0].X + tabLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, -tabHeight, 0)); tabPts.Add(new Point3d(points[0].X + remainingLength, 0, 0)); break; } points.AddRange(tabPts); } Brep brep = null; Polyline curve = new Polyline(points); double xLoc = 0; switch (positionType) { case PositionType.Top: xLoc = xStart + position; break; case PositionType.Bottom: xLoc = xEnd - rootChord + position; break; case PositionType.Middle: xLoc = (xEnd - xStart) / 2 + position; break; case PositionType.After: xLoc = xEnd + position; break; case PositionType.Absolute: xLoc = position; break; } List <Brep> breps = new List <Brep>(); if (curve.IsClosed) { Extrusion ext = Extrusion.Create(curve.ToNurbsCurve(), thickness, true); brep = ext.ToBrep(); Transform trans = Transform.Translation(new Vector3d(0, parentRadius, thickness / 2)); brep.Transform(trans); trans = Transform.Rotation(cant * Math.PI / 180.0, Vector3d.YAxis, new Point3d(rootChord / 2, 0, 0)); brep.Transform(trans); trans = Transform.Translation(new Vector3d(xLoc, 0, 0)); brep.Transform(trans); breps.Add(brep); double deltaAng = 360 / count; for (int i = 1; i < count; i++) { Transform copyTrans = Transform.Rotation(i * deltaAng * Math.PI / 180.0, Vector3d.XAxis, new Point3d(0, 0, 0)); Brep newBrep = brep.DuplicateBrep(); newBrep.Transform(copyTrans); breps.Add(newBrep); } foreach (Brep brp in breps) { if (doc.Objects.AddBrep(brp) != Guid.Empty) { result = Rhino.Commands.Result.Success; } } doc.Views.Redraw(); } }
//====================================================================// public static Brep Clone(this Brep brep) { return(brep.DuplicateBrep()); }
public GsaMember2d Duplicate() { if (this == null) { return(null); } GsaMember2d dup = new GsaMember2d() { Member = new Member() { Group = m_member.Group, IsDummy = m_member.IsDummy, MeshSize = m_member.MeshSize, Name = m_member.Name.ToString(), Offset = m_member.Offset, OrientationAngle = m_member.OrientationAngle, OrientationNode = m_member.OrientationNode, Property = m_member.Property, Topology = m_member.Topology.ToString(), Type = m_member.Type, // GsaToModel.Member2dType((int)Member.Type), Type2D = m_member.Type2D //GsaToModel.AnalysisOrder((int) Member.Type2D) } }; if ((System.Drawing.Color)m_member.Colour != System.Drawing.Color.FromArgb(0, 0, 0)) // workaround to handle that System.Drawing.Color is non-nullable type { dup.m_member.Colour = m_member.Colour; } dup.Member.Offset.X1 = m_member.Offset.X1; dup.Member.Offset.X2 = m_member.Offset.X2; dup.Member.Offset.Y = m_member.Offset.Y; dup.Member.Offset.Z = m_member.Offset.Z; if (m_brep == null) { return(dup); } if (m_brep != null) { dup.m_brep = Brep.DuplicateBrep(); } if (m_crv != null) { dup.m_crv = PolyCurve.DuplicatePolyCurve(); } Point3dList point3Ds = new Point3dList(Topology); dup.Topology = new List <Point3d>(point3Ds.Duplicate()); dup.TopologyType = TopologyType.ToList(); if (void_crvs != null) { dup.void_crvs = new List <PolyCurve>(); dup.void_topo = new List <List <Point3d> >(); dup.void_topoType = new List <List <string> >(); for (int i = 0; i < void_crvs.Count; i++) { dup.void_crvs.Add(void_crvs[i].DuplicatePolyCurve()); Point3dList voidpoint3Ds = new Point3dList(void_topo[i]); dup.void_topo.Add(new List <Point3d>(voidpoint3Ds.Duplicate())); dup.void_topoType.Add(void_topoType[i].ToList()); } } if (incl_Lines != null) { dup.incl_Lines = new List <PolyCurve>(); dup.incLines_topo = new List <List <Point3d> >(); dup.inclLines_topoType = new List <List <string> >(); for (int i = 0; i < incl_Lines.Count; i++) { dup.incl_Lines.Add(incl_Lines[i].DuplicatePolyCurve()); Point3dList inclLinepoint3Ds = new Point3dList(incLines_topo[i]); dup.incLines_topo.Add(new List <Point3d>(inclLinepoint3Ds.Duplicate())); dup.inclLines_topoType.Add(inclLines_topoType[i].ToList()); } } if (m_prop != null) { dup.Property = Property.Duplicate(); } Point3dList inclpoint3Ds = new Point3dList(incl_pts); dup.incl_pts = new List <Point3d>(inclpoint3Ds.Duplicate()); dup.ID = ID; return(dup); }
public static Brep OrientBrep(this Brep b) { Brep bCopy = b.DuplicateBrep(); try { int[][] ef = b.GetEdgeFaces(); //Get Edges by facepair Dictionary <string, int> dictFToE = new Dictionary <string, int>(); for (int i = 0; i < ef.Length; i++) { if (ef[i].Length == 2) { dictFToE.Add(ef[i][0].ToString() + " " + ef[i][1].ToString(), i); dictFToE.Add(ef[i][1].ToString() + " " + ef[i][0].ToString(), i); } } //Get brep edge and their flags //flag will be shifted based on bfs int[][] fe = b.GetFaceEdges(); bool[][] feF = new bool[fe.Length][]; for (int i = 0; i < fe.Length; i++) { feF[i] = new bool[] { true, false, true, false } } ; Curve[][] feC = b.GetFaceCurves(); //Iterate BFS Tuple <List <List <int> >, List <List <int[]> > > brepBFS = NGonsCore.Graphs.UndirectedGraphBfsRhino.BrepBFS(b); for (int i = 0; i < brepBFS.Item2[0].Count; i++) // brepBFS.Item2[0].Count { int[] faces = brepBFS.Item2[0][i]; string pair = faces[0].ToString() + " " + faces[1].ToString(); //Print(pair); int e = dictFToE[pair]; int[] efCurrent = ef[e]; int eLocal0 = Array.IndexOf(fe[faces[0]], e); int eLocal1 = Array.IndexOf(fe[faces[1]], e); //Print(feF[faces[0]][eLocal0].ToString() + " " + feF[faces[1]][eLocal1].ToString()); if (feF[faces[0]][eLocal0] != feF[faces[1]][eLocal1]) { //Print("Yes"); feF[faces[1]] = feF[faces[1]].shiftRight(); } else { //Print("No"); } //Print(feF[faces[0]][eLocal0].ToString() + " " + feF[faces[1]][eLocal1].ToString()); } for (int i = 0; i < fe.Length; i++) { if (!feF[i][0]) { feC[i] = feC[i].Shift(1); bCopy.Faces[i].Transpose(true); } } //FEC = feC; //FEF = feF; //BCopy = bCopy; } catch (Exception e) { Rhino.RhinoApp.WriteLine(e.ToString()); } return(bCopy); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //if first time put the panel geo to memory only once Boolean start = false; if (!DA.GetData(3, ref start)) { return; } if (!ready && start && PathMaker.analysisPoint3d.Count > 0) { Vector3d moveTemp = new Vector3d(0, 0, 0); if (!DA.GetData(4, ref moveTemp)) { return; } List <Brep> panelTemp = new List <Brep>(); Brep baseTemp = null; if (!DA.GetData(1, ref panelTemp)) { return; } if (!DA.GetData(0, ref baseTemp)) { return; } for (int i = 0; i < PathMaker.analysisPoint3d.Count; i++) { List <Brep> panelTemp2 = new List <Brep>(panelTemp); Brep baseTemp2 = baseTemp.DuplicateBrep(); Vector3d totVec = new Vector3d(0, 0, 0); totVec += new Rhino.Geometry.Vector3d(PathMaker.analysisPoint3d[i]); totVec += moveTemp; baseTemp.Translate(totVec); baseGeo.Add(baseTemp); for (int j = 0; j < panelTemp2.Count; j++) { Brep panelTempBrep = panelTemp2[i]; panelTempBrep.Translate(totVec); panelGeo.Add(panelTempBrep); } } if (!DA.GetData(2, ref robo)) { return; } ready = true; } foreach (Double d in analysisResults) { colors.Clear(); if (d < 15) { colors.Add(System.Drawing.Color.FromArgb(0, 255, 0)); } else { int r = 0 + Map((int)d - 15, 0, 85, 0, 255); int g = 255 - Map((int)d - 15, 0, 85, 0, 255); colors.Add(System.Drawing.Color.FromArgb(r, g, 0)); } } if (PathMaker.actionCount > roboLoc) { Vector3d vecMove = new Vector3d(0, 0, 0); Vector3d vecTemp1 = new Vector3d(PathMaker.inputPoints[roboLoc]); Vector3d vecTemp2 = new Vector3d(PathMaker.inputPoints[PathMaker.actionCount]); vecMove += vecTemp2 - vecTemp1; robo.Translate(vecMove); roboLoc = PathMaker.actionCount; } }
public static Brep ReinstallHBEntityFrom(this Brep hbObj, Dictionary <Guid, HBObjEntity> tempEntityHolder) { if (hbObj == null) { return(hbObj); } var honeybeeObj = hbObj.DuplicateBrep(); if (honeybeeObj.Faces.Count > 1 && honeybeeObj.IsSolid) { //This is a room var data = honeybeeObj.GetUserString("HBDataID"); if (string.IsNullOrEmpty(data)) { return(honeybeeObj); } var guid = Guid.Parse(data); var found = tempEntityHolder.TryGetValue(guid, out Entities.HBObjEntity entity); if (!found) { return(honeybeeObj); } if (entity is Entities.RoomEntity roomEnt) { var dup = new Entities.RoomEntity(); dup.Duplicate(roomEnt); honeybeeObj.UserData.Add(dup); } //Now add subSurfaces foreach (var srf in honeybeeObj.Surfaces) { var srfdata = srf.GetUserString("HBDataID"); if (string.IsNullOrEmpty(srfdata)) { throw new ArgumentException("Lost Honeybee data after last step!"); } var srfguid = Guid.Parse(srfdata); var srffound = tempEntityHolder.TryGetValue(srfguid, out Entities.HBObjEntity faceentity); if (!srffound) { throw new ArgumentException("This shouldn't be happening, but still lost Honeybee face data after last step!"); } if (faceentity is Entities.FaceEntity faceEnt) { var dup = new Entities.FaceEntity(); dup.Duplicate(faceEnt); srf.UserData.Add(dup); } //clean temp tag for face srf.GetUserStrings().Remove("HBDataID"); } //clean temp tag for room honeybeeObj.GetUserStrings().Remove("HBDataID"); return(honeybeeObj); } else if (honeybeeObj.Faces.Count == 1) { //TODO: Aperture; //Might never be used. return(honeybeeObj); } else { //TODO: Shading //Might never be used. return(honeybeeObj); } }
public Pipe Duplicate() { Pipe pipe = new Pipe(this.ID, new Line(line.From, line.To), new Plane(plane), radius, new Plane(cutter0), new Plane(cutter1), new Polyline(poly0), new Polyline(poly1), c0, c1); pipe.meshloft = meshloft.DuplicateMesh(); if (pipe.breploft != null) { if (pipe.breploft.IsValid) { pipe.breploft = breploft.DuplicateBrep(); } } foreach (Polyline p in boundingBoxCuts) { pipe.boundingBoxCuts.Add(new Polyline(p)); } foreach (Polyline p in meshProjections) { pipe.meshProjections.Add(new Polyline(p)); } foreach (Line[] p in meshProjectionsLines) { Line[] lines = new Line[p.Length]; for (int i = 0; i < p.Length; i++) { lines[i] = p[i]; } pipe.meshProjectionsLines.Add(lines); } foreach (int nei in this.neiID) { pipe.neiID.Add(nei); } foreach (Line l in drillingHoles) { pipe.drillingHoles.Add(l); } foreach (Plane pln in jointPlanes) { pipe.jointPlanes.Add(new Plane(pln)); } pipe.endJoint0 = new Polyline[this.endJoint0.Length]; for (int i = 0; i < pipe.endJoint0.Length; i++) { pipe.endJoint0[i] = new Polyline(this.endJoint0[i]); } pipe.endJoint1 = new Polyline[this.endJoint1.Length]; for (int i = 0; i < pipe.endJoint1.Length; i++) { pipe.endJoint1[i] = new Polyline(this.endJoint1[i]); } if (PipeJoint0 != null) { pipe.PipeJoint0 = this.PipeJoint0.Duplicate(); } if (PipeJoint1 != null) { pipe.PipeJoint1 = this.PipeJoint1.Duplicate(); } pipe.breploft = this.breploft.DuplicateBrep(); pipe.brepCuts = new List <Brep>(); for (int i = 0; i < this.brepCuts.Count; i++) { pipe.brepCuts.Add(this.brepCuts[i].DuplicateBrep()); } return(pipe); }
public GsaMember2d Duplicate() { GsaMember2d dup = new GsaMember2d { m_member = m_member //add clone or duplicate if available }; if (m_brep != null) { dup.m_brep = m_brep.DuplicateBrep(); } if (m_crv != null) { dup.m_crv = m_crv.DuplicatePolyCurve(); } Point3dList point3Ds = new Point3dList(m_topo); dup.Topology = new List <Point3d>(point3Ds.Duplicate()); dup.TopologyType = m_topoType.ToList(); if (void_crvs != null) { dup.void_crvs = new List <PolyCurve>(); dup.void_topo = new List <List <Point3d> >(); dup.void_topoType = new List <List <string> >(); for (int i = 0; i < void_crvs.Count; i++) { dup.void_crvs.Add(void_crvs[i].DuplicatePolyCurve()); Point3dList voidpoint3Ds = new Point3dList(void_topo[i]); dup.void_topo.Add(new List <Point3d>(voidpoint3Ds.Duplicate())); dup.void_topoType.Add(void_topoType[i].ToList()); } } if (incl_Lines != null) { dup.incl_Lines = new List <PolyCurve>(); dup.incLines_topo = new List <List <Point3d> >(); dup.inclLines_topoType = new List <List <string> >(); for (int i = 0; i < incl_Lines.Count; i++) { dup.incl_Lines.Add(incl_Lines[i].DuplicatePolyCurve()); Point3dList inclLinepoint3Ds = new Point3dList(incLines_topo[i]); dup.incLines_topo.Add(new List <Point3d>(inclLinepoint3Ds.Duplicate())); dup.inclLines_topoType.Add(inclLines_topoType[i].ToList()); } } if (m_prop != null) { dup.Property = m_prop.Duplicate(); } Point3dList inclpoint3Ds = new Point3dList(incl_pts); dup.incl_pts = new List <Point3d>(inclpoint3Ds.Duplicate()); dup.ID = m_id; if (m_prop != null) { dup.Property = m_prop.Duplicate(); } return(dup); }
public DataTree <Brep> Generate3DBuildings(List <OSMWay> ways) { double unitScale = CommonGHProcessors.GetRhinoUnitScale(Rhino.RhinoDoc.ActiveDoc); DataTree <Brep> breps = new DataTree <Brep>(); for (int i = 0; i < ways.Count; i++) { OSMWay currentWay = ways[i]; double height = 0; // Check if there is a building heigh identified foreach (KeyValuePair <string, string> tag in currentWay.Tags) { if (tag.Key.ToLower() == "height") { try { string heightStr = tag.Value.ToLower(); if (heightStr.Contains("m")) { height = Convert.ToDouble(heightStr.Replace("m", string.Empty)) * unitScale; } else if (heightStr.Contains("\'") || heightStr.Contains("\"")) { string[] heightArr = heightStr.Split(new char[] { '\'' }); if (heightArr.Count() == 1) { height = Convert.ToDouble(heightArr[0]); } else { double ft = Convert.ToDouble(heightArr[0]); double inch = Convert.ToDouble(heightArr[1].Replace("\"", string.Empty)); ft += (inch / 12); double metric = ft * 0.30479999024640031211519001231392; height = metric * unitScale; } } else { height = Convert.ToDouble(heightStr) * unitScale; } } catch { } break; } } Vector3d heightVect = new Vector3d(0, 0, height); // Create Polylines if possible List <Polyline> boundaryCrvs = new List <Polyline>(); for (int j = 0; j < currentWay.Points.Count; j++) { List <LINE.Geometry.Point3d> pointList = currentWay.Points[j]; List <Point3d> polyLinePoints = new List <Point3d>(); foreach (LINE.Geometry.Point3d point in pointList) { try { Point3d pt = new Point3d(point.X, point.Y, point.Z); polyLinePoints.Add(pt); } catch { } } if (polyLinePoints.Count > 2) { Polyline pline = new Polyline(polyLinePoints); if (!pline.IsClosed) { pline.Add(pline.First); } //Curve crv = pline.ToNurbsCurve() as Curve; //crv.MakeClosed(0.001); boundaryCrvs.Add(pline); } } // Create the extrued masses as breps if (boundaryCrvs.Count == 1) { try { Line[] ca = boundaryCrvs[0].GetSegments(); List <Curve> crvSegments = new List <Curve>(); foreach (Line line in ca) { crvSegments.Add(line.ToNurbsCurve()); } List <Brep> unjoinedBreps = new List <Brep>(); Curve[] pc = PolyCurve.JoinCurves(crvSegments); Brep[] brepArr = Brep.CreatePlanarBreps(pc); unjoinedBreps.Add(brepArr[0]); // Add the extruded surfaces foreach (Curve crvSeg in crvSegments) { Surface srf = Surface.CreateExtrusion(crvSeg, heightVect); if (srf != null) { unjoinedBreps.Add(srf.ToBrep()); } } //Surface srf2 = Surface.CreateExtrusion(pc[0], heightVect); //Brep brep = srf2.ToBrep(); //unjoinedBreps.Add(brep); Brep top = brepArr[0].DuplicateBrep(); top.Translate(heightVect); unjoinedBreps.Add(top); Brep[] joinedBreps = Brep.JoinBreps(unjoinedBreps, 0.001); breps.Add(joinedBreps[0], new GH_Path(i, 0)); //breps.Add(brep.CapPlanarHoles(0.01), new GH_Path(i, 0)); } catch { breps.Add(null, new GH_Path(i, 0)); } } else if (boundaryCrvs.Count > 1) { try { List <Curve> crvSegments = new List <Curve>(); List <Curve> polyCurves = new List <Curve>(); foreach (Polyline pl in boundaryCrvs) { Line[] ca = pl.GetSegments(); List <Curve> tempCrvs = new List <Curve>(); foreach (Line line in ca) { tempCrvs.Add(line.ToNurbsCurve()); crvSegments.Add(line.ToNurbsCurve()); } polyCurves.Add(PolyCurve.JoinCurves(tempCrvs)[0]); } List <Brep> brepSegments = new List <Brep>(); // Create an initial brep from lofting Brep[] brepArr = Brep.CreatePlanarBreps(polyCurves); Brep baseBrep = brepArr[0]; brepSegments.Add(baseBrep); // Add the extruded surfaces foreach (Curve crvSeg in crvSegments) { Surface srf = Surface.CreateExtrusion(crvSeg, heightVect); if (srf != null) { brepSegments.Add(srf.ToBrep()); } } // move the base surface up Brep topBrep = baseBrep.DuplicateBrep(); topBrep.Translate(heightVect); brepSegments.Add(topBrep); //topBrep.Flip(); Brep[] joinedBreps = Brep.JoinBreps(brepSegments, 0.0001); //BrepSolidOrientation solidOrientation = joinedBreps[0].get_SolidOrientation(); breps.Add(joinedBreps[0], new GH_Path(i, 0)); } catch { breps.Add(null, new GH_Path(i, 0)); } } else { // single point data breps.Add(null, new GH_Path(i, 0)); } //System.Windows.Forms.MessageBox.Show("Current 3d i: " + i.ToString() + "\nBranches: " + breps.BranchCount.ToString()); } return(breps); }