public static Brep ToRhinoBrep(NXOpen.Body body) { if (false) { Brep brep = new Brep(); for (int i = 0; i < body.GetFaces().Length; i++) { AddNXFace(body.GetFaces()[i], brep); } return(brep); } else { return(JoinAndMerge(body.GetFaces().Select(x => ToRhinoBrep(x)).ToArray(), Globals.DistanceTolerance)); } }
static RevSurface ToRhinoRevSurface(NXOpen.Face face, FaceEx.FaceData faceData) { var bodyFeatures = face.GetBody().GetFeatures(); var revolveFeature = bodyFeatures.FirstOrDefault(obj => obj is NXOpen.Features.Revolve); Curve faceSectionCurve = default; double startRadian = 0.0; double endRadian = Math.PI * 2; if (revolveFeature != null) { NXOpen.Features.RevolveBuilder revolveBuilder = WorkPart.Features.CreateRevolveBuilder(revolveFeature); revolveBuilder.Section.GetOutputCurves(out var sectionCurves); startRadian = revolveBuilder.Limits.StartExtend.Value.Value * Math.PI / 180.0; endRadian = revolveBuilder.Limits.EndExtend.Value.Value * Math.PI / 180.0; revolveBuilder.Destroy(); for (int i = 0; i < sectionCurves.Length; i++) { var baseCurve = sectionCurves[i] as NXOpen.IBaseCurve; var curveMidPt = baseCurve.GetPoint(0.5); if (curveMidPt.DistanceTo(face.Tag).Distance < DistanceTolerance) { faceSectionCurve = baseCurve.ToRhinoCurve(); break; } } } else { var faceBoundingBox = face.GetAlignedBoundingBox(faceData.Direction); var point1 = faceData.Point.Move(faceData.Direction, faceBoundingBox.Height * 1.5); var faceMidPoint = face.GetPoint(); // 求与旋转方向垂直,并且位于面上的方向 var verticalDirection = faceData.Direction.CrossProduct(faceMidPoint.Subtract(faceData.Point)).CrossProduct(faceData.Direction); var point2 = point1.Move(verticalDirection, faceBoundingBox.Length * 1.5); var point3 = point2.Move(faceData.Direction.Reverse(), faceBoundingBox.Height * 3); var point4 = point3.Move(verticalDirection.Reverse(), faceBoundingBox.Length * 1.5); NXOpen.Session.UndoMarkId undoMarkId = TheSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Calc Rev Profile"); NXOpen.Body fourPointSurface = WorkPart.Features.CreateFourPointSurface(point1, point2, point3, point4); try { NXOpen.Features.IntersectionCurve intersectionCurveFeature = WorkPart.Features.CreateIntersectionCurve(fourPointSurface.GetFaces(), face); faceSectionCurve = (intersectionCurveFeature.GetEntities()[0] as NXOpen.Curve).ToRhino(); intersectionCurveFeature.Delete(); fourPointSurface.Delete(); } catch (Exception) { TheSession.UndoToMark(undoMarkId, "Calc Rev Profile"); Console.WriteLine($"无法创建面 {face.Tag} 的交线"); return(null); } finally { TheSession.DeleteUndoMark(undoMarkId, "Calc Rev Profile"); } } return(RevSurface.Create(faceSectionCurve, new Line(faceData.Point.ToRhino(), faceData.Point.Move(faceData.Direction, 10.0).ToRhino()), startRadian, endRadian)); }