C# NX二次开发:在多个体的模型中如何实现拉伸操作布尔减

129 阅读2分钟

大家好,今天接着上一篇拉伸文章去讲。

UF_MODL_create_extruded1 (view source)

uf_list_p_t objects Input List of objects to be extruded. char * taper_angle Input Taper angle (in degrees). char * limit [ 2 ] Input Limit of extrusion. This is declared as: char limit[2]. The first value is the start value of the extrusion and the second value is the end of the extrusion (see the example program). double point [ 3 ] Input not used double direction [ 3 ] Input Extrusion axis. UF_FEATURE_SIGN sign Input The sign of the operation to be performed. UF_NULLSIGN = create new target solid UF_POSITIVE = add to target solid UF_NEGATIVE = subtract from target solid UF_UNSIGNED = intersect with target solid tag_t target_body Input Target body to perform Boolean uf_list_p_t * features Output to UF_free List of feature identifiers created. This list must be freed by calling UF_MODL_delete_list. 可能大家也注意到了这里面多了一个传入目标体的参数,这个时候大家可能以为这就是解决了上面所说的那个问题了,我当时也是这样认为的,可到了使用的时候才知道,你传入的Tag值也不起作用,这个API是有问题的。

上一篇文章讲到这有问题的,现在来讲如果想要实现标题中想要的效果怎么解决。

直接上代码就不来虚的了:

///

/// 使用NXOPEN来创建拉伸操作并且返回特征的tag值 /// /// public Tag NXopenCreateExtrude(string endextend, Feature feature, Sketch sketch,Body body) { NXOpen.Features.Feature nullNXOpen_Features_Feature = null; NXOpen.Features.ExtrudeBuilder extrudeBuilder1; extrudeBuilder1 = workPart.Features.CreateExtrudeBuilder(nullNXOpen_Features_Feature); NXOpen.Section section1; section1 = workPart.Sections.CreateSection(0.00095, 0.001, 0.050000000000000003); extrudeBuilder1.Section = section1; extrudeBuilder1.AllowSelfIntersectingSection(true); NXOpen.Unit unit1; unit1 = extrudeBuilder1.Draft.FrontDraftAngle.Units; extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Create; NXOpen.Body[] targetBodies1 = new NXOpen.Body[1]; NXOpen.Body nullNXOpen_Body = null; targetBodies1[0] = nullNXOpen_Body; extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies1); extrudeBuilder1.Limits.StartExtend.Value.SetFormula("0"); extrudeBuilder1.Limits.EndExtend.Value.SetFormula(endextend); extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract; NXOpen.Body[] targetBodies2 = new NXOpen.Body[1]; targetBodies2[0] = nullNXOpen_Body; extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies2); NXOpen.GeometricUtilities.SmartVolumeProfileBuilder smartVolumeProfileBuilder1; smartVolumeProfileBuilder1 = extrudeBuilder1.SmartVolumeProfile; smartVolumeProfileBuilder1.OpenProfileSmartVolumeOption = false; smartVolumeProfileBuilder1.CloseProfileRule = NXOpen.GeometricUtilities.SmartVolumeProfileBuilder.CloseProfileRuleType.Fci; section1.SetAllowedEntityTypes(NXOpen.Section.AllowTypes.OnlyCurves); NXOpen.Features.Feature[] features1 = new NXOpen.Features.Feature[1]; //NXOpen.Features.SketchFeature sketchFeature1 = ((NXOpen.Features.SketchFeature)workPart.Features.FindObject("SKETCH(490)")); features1[0] = feature; NXOpen.CurveFeatureRule curveFeatureRule1; curveFeatureRule1 = workPart.ScRuleFactory.CreateRuleCurveFeature(features1); section1.AllowSelfIntersection(true); NXOpen.SelectionIntentRule[] rules1 = new NXOpen.SelectionIntentRule[1]; rules1[0] = curveFeatureRule1; NXOpen.NXObject nullNXOpen_NXObject = null; NXOpen.Point3d helpPoint1 = new NXOpen.Point3d(0.0, 0.0, 0.0); section1.AddToSection(rules1, nullNXOpen_NXObject, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen.Section.Mode.Create, false); NXOpen.Sketch sketch1 = sketch; NXOpen.Direction direction1; direction1 = workPart.Directions.CreateDirection(sketch1, NXOpen.Sense.Forward, NXOpen.SmartObject.UpdateOption.WithinModeling); extrudeBuilder1.Direction = direction1; NXOpen.Unit unit2; unit2 = extrudeBuilder1.Offset.StartOffset.Units; //NXOpen.Expression expression2; //expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit2); extrudeBuilder1.BooleanOperation.Type = NXOpen.GeometricUtilities.BooleanOperation.BooleanType.Subtract; NXOpen.Body[] targetBodies3 = new NXOpen.Body[1]; NXOpen.Body body1 = body; targetBodies3[0] = body1; extrudeBuilder1.BooleanOperation.SetTargetBodies(targetBodies3); extrudeBuilder1.ParentFeatureInternal = false; NXOpen.Features.Feature feature1; feature1 = extrudeBuilder1.CommitFeature(); NXOpen.Expression expression3 = extrudeBuilder1.Limits.StartExtend.Value; NXOpen.Expression expression4 = extrudeBuilder1.Limits.EndExtend.Value; extrudeBuilder1.Destroy(); //workPart.Expressions.Delete(expression2); return feature1.Tag; }

解决方法是我采用了NXOPEN重新封装了一个方法,然后这些入参都是我试验过的,需要的小伙伴直接拿去用就行了。 实验效果也是达到了我们想要的预期效果,非常nice。

今天要讲的就这么多,我们下篇文章再见。

散会 ————————————————

                        版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                    

原文链接:blog.csdn.net/m0_53104033…