当前位置: 首页 > news >正文

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

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

UF_MODL_create_extruded1 (view source)

uf_list_p_tobjectsInputList of objects to be extruded.
char *taper_angleInputTaper angle (in degrees).
char *limit [ 2 ]InputLimit 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).
doublepoint [ 3 ]Inputnot used
doubledirection [ 3 ]InputExtrusion axis.
UF_FEATURE_SIGNsignInputThe 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_ttarget_bodyInputTarget body to perform Boolean
uf_list_p_t *featuresOutput to UF_*free*List of feature identifiers created. This list
must be freed by calling UF_MODL_delete_list.

可能大家也注意到了这里面多了一个传入目标体的参数,这个时候大家可能以为这就是解决了上面所说的那个问题了,我当时也是这样认为的,可到了使用的时候才知道,你传入的Tag值也不起作用,这个API是有问题的。

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

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

  /// <summary>
    /// 使用NXOPEN来创建拉伸操作并且返回特征的tag值
    /// </summary>
    /// <returns></returns>
    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。

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

散会

相关文章:

  • Java入职篇(5)—— IDEA快捷键
  • 使用 Docker 部署前端项目全攻略
  • DevOps实践:持续集成与持续部署完全指南
  • 图解AUTOSAR_CP_BSW_General
  • 什么是 HTML?
  • 第一个vue项目
  • 成为Python砖家(7): 使用miniforge管理Python版本
  • java设计模式面试题3道
  • Linux设置环境变量
  • 【DeepSeek】蓝耘智算 | 中国AI新范式:蓝耘智算云+DeepSeek R1部署实战教程
  • HiRAG层次化知识增强的检索增强生成框架:模仿人类从细节到抽象的多粒度认知过程【附代码】
  • 驾驭 DeepSeek 科技之翼,翱翔现代学习新天际
  • TensorFlow 是什么?
  • 卷积神经网络 - 一维卷积、二维卷积
  • 【PTA题目解答】7-3 字符串的全排列(20分)next_permutation
  • Redis 的特点
  • 大模型推理后JSON数据后处理
  • Elasticsearch集群与日志系统实战部署指南
  • 3 C#调用visionPro的toolblock的步骤
  • jQuery从入门到应用:选择器、DOM与Ajax综合指南
  • 日产淡水10万吨、全自动运行,万华化学蓬莱海水淡化厂投产
  • 今年4月上海一二手房成交面积同比增21%,二手房成交2.07万套
  • 讲武谈兵|朝鲜“崔贤”号驱逐舰下水,朝版“宙斯盾”战力如何?
  • 国家能源局通报上月投诉情况:赤峰有群众反映电费异常增高,已退费
  • 北京银行一季度净赚超76亿降逾2%,不良贷款率微降
  • 69岁朱自强被查,曾任南京地铁总经理