public Body Revolve(Part workPart, Axis axisRotation, Sketch sketch, Line lineSketch, Point3d point3dSketch, double degStart, double degEnd) { //RevolveBulidier NXOpen.Features.Feature nullFeature1 = null; NXOpen.Features.RevolveBuilder revolveBuilder1 = workPart.Features.CreateRevolveBuilder(nullFeature1); //Section Section section1 = workPart.Sections.CreateSection(0.02, 0.02, 0.02); revolveBuilder1.Section = section1; revolveBuilder1.Axis = axisRotation; revolveBuilder1.Tolerance = 0.02; section1.DistanceTolerance = 0.02; section1.ChainingTolerance = 0.02; //Line assignment NXOpen.Features.Feature[] features1 = new NXOpen.Features.Feature[1]; NXOpen.Features.SketchFeature sketchFeature1 = (NXOpen.Features.SketchFeature)sketch.Feature; features1[0] = sketchFeature1; CurveFeatureRule curveFeatureRule1; curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1); section1.AllowSelfIntersection(true); SelectionIntentRule[] rules1 = new SelectionIntentRule[1]; rules1[0] = curveFeatureRule1; NXObject nullNXObject = null; //Selection section1.AddToSection(rules1, lineSketch, nullNXObject, nullNXObject, point3dSketch, NXOpen.Section.Mode.Create, false); revolveBuilder1.Axis = axisRotation; //Sheet Body selection revolveBuilder1.FeatureOptions.BodyType = NXOpen.GeometricUtilities.FeatureOptions.BodyStyle.Sheet; revolveBuilder1.Section = section1; //Ustawienia revolveBuilder1.Limits.StartExtend.Value.RightHandSide = degStart.ToString(); revolveBuilder1.Limits.EndExtend.Value.RightHandSide = degEnd.ToString(); revolveBuilder1.ParentFeatureInternal = false; NXObject feature_revolve1 = revolveBuilder1.CommitFeature(); NXOpen.Features.BodyFeature bodyFeature1 = (NXOpen.Features.BodyFeature)feature_revolve1; Body[] body = bodyFeature1.GetBodies(); return(body[0]); }
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)); }