/// <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="originPoint">投影平面原点</param> /// <param name="normal">投影平面方向</param> public static ProjectCurve CreateProjectCurve(this FeatureCollection features, Point point_to_project, Point3d originPoint, Vector3d normal) { NXOpen.Features.ProjectCurveBuilder projectCurveBuilder = features.CreateProjectCurveBuilder(null); projectCurveBuilder.CurveFitData.Tolerance = 0.025399999999999999; projectCurveBuilder.CurveFitData.AngleTolerance = 0.5; projectCurveBuilder.ProjectionDirectionMethod = NXOpen.Features.ProjectCurveBuilder.DirectionType.AlongFaceNormal; projectCurveBuilder.AngleToProjectionVector.RightHandSide = "0"; Plane plane_to_project_to = WorkPart.Planes.CreatePlane(originPoint, normal, NXOpen.SmartObject.UpdateOption.WithinModeling); plane_to_project_to.SetMethod(NXOpen.PlaneTypes.MethodType.Distance); plane_to_project_to.SetFlip(false); plane_to_project_to.SetReverseSide(false); plane_to_project_to.SetAlternate(NXOpen.PlaneTypes.AlternateType.One); plane_to_project_to.Evaluate(); projectCurveBuilder.SectionToProject.DistanceTolerance = 0.025399999999999999; projectCurveBuilder.SectionToProject.ChainingTolerance = 0.024129999999999999; projectCurveBuilder.SectionToProject.AngleTolerance = 0.5; projectCurveBuilder.PlaneToProjectTo = plane_to_project_to; projectCurveBuilder.SectionToProject.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.CurvesAndPoints); #if NX12 NXOpen.CurveDumbRule curveDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project }); #else NXOpen.CurveDumbRule curveDumbRule = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { point_to_project }); #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); ProjectCurve projectCurve = (ProjectCurve)projectCurveBuilder.Commit(); projectCurveBuilder.SectionToProject.CleanMappingData(); projectCurveBuilder.Destroy(); return(projectCurve); }
/// <summary> /// 测量点到一组对象之间的最短距离,只能是当前工作部件中的对象,可用类型为 Point, Curve, Edge, Face, Body, Datum Plane. /// </summary> /// <param name="measureManager"></param> /// <param name="point">出发点</param> /// <param name="objects"></param> /// <returns>距离值</returns> public static (bool Success, double Distance, Point3d PointOnObjects) MeasureDistance(this MeasureManager measureManager, Point3d point, NXObject[] objects) { try { #if NX12 NXOpen.CurveDumbRule curveDumbRule1 = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { WorkPart.Points.CreatePoint(point) }); #else NXOpen.CurveDumbRule curveDumbRule1 = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(new Point[] { WorkPart.Points.CreatePoint(point) }); #endif ScCollector scCollector1 = WorkPart.ScCollectors.CreateCollector(); scCollector1.ReplaceRules(new SelectionIntentRule[] { curveDumbRule1 }, false); ScCollector scCollector2 = CreateCollector(objects); NXOpen.Unit lengthUnit = WorkPart.UnitCollection.FindObject("MilliMeter"); var minimumMeasure = measureManager.NewScDistance(lengthUnit, MeasureManager.MeasureType.Minimum, true, scCollector1, scCollector2); var measureFeature = minimumMeasure.CreateFeature(); var measureLine = measureFeature.GetEntities()[0] as Line; var minimumDistance = measureLine.GetLength(); Point3d pointOnObjects = measureLine.EndPoint; measureFeature.Delete(); return(true, minimumDistance, pointOnObjects); } catch (Exception) { return(false, 0, new Point3d()); } }
/// <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); }
private static ScCollector CreateCollector(NXObject[] objects) { List <SelectionIntentRule> selectionIntentRules = new List <SelectionIntentRule>(); var baseCurvesInCurrenObjects = objects.Where(obj => obj is IBaseCurve).Select(obj => obj as IBaseCurve).ToArray(); if (baseCurvesInCurrenObjects.Length != 0) { #if NX12 NXOpen.CurveDumbRule curveDumbRule2 = (WorkPart as BasePart).ScRuleFactory.CreateRuleBaseCurveDumb(baseCurvesInCurrenObjects); selectionIntentRules.Add(curveDumbRule2); #else NXOpen.CurveDumbRule curveDumbRule2 = WorkPart.ScRuleFactory.CreateRuleBaseCurveDumb(baseCurvesInCurrenObjects); selectionIntentRules.Add(curveDumbRule2); #endif } var bodiesInCurrenObjects = objects.Where(obj => obj is Body).Select(obj => obj as Body).ToArray(); if (bodiesInCurrenObjects.Length != 0) { #if NX12 var bodyDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleBodyDumb(bodiesInCurrenObjects); selectionIntentRules.Add(bodyDumbRule); #else var bodyDumbRule = WorkPart.ScRuleFactory.CreateRuleBodyDumb(bodiesInCurrenObjects); selectionIntentRules.Add(bodyDumbRule); #endif } var facesInCurrenObjects = objects.Where(obj => obj is Face).Select(obj => obj as Face).ToArray(); if (facesInCurrenObjects.Length != 0) { #if NX12 var faceDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleFaceDumb(facesInCurrenObjects); selectionIntentRules.Add(faceDumbRule); #else var faceDumbRule = WorkPart.ScRuleFactory.CreateRuleFaceDumb(facesInCurrenObjects); selectionIntentRules.Add(faceDumbRule); #endif } var edgesInCurrenObjects = objects.Where(obj => obj is Edge).Select(obj => obj as Edge).ToArray(); if (edgesInCurrenObjects.Length != 0) { #if NX12 var edgeDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleEdgeDumb(edgesInCurrenObjects); selectionIntentRules.Add(edgeDumbRule); #else var edgeDumbRule = WorkPart.ScRuleFactory.CreateRuleEdgeDumb(edgesInCurrenObjects); selectionIntentRules.Add(edgeDumbRule); #endif } var pointsInCurrenObjects = objects.Where(obj => obj is Point).Select(obj => obj as Point).ToArray(); if (pointsInCurrenObjects.Length != 0) { #if NX12 var pointDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleCurveDumbFromPoints(pointsInCurrenObjects); #else var pointDumbRule = WorkPart.ScRuleFactory.CreateRuleCurveDumbFromPoints(pointsInCurrenObjects); #endif selectionIntentRules.Add(pointDumbRule); } var datumplanesInCurrenObjects = objects.Where(obj => obj is DatumPlane).Select(obj => obj as DatumPlane).ToArray(); if (datumplanesInCurrenObjects.Length != 0) { #if NX12 var datumDumbRule = (WorkPart as BasePart).ScRuleFactory.CreateRuleFaceDatum(datumplanesInCurrenObjects); selectionIntentRules.Add(datumDumbRule); #else var datumDumbRule = WorkPart.ScRuleFactory.CreateRuleFaceDatum(datumplanesInCurrenObjects); selectionIntentRules.Add(datumDumbRule); #endif } var collector = WorkPart.ScCollectors.CreateCollector(); collector.ReplaceRules(selectionIntentRules.ToArray(), false); return(collector); }