UG/NX二开Siemens官方实例解析 4.2 EX_Curve_CreateFillet(连接关联曲线)

前言

        本系列文章主要讲解NXOpen UF API(简称ufun函数)的使用,之前看教学视频大都建议用ufun进行开发,这里西门子官方还专门给了一套系列文章来讲,说明官方也是特别推崇ufun。

        本人从事二开也有一段时间了,我的二开启蒙师父就特别喜欢用NXOpen API,用他的话来说“年少不知nxopen好,错把ufun当成宝”,其实就我个人而言,还是喜欢NXOPEN+ufun联合开发。


一、小节概要

本实例实现了通过ufun函数连接关联曲线,主要知识点如下:

1、theUfSession的初始化

2、通过StreamWriter记录日志

3、创建直线相关ufun方法

4、创建圆弧相关ufun方法

5、创建连接关联曲线的ufun方法

二、需求分析

1、效果图

2、需求分解

这里需要创建连接曲线,分以下几步实现:

1)先新建prt文件

2)有了文件,画曲线、直线

3)创建连接曲线

3)保存文件

三、程序分析

1、源码所在目录

UGOPEN\SampleNXOpenApplications\.NET\NXOpenExamples\EX_Curve_CreateFillet.cs

2、主要功能分析 

1、创建直线

UFCurve.Line line_coords1 = new UFCurve.Line();
line_coords1.start_point = new double[3];
line_coords1.start_point[0] = 1.2;
line_coords1.start_point[1] = 0.2;
line_coords1.start_point[2] = 0.0;
line_coords1.end_point = new double[3];
line_coords1.end_point[0] = -0.5;
line_coords1.end_point[1] = 2.5;
line_coords1.end_point[2] = 0.0;
theUfSession.Curve.CreateLine(ref line_coords1, out line1);

有起始端点的坐标就可以创建一条直线 

2、创建圆弧

UFCurve.Arc arc_coords1 = new UFCurve.Arc();        
arc_coords1.matrix_tag = Tag.Null;
arc_coords1.start_angle =238*DEGRA ;
arc_coords1.end_angle = 357*DEGRA;
arc_coords1.arc_center=new double[3];
arc_coords1.arc_center[0] = 0.22;
arc_coords1.arc_center[1] = 4.3;
arc_coords1.arc_center[2] = 0.0;
arc_coords1.radius = 2.0;
theUfSession.Csys.AskWcs(out wcs_tag);
theUfSession.Csys.AskMatrixOfObject(wcs_tag, out matrix_tag);
arc_coords1.matrix_tag=matrix_tag;
theUfSession.Curve.CreateArc(ref arc_coords1, out arc1);

创建圆弧的关键在于初始化 arc_coords

1、matrix_tag    圆弧所在的CSYS矩阵

2、start_angle   开始弧度

3、end_angle    结束弧度

4、arc_center    圆弧中心坐标

5、radius           圆弧半径

3、连接关联曲线

/*create fillet between "arc1" and "line1"*/
curve_objs[0] = arc1;
curve_objs[1] = line1;
center[0] = 0.0;
center[1] = 2.1;
center[2] = 0.0;
radius = .25;
trim_opts[0] = 1;          /*trim first UFCurve*/
trim_opts[1] = 1;         /*trim second UFCurve*/
theUfSession.Curve.CreateFillet(UF_CURVE_2_CURVE,curve_objs,   center, radius, trim_opts,arc_opts, out fillet_obj1);

4、附上连接关联曲线的官方函数截图 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
UG/NX二次开发中,可以使用以下方法获取曲线的类型: 1. 获取曲线对象,例如线、圆、椭圆等。 2. 使用UG/Curve_Type.hxx头文件中的枚举类型,通过曲线对象的CurveType()方法获取曲线类型。 以下是一个示例代码,演示如何获取曲线类型: ``` #include <NXOpen/NXException.hxx> #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/Features_Feature.hxx> #include <NXOpen/Features_FeatureCollection.hxx> #include <NXOpen/Features_FeatureType.hxx> #include <NXOpen/Features_BodyFeature.hxx> #include <NXOpen/Features_BodyFeatureCollection.hxx> #include <NXOpen/Curve.hxx> #include <NXOpen/Curve_Type.hxx> using namespace NXOpen; void getCurveType(Curve* curve) { if (curve == NULL) { return; } Curve::Type type = curve->CurveType(); switch (type) { case Curve::Type_Line: // do something for line break; case Curve::Type_Circle: // do something for circle break; case Curve::Type_Ellipse: // do something for ellipse break; // add more cases for other curve types default: // do something for unknown curve type break; } } int main(int argc, char* argv[]) { Part* part = NULL; PartCollection* partCollection = NULL; Features::Feature* feature = NULL; Features::FeatureCollection* featureCollection = NULL; Features::BodyFeature* bodyFeature = NULL; Features::BodyFeatureCollection* bodyFeatureCollection = NULL; Curve* curve = NULL; try { partCollection = NXOpen::Session::GetSession()->Parts(); part = partCollection->ActivePart(); featureCollection = part->Features(); feature = featureCollection->FindObject("feature_name", Features::FeatureType_Body); bodyFeatureCollection = feature->BodyFeatures(); bodyFeature = bodyFeatureCollection->FindObject("body_feature_name"); curve = dynamic_cast<Curve*>(bodyFeature->GetGeometryObject()); getCurveType(curve); } catch (NXException& ex) { // handle exception } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MarcoPro

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值