/// <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(); } }
/// <summary> /// 创建圆柱特征 /// </summary> /// <param name="zAxis">轴</param> /// <param name="centerPt">中心点</param> /// <param name="offset"></param> /// <param name="toolingBoxFeature"></param> /// <param name="objs"></param> /// <returns></returns> public static ToolingBox CreateToolingCylinder(Vector3d zAxis, Point3d centerPt, double[] offset, ToolingBox toolingBoxFeature = null, params TaggedObject[] objs) { Part workPart = theSession.Parts.Work; SelectionRuleFactory rules = new SelectionRuleFactory(objs.ToList()); //ToolingBox nullToolingBox = null; ToolingBoxBuilder toolingBoxBuilder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(toolingBoxFeature); toolingBoxBuilder.Type = ToolingBoxBuilder.Types.BoundedCylinder; Direction dir = workPart.Directions.CreateDirection(centerPt, zAxis, SmartObject.UpdateOption.WithinModeling); toolingBoxBuilder.AxisVector = dir; toolingBoxBuilder.RadialOffset.Value = offset[2]; toolingBoxBuilder.OffsetPositiveZ.Value = offset[0]; toolingBoxBuilder.OffsetNegativeZ.Value = offset[1]; // toolingBoxBuilder.SingleOffset = false; ScCollector scCollector = toolingBoxBuilder.BoundedObject; scCollector.ReplaceRules(rules.CreateSelectionRule().ToArray(), false); toolingBoxBuilder.CalculateBoxSize(); NXObject[] selections = new NXObject[1]; NXObject[] deselections = new NXObject[1]; selections[0] = (NXObject)objs[0]; toolingBoxBuilder.SetSelectedOccurrences(selections, deselections); toolingBoxBuilder.CalculateBoxSize(); NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox"); try { return(toolingBoxBuilder.CommitFeature() as ToolingBox); } catch (Exception ex) { LogMgr.WriteLog("Basic.ToolingFeature.CreateToolingBox:错误:" + ex.Message); return(null); } finally { toolingBoxBuilder.Destroy(); theSession.UpdateManager.DoUpdate(markId); theSession.DeleteUndoMark(markId, "End ToolingBox"); } }
/// <summary> /// 创建拉伸特征 /// </summary> /// <param name="vec">向量</param> /// <param name="start">起始</param> /// <param name="end">终止</param> /// <param name="extrude">lastez</param> /// <param name="line">线</param> /// <returns></returns> public static NXOpen.Features.Feature CreateExtrude(Vector3d vec, string start, string end, NXOpen.Features.Feature extrude = null, params TaggedObject[] line) { Session theSession = Session.GetSession(); Part workPart = theSession.Parts.Work; SelectionRuleFactory rules = new SelectionRuleFactory(line.ToList()); NXOpen.Features.Feature nullNXOpen_Features_Feature = null; NXOpen.Features.ExtrudeBuilder extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature); NXOpen.Section section1 = workPart.Sections.CreateSection(); extrudeBuilder1.Section = section1; extrudeBuilder1.Limits.StartExtend.Value.RightHandSide = start; extrudeBuilder1.Limits.EndExtend.Value.RightHandSide = end; NXOpen.Point3d origin1 = new NXOpen.Point3d(0.0, 0.0, 0.0); NXOpen.Direction direction1; direction1 = workPart.Directions.CreateDirection(origin1, vec, NXOpen.SmartObject.UpdateOption.WithinModeling); NXOpen.NXObject nullNXOpen_NXObject = null; section1.AddToSection(rules.CreateSelectionRule().ToArray(), (NXObject)line[0], nullNXOpen_NXObject, nullNXOpen_NXObject, origin1, NXOpen.Section.Mode.Create, false); extrudeBuilder1.Direction = direction1; NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start Extruded"); try { return(extrudeBuilder1.CommitFeature()); } catch (NXException ex) { LogMgr.WriteLog("ExtrudedUtils:CreateExtruded:" + ex.Message); throw ex; } finally { extrudeBuilder1.Destroy(); theSession.UpdateManager.DoUpdate(markId); theSession.DeleteUndoMark(markId, "End Extruded"); } }
/// <summary> /// 创建方块盒 /// </summary> /// <param name="matr">矩阵</param> /// <param name="centerPt">中心坐标</param> /// <param name="offset">偏置 offset[6]</param> /// <param name="toolingBoxFeature">方块盒特征</param> /// <param name="objs"></param> /// <returns></returns> public static ToolingBox CreateToolingBlockBox(Matrix3x3 matr, Point3d centerPt, double[] offset, ToolingBox toolingBoxFeature = null, params TaggedObject[] objs) { Part workPart = theSession.Parts.Work; SelectionRuleFactory rules = new SelectionRuleFactory(objs.ToList()); //ToolingBox nullToolingBox = null; ToolingBoxBuilder toolingBoxBuilder = workPart.Features.ToolingFeatureCollection.CreateToolingBoxBuilder(toolingBoxFeature); toolingBoxBuilder.Type = ToolingBoxBuilder.Types.BoundedBlock; toolingBoxBuilder.OffsetPositiveX.Value = offset[0]; toolingBoxBuilder.OffsetNegativeX.Value = offset[1]; toolingBoxBuilder.OffsetPositiveY.Value = offset[2]; toolingBoxBuilder.OffsetNegativeY.Value = offset[3]; toolingBoxBuilder.OffsetPositiveZ.Value = offset[4]; toolingBoxBuilder.OffsetNegativeZ.Value = offset[5]; toolingBoxBuilder.SingleOffset = false; toolingBoxBuilder.SetBoxMatrixAndPosition(matr, centerPt); ScCollector scCollector = toolingBoxBuilder.BoundedObject; scCollector.ReplaceRules(rules.CreateSelectionRule().ToArray(), false); toolingBoxBuilder.CalculateBoxSize(); NXOpen.Session.UndoMarkId markId = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Start ToolingBox"); try { return(toolingBoxBuilder.CommitFeature() as ToolingBox); } catch (Exception ex) { LogMgr.WriteLog("Basic.ToolingFeature.CreateToolingBox:错误:" + ex.Message); return(null); } finally { toolingBoxBuilder.Destroy(); theSession.UpdateManager.DoUpdate(markId); theSession.DeleteUndoMark(markId, "End ToolingBox"); } }