/// <summary> /// 布尔操作 /// </summary> /// <param name="targetBody">目标体</param> /// <param name="toolBody">工具体</param> /// <param name="copyTools">复制工具</param> /// <param name="type">类型</param> /// <returns></returns> public static NXOpen.Features.BooleanFeature CreateBooleanFeature(Body targetBody, bool copyTargets, bool copyTools, NXOpen.Features.Feature.BooleanType type, params Body[] toolBody) { Part workPart = theSession.Parts.Work; NXOpen.Features.BooleanFeature nullNXOpen_Features_BooleanFeature = null; NXOpen.Features.BooleanBuilder booleanBuilder1 = workPart.Features.CreateBooleanBuilderUsingCollector(nullNXOpen_Features_BooleanFeature); booleanBuilder1.CopyTargets = copyTargets; booleanBuilder1.CopyTools = copyTools; booleanBuilder1.Operation = type; bool added1 = booleanBuilder1.Targets.Add(targetBody); NXOpen.ScCollector scCollector = workPart.ScCollectors.CreateCollector(); ISelectionRule rule = new SelectionBodyRule(toolBody.ToList()); SelectionIntentRule[] rules = { rule.CreateSelectionRule() }; scCollector.ReplaceRules(rules, false); booleanBuilder1.ToolBodyCollector = scCollector; try { NXOpen.Features.Feature boolFeature = booleanBuilder1.CommitFeature(); return(boolFeature as NXOpen.Features.BooleanFeature); } catch (NXException ex) { LogMgr.WriteLog("Basic.BooleanUtils.CreateBooleanFeature:错误:" + ex.Message); throw ex; } finally { booleanBuilder1.Destroy(); } }
/// <summary> /// 设置加工面 /// </summary> /// <param name="faces"></param> public void SetGeometry(params Face[] faces) { NXOpen.CAM.SurfaceContourBuilder builder1; builder1 = workPart.CAMSetup.CAMOperationCollection.CreateSurfaceContourBuilder(this.Oper); builder1.FeedsBuilder.SetMachiningData(); NXOpen.CAM.GeometrySetList geometrySetList; geometrySetList = builder1.CutAreaGeometry.GeometryList; NXOpen.CAM.GeometrySet geometrySet2; geometrySet2 = builder1.CutAreaGeometry.CreateGeometrySet(); geometrySetList.Append(geometrySet2); NXOpen.ScCollector scCollector1 = geometrySet2.ScCollector; ISelectionRule rule = new SelectionFaceRule(faces.ToList()); SelectionIntentRule[] rules = new SelectionIntentRule[1] { rule.CreateSelectionRule() }; scCollector1.ReplaceRules(rules, false); try { builder1.Commit(); } catch (NXException ex) { LogMgr.WriteLog("SurfaceContourModel.SetGeometry 错误" + ex.Message); } finally { builder1.Destroy(); } }
/// <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="targetBody">目标体</param> /// <param name="toolBody">工具体</param> /// <param name="copyTools">复制工具</param> /// <param name="type">类型</param> /// <returns></returns> public static NXOpen.Features.BooleanFeature CreateBooleanFeature(Body targetBody, Body toolBody, bool copyTools, NXOpen.Features.Feature.BooleanType type) { Part workPart = theSession.Parts.Work; NXOpen.Features.BooleanFeature nullNXOpen_Features_BooleanFeature = null; NXOpen.Features.BooleanBuilder booleanBuilder1 = workPart.Features.CreateBooleanBuilderUsingCollector(nullNXOpen_Features_BooleanFeature); //ScCollector scCollector1 = booleanBuilder1.ToolBodyCollector; // NXOpen.GeometricUtilities.BooleanRegionSelect booleanRegionSelect1 = booleanBuilder1.BooleanRegionSelect; booleanBuilder1.CopyTools = copyTools; booleanBuilder1.Operation = type; bool added1 = booleanBuilder1.Targets.Add(targetBody); //NXOpen.TaggedObject[] targets1 = new NXOpen.TaggedObject[1]; //targets1[0] = targetBody; //booleanRegionSelect1.AssignTargets(targets1); NXOpen.ScCollector scCollector = workPart.ScCollectors.CreateCollector(); TaggedObject[] obj = { toolBody }; SelectionRuleFactory fac = new SelectionRuleFactory(obj.ToList()); //Body[] bodies1 = { toolBody }; //BodyDumbRule bodyDumbRule1 = workPart.ScRuleFactory.CreateRuleBodyDumb(bodies1, true); //SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1]; //rules1[0] = bodyDumbRule1; scCollector.ReplaceRules(fac.CreateSelectionRule().ToArray(), false); booleanBuilder1.ToolBodyCollector = scCollector; //NXOpen.TaggedObject[] targets2 = new NXOpen.TaggedObject[1]; //targets2[0] = toolBody; //booleanRegionSelect1.AssignTargets(targets2); try { NXOpen.Features.Feature boolFeature = booleanBuilder1.CommitFeature(); return(boolFeature as NXOpen.Features.BooleanFeature); } catch (Exception ex) { LogMgr.WriteLog("Basic.BooleanUtils.CreateBooleanFeature:错误:" + ex.Message); return(null); } finally { booleanBuilder1.Destroy(); } }
/// <summary> /// 创建修剪特征 /// </summary> /// <param name="planeFace"></param> /// <param name="isFlip"></param> /// <param name="isok"></param> /// <param name="bodys"></param> /// <returns></returns> public static NXOpen.Features.TrimBody2 CreateTrimBodyFeature(Face planeFace, bool isFlip, out bool isok, params Body[] bodys) { Part workPart = theSession.Parts.Work; NXOpen.Features.TrimBody2 nullNXOpen_Features_TrimBody2 = null; NXOpen.Features.TrimBody2Builder trimBody2Builder1 = workPart.Features.CreateTrimBody2Builder(nullNXOpen_Features_TrimBody2); List <TaggedObject> tgs = new List <TaggedObject>(); foreach (Body body in bodys) { tgs.Add(body); } SelectionRuleFactory fac = new SelectionRuleFactory(tgs); NXOpen.Plane plane1 = null; try { plane1 = PlaneUtils.CreatePlaneOfFace(planeFace, isFlip); } catch (NXException ex) { LogMgr.WriteLog("Basic.TrimBody:CreateTrimBodyFeature:" + ex.Message); throw ex; } trimBody2Builder1.BooleanTool.FacePlaneTool.ToolPlane = plane1; trimBody2Builder1.BooleanTool.ToolOption = NXOpen.GeometricUtilities.BooleanToolBuilder.BooleanToolType.NewPlane; NXOpen.ScCollector scCollector1 = workPart.ScCollectors.CreateCollector(); scCollector1.ReplaceRules(fac.CreateSelectionRule().ToArray(), false); trimBody2Builder1.TargetBodyCollector = scCollector1; try { isok = true; return(trimBody2Builder1.CommitFeature() as NXOpen.Features.TrimBody2); } catch (Exception ex) { LogMgr.WriteLog("Basic.TrimBody:CreateTrimBodyFeature:" + ex.Message); throw ex; } finally { trimBody2Builder1.Destroy(); } }
public void SetGeometry(params Face[] faces) { NXOpen.CAM.ZLevelMillingBuilder builder1; try { builder1 = workPart.CAMSetup.CAMOperationCollection.CreateZlevelMillingBuilder(this.Oper); } catch (NXException ex) { throw ex; } builder1.FeedsBuilder.SetMachiningData(); NXOpen.CAM.GeometrySetList geometrySetList; geometrySetList = builder1.CutAreaGeometry.GeometryList; NXOpen.CAM.GeometrySet geometrySet2; geometrySet2 = builder1.CutAreaGeometry.CreateGeometrySet(); geometrySetList.Append(geometrySet2); NXOpen.ScCollector scCollector1 = geometrySet2.ScCollector; ISelectionRule rule = new SelectionFaceRule(faces.ToList()); SelectionIntentRule[] rules = new SelectionIntentRule[1] { rule.CreateSelectionRule() }; scCollector1.ReplaceRules(rules, false); try { builder1.Commit(); } catch (NXException ex) { throw ex; } finally { builder1.Destroy(); } }
/// <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); }
public void CreateBracket(double thickness, double length, double height, double holeradius, double holedistance) { NXOpen.Point3d point1 = new NXOpen.Point3d(0, 0, 0); NXOpen.Point3d point2 = new NXOpen.Point3d(0, 0, height); NXOpen.Point3d point3 = new NXOpen.Point3d(0, thickness, height); NXOpen.Point3d point4 = new NXOpen.Point3d(0, thickness, thickness); NXOpen.Point3d point5 = new NXOpen.Point3d(0, length, thickness); NXOpen.Point3d point6 = new NXOpen.Point3d(0, length, 0); IBaseCurve[] curves1 = new IBaseCurve[6] { workPart.Curves.CreateLine(point1, point2), workPart.Curves.CreateLine(point2, point3), workPart.Curves.CreateLine(point3, point4), workPart.Curves.CreateLine(point4, point5), workPart.Curves.CreateLine(point5, point6), workPart.Curves.CreateLine(point6, point1) }; CreateExtrude(curves1, true, 52.0, new Vector3d(1.0, 0, 0)); //Left Line NXOpen.Point3d point7 = new NXOpen.Point3d(-21.0, 0, height - 8.0); NXOpen.Point3d point8 = new NXOpen.Point3d(-21, 0, height - 16.0); //Right LIne NXOpen.Point3d point9 = new NXOpen.Point3d(-15, 0, height - 16.0); NXOpen.Point3d point10 = new NXOpen.Point3d(-15, 0, height - 8.0); //Top Arc NXOpen.Point3d Center1 = new NXOpen.Point3d(-18, 0, height - 8.0); NXOpen.Vector3d dir1 = new NXOpen.Vector3d(-1.0, 0, 0); NXOpen.Vector3d dir2 = new NXOpen.Vector3d(0, 0, -1.0); //Bottom Arc NXOpen.Point3d Center2 = new NXOpen.Point3d(-18, 0, height - 16.0); IBaseCurve[] curves2 = new IBaseCurve[4] { workPart.Curves.CreateLine(point7, point8), workPart.Curves.CreateArc(Center2, dir1, dir2, 3.0, 0, Math.PI), workPart.Curves.CreateLine(point9, point10), workPart.Curves.CreateArc(Center1, dir1, dir2, 3.0, Math.PI, 2 * Math.PI) }; //Right Side //Left Line NXOpen.Point3d point11 = new NXOpen.Point3d(21.0, 0, height - 8.0); NXOpen.Point3d point12 = new NXOpen.Point3d(21, 0, height - 16.0); //Right LIne NXOpen.Point3d point13 = new NXOpen.Point3d(15, 0, height - 16.0); NXOpen.Point3d point14 = new NXOpen.Point3d(15, 0, height - 8.0); //Top Arc NXOpen.Point3d Center3 = new NXOpen.Point3d(18, 0, height - 8.0); //Bottom Arc NXOpen.Point3d Center4 = new NXOpen.Point3d(18, 0, height - 16.0); IBaseCurve[] curves3 = new IBaseCurve[4] { workPart.Curves.CreateLine(point11, point12), workPart.Curves.CreateArc(Center4, dir1, dir2, 3.0, 0, Math.PI), workPart.Curves.CreateLine(point13, point14), workPart.Curves.CreateArc(Center3, dir1, dir2, 3.0, Math.PI, 2 * Math.PI) }; CreateExtrude(curves2, false, 2.0 * thickness, new Vector3d(0, 1, 0)); CreateExtrude(curves3, false, 2.0 * thickness, new Vector3d(0, 1, 0)); //EdgeBlend Start NXOpen.Features.EdgeBlendBuilder edgeBlendBuilder1 = workPart.Features.CreateEdgeBlendBuilder(null); NXOpen.ScCollector scCollector1 = workPart.ScCollectors.CreateCollector(); NXOpen.Edge[] seedEdges1 = new NXOpen.Edge[2]; NXOpen.Features.Extrude extrude1 = (NXOpen.Features.Extrude)workPart.Features.ToArray().OfType <NXOpen.Features.Extrude>().First(); Edge[] edges = extrude1.GetBodies()[0].GetEdges(); NXOpen.Point3d edgeendpoint1 = new NXOpen.Point3d(26, 0, height); NXOpen.Point3d edgeendpoint2 = new NXOpen.Point3d(26, thickness, height); NXOpen.Point3d edgeendpoint3 = new NXOpen.Point3d(-26, 0, height); NXOpen.Point3d edgeendpoint4 = new NXOpen.Point3d(-26, thickness, height); Edge edge1 = null; Edge edge2 = null; for (int i = 0; i < edges.Length; i++) { NXOpen.Point3d endpoint; NXOpen.Point3d endpoint2; edges[i].GetVertices(out endpoint, out endpoint2); if (Math.Abs(edgeendpoint1.X - endpoint.X) < .01 && Math.Abs(edgeendpoint1.Y - endpoint.Y) < .01 && Math.Abs(edgeendpoint1.Z - endpoint.Z) < .01 && Math.Abs(edgeendpoint2.X - endpoint2.X) < .01 && Math.Abs(edgeendpoint2.Y - endpoint2.Y) < .01 && Math.Abs(edgeendpoint2.Z - endpoint2.Z) < .01) { edge1 = edges[i]; } else if (Math.Abs(edgeendpoint3.X - endpoint.X) < .01 && Math.Abs(edgeendpoint3.Y - endpoint.Y) < .01 && Math.Abs(edgeendpoint3.Z - endpoint.Z) < .01 && Math.Abs(edgeendpoint4.X - endpoint2.X) < .01 && Math.Abs(edgeendpoint4.Y - endpoint2.Y) < .01 && Math.Abs(edgeendpoint4.Z - endpoint2.Z) < .01) { edge2 = edges[i]; } if (edge1 != null && edge2 != null) { break; } } seedEdges1[0] = edge1; seedEdges1[1] = edge2; NXOpen.EdgeMultipleSeedTangentRule edgeMultipleSeedTangentRule1; edgeMultipleSeedTangentRule1 = workPart.ScRuleFactory.CreateRuleEdgeMultipleSeedTangent(seedEdges1, 0.5, true); NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1]; rules1[0] = edgeMultipleSeedTangentRule1; scCollector1.ReplaceRules(rules1, false); int csIndex1; csIndex1 = edgeBlendBuilder1.AddChainset(scCollector1, "8"); edgeBlendBuilder1.CommitFeature(); edgeBlendBuilder1.Destroy(); //EdgeBlend End //Circle's Extrude NXOpen.Point3d holecenter1 = new NXOpen.Point3d(holedistance / 2, 20, 10); NXOpen.Point3d holecenter2 = new NXOpen.Point3d(-holedistance / 2, 20, 10); NXOpen.Vector3d dir3 = new NXOpen.Vector3d(0, -1.0, 0); NXOpen.Vector3d dir4 = new NXOpen.Vector3d(1, 0, 0); IBaseCurve[] hole1 = new IBaseCurve[1] { workPart.Curves.CreateArc(holecenter1, dir3, dir4, holeradius, 0, 2 * Math.PI), }; IBaseCurve[] hole2 = new IBaseCurve[1] { workPart.Curves.CreateArc(holecenter2, dir3, dir4, holeradius, 0, 2 * Math.PI), }; CreateExtrude(hole1, false, 2 * thickness, new Vector3d(0, 0, 1)); CreateExtrude(hole2, false, 2 * thickness, new Vector3d(0, 0, 1)); //Big Slot //Top Line NXOpen.Point3d slotpt1 = new NXOpen.Point3d(-6, 44, 0); NXOpen.Point3d slotpt2 = new NXOpen.Point3d(-6, length - 14.0, 0); //BOttom Line NXOpen.Point3d slotpt4 = new NXOpen.Point3d(6, 44, 0); NXOpen.Point3d slotpt3 = new NXOpen.Point3d(6, length - 14.0, 0); //Right Arc NXOpen.Point3d slotcenter1 = new NXOpen.Point3d(0, 44, 0); //Left Arc NXOpen.Point3d slotcenter2 = new NXOpen.Point3d(0, length - 14.0, 0); IBaseCurve[] slotcurve = new IBaseCurve[4] { workPart.Curves.CreateLine(slotpt1, slotpt2), workPart.Curves.CreateArc(slotcenter2, dir3, dir4, 6.0, Math.PI / 2, 3 * Math.PI / 2), workPart.Curves.CreateLine(slotpt3, slotpt4), workPart.Curves.CreateArc(slotcenter1, dir3, dir4, 6.0, -Math.PI / 2, Math.PI / 2) }; CreateExtrude(slotcurve, false, 2 * thickness, new Vector3d(0, 0, 1)); //Curvey Part //bottom Arc NXOpen.Point3d botarc = new NXOpen.Point3d(26, 44, 0); //bottom line NXOpen.Point3d botpt1 = new NXOpen.Point3d(14, 44, 0); NXOpen.Point3d botpt2 = new NXOpen.Point3d(14, length - 14.0, 0); //Big Arc NXOpen.Point3d sidearc = new NXOpen.Point3d(0, length - 14.0, 0); //Top Line NXOpen.Point3d toppt2 = new NXOpen.Point3d(-14, 44, 0); NXOpen.Point3d toppt1 = new NXOpen.Point3d(-14, length - 14.0, 0); //Right Arc NXOpen.Point3d toparc = new NXOpen.Point3d(-26, 44, 0); //OUtline NXOpen.Point3d out1 = new NXOpen.Point3d(-26, 32, 0); NXOpen.Point3d out2 = new NXOpen.Point3d(-28, 32, 0); NXOpen.Point3d out3 = new NXOpen.Point3d(-28, length + 10, 0); NXOpen.Point3d out4 = new NXOpen.Point3d(28, length + 10, 0); NXOpen.Point3d out5 = new NXOpen.Point3d(28, 32, 0); NXOpen.Point3d out6 = new NXOpen.Point3d(26, 32, 0); IBaseCurve[] bigcutcurve = new IBaseCurve[10] { workPart.Curves.CreateArc(botarc, dir3, dir4, 12, -Math.PI / 2, 0), workPart.Curves.CreateLine(botpt1, botpt2), workPart.Curves.CreateArc(sidearc, dir3, dir4, 14, Math.PI / 2, 3 * Math.PI / 2), workPart.Curves.CreateLine(toppt1, toppt2), workPart.Curves.CreateArc(toparc, dir3, dir4, 12, 0, Math.PI / 2), workPart.Curves.CreateLine(out1, out2), workPart.Curves.CreateLine(out2, out3), workPart.Curves.CreateLine(out3, out4), workPart.Curves.CreateLine(out4, out5), workPart.Curves.CreateLine(out5, out6) }; CreateExtrude(bigcutcurve, false, 2 * thickness, new Vector3d(0, 0, 1)); }