/// <summary> /// 沿面的法向投影曲线 /// </summary> /// <param name="features"></param> /// <param name="curves"></param> /// <param name="faces_to_project_to"></param> /// <returns></returns> public static ProjectCurve CreateProjectCurve(this FeatureCollection features, IBaseCurve[] curves, Face[] faces_to_project_to) { NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null); projectCurveBuilder.CurveFitData.Tolerance = 0.01; projectCurveBuilder.CurveFitData.AngleTolerance = 0.5; projectCurveBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongFaceNormal; projectCurveBuilder.SectionToProject.DistanceTolerance = 0.01; projectCurveBuilder.SectionToProject.ChainingTolerance = 0.0094999999999999998; projectCurveBuilder.SectionToProject.AngleTolerance = 0.5; projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints); #if NX12 NXOpen.CurveDumbRule curveDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleBaseCurveDumb(curves); #else NXOpen.CurveDumbRule curveDumbRule = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(curves); #endif projectCurveBuilder.SectionToProject.AllowSelfIntersection(true); NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1] { curveDumbRule }; projectCurveBuilder.SectionToProject.AddToSection(rules1, null, null, null, new Point3d(), NXOpen.Section.Mode.Create, false); NXOpen.ScCollector scCollector1 = WorkPart.ScCollectors.CreateCollector(); #if NX12 NXOpen.FaceDumbRule faceDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to); #else NXOpen.FaceDumbRule faceDumbRule = WorkPart.ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to); #endif NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1] { faceDumbRule }; scCollector1.ReplaceRules(rules2, false); bool added1 = projectCurveBuilder.FaceToProjectTo.Add(scCollector1); ProjectCurve nXObject1 = (ProjectCurve)projectCurveBuilder.Commit(); projectCurveBuilder.SectionToProject.CleanMappingData(); projectCurveBuilder.Destroy(); return(nXObject1); }
/// <summary> /// 投影点 /// </summary> /// <param name="features"></param> /// <param name="point_to_project">要投影的点</param> /// <param name="faces_to_project_to">投影到的面</param> /// <param name="project_direction3d">投影方向,正反向均可</param> /// <returns></returns> public static ProjectCurve CreateProjectCurve(this FeatureCollection features, Point point_to_project, Face[] faces_to_project_to, Vector3d project_direction3d) { NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null); projectCurveBuilder.CurveFitData.Tolerance = 0.01; projectCurveBuilder.CurveFitData.AngleTolerance = 0.5; projectCurveBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongVector; projectCurveBuilder.AngleToProjectionVector.RightHandSide = "0"; projectCurveBuilder.SectionToProject.DistanceTolerance = 0.01; projectCurveBuilder.SectionToProject.ChainingTolerance = 0.0095; projectCurveBuilder.SectionToProject.AngleTolerance = 0.5; projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints); #if NX12 NXOpen.CurveDumbRule curveDumbRule1 = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project }); #else NXOpen.CurveDumbRule curveDumbRule1 = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project }); #endif projectCurveBuilder.SectionToProject.AllowSelfIntersection(true); NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1] { curveDumbRule1 }; projectCurveBuilder.SectionToProject.AddToSection(rules1, null, null, null, new Point3d(), NXOpen.Section.Mode.Create, false); NXOpen.ScCollector scCollector = WorkPart.ScCollectors.CreateCollector(); #if NX12 NXOpen.FaceDumbRule faceDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to); #else NXOpen.FaceDumbRule faceDumbRule = WorkPart.ScRuleFactory.CreateRuleFaceDumb(faces_to_project_to); #endif NXOpen.SelectionIntentRule[] rules2 = new NXOpen.SelectionIntentRule[1] { faceDumbRule }; scCollector.ReplaceRules(rules2, false); bool added1 = projectCurveBuilder.FaceToProjectTo.Add(scCollector); NXOpen.Direction direction = WorkPart.Directions.CreateDirection(new Point3d(), project_direction3d, NXOpen.SmartObject.UpdateOption.WithinModeling); projectCurveBuilder.ProjectionVector = direction; projectCurveBuilder.ProjectionOption = ProjectCurveBuilder.ProjectionOptionType.ProjectBothSides; ProjectCurve nXObject = (ProjectCurve)projectCurveBuilder.Commit(); projectCurveBuilder.SectionToProject.CleanMappingData(); projectCurveBuilder.Destroy(); return(nXObject); }