UG/NX二开Siemens官方实例解析 4.1 EX_Curve_CreateArc(创建曲线)

前言

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

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

        本系列的第一篇文章,这里科普一下C#调用ufun的方法,后面将不在累赘: 


一、知识点提取

本实例实现了通过ufun函数自动创建曲线,主要知识点如下:

1、theUfSession的初始化

2、通过StreamWriter记录日志

3、File方法的使用

4、创建曲线相关ufun方法

二、需求分析

1、效果图

2、需求分解

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

1)先新建prt文件

2)有了文件,画曲线

3)保存文件

三、程序分析

1、源码所在目录

UGOPEN\SampleNXOpenApplications\.NET\NXOpenExamples\EX_Curve_CreateArc.cs

2、主要功能分析 

1、FileStream记录日志方法的使用

private static FileStream fs; 
fs = new FileStream("EX_Curve_CreateArc.log", FileMode.Create, FileAccess.Write);
w = new StreamWriter(fs); // create a stream writer 
w.Write("Log Entry : \r\n");
w.WriteLine("--Log entry goes here--"); 
w.Flush(); // update underlying file
w.WriteLine("End of Log File");
w.Close();

2、 theUfSession的初始化

private static UFSession theUfSession;
private static Session theSession;
theSession=Session.GetSession();
theUfSession= UFSession.GetUFSession();

3、 File方法的使用,判断文件是否存在

File.Exists("EX_Curve_CreateArc.prt")

4、 创建曲线相关ufun方法

Tag UFPart;
string part_name = "EX_Curve_CreateArc";
int units =2; 
string name;
theUfSession.Part.New(part_name, units, out UFPart);
theUfSession.Part.AskPartName(UFPart, out name);
Tag arc, wcs;
UFCurve.Arc arc_coords = new UFCurve.Arc();     
/* Fill out the data structure */
arc_coords.start_angle = 0.0;
arc_coords.end_angle = 3.0;
arc_coords.arc_center=new double[3];
arc_coords.arc_center[0] = 0.0;
arc_coords.arc_center[1] = 0.0;
arc_coords.arc_center[2] = 1.0;
arc_coords.radius = 2.0;
theUfSession.Csys.AskWcs(out wcs);
theUfSession.Csys.AskMatrixOfObject(wcs,out arc_coords.matrix_tag);
theUfSession.Curve.CreateArc(ref arc_coords,out arc);
theUfSession.Part.Save();

创建曲线步骤:

1、新建prt文件,theUfSession.Part.New(part_name, units, out UFPart);

2、设置曲线参数,画曲线,theUfSession.Curve.CreateArc(ref arc_coords,out arc);

3、保存prt文件,theUfSession.Part.Save();  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MarcoPro

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

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

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

打赏作者

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

抵扣说明:

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

余额充值