前言
本系列文章主要讲解NXOpen UF API(简称ufun函数)的使用,之前看教学视频大都建议用ufun进行开发,这里西门子官方还专门给了一套系列文章来讲,说明官方也是特别推崇ufun。
本人从事二开也有一段时间了,我的二开启蒙师父就特别喜欢用NXOpen API,用他的话来说“年少不知nxopen好,错把ufun当成宝”,其实就我个人而言,还是喜欢NXOPEN+ufun联合开发。
一、小节概要
本实例实现了特征信息的获取,主要知识点如下:
1、遍历工作部件 theUfSession.Obj.CycleObjsInPart
2、获取特征类型 theUfSession.Modl.AskFeatType
3、获取关联特征 theUfSession.Modl.AskFeatRelatives
4、返回父特征和子特征相关信息
二、需求分析
1、效果图
2、需求分解
1、遍历工作部件
2、获取特征类型
3、获取关联特征
4、返回父特征和子特征相关信息
三、程序分析
1、源码所在目录
UGOPEN\SampleNXOpenApplications\.NET\NXOpenExamples\EX_Modl_FeatureType
2、主要功能分析
1、遍历工作部件
part_tag = theUfSession.Assem.AskWorkPart();
theUfSession.Obj.CycleObjsInPart(part_tag, enttype, ref feat1);
2、获取特征类型
theUfSession.Modl.AskFeatType(feat1,out feat_type);
tmp_text = " Feature "+ index + " = " + feat1 + " is of type " + feat_type + "\n";
theUfSession.Ui.WriteListingWindow(tmp_text);
3、获取关联特征
theUfSession.Modl.AskFeatRelatives(feat1,out num_parents,out parent_array,out num_children,
out children_array);
4、返回父特征和子特征相关信息
if(num_parents > 0)
{
for (inx = 0;inx < num_parents; inx++)
{
theUfSession.Modl.AskFeatType(parent_array[inx],out feat_type);
tmp_text = " Parent id " + inx + " = " + parent_array[inx] +
" is of feature type " + feat_type + "\n";
theUfSession.Ui.WriteListingWindow(tmp_text);
}
}
tmp_text = " children array for feature " + feat1 + " contains " + num_children + " members:\n";
theUfSession.Ui.WriteListingWindow(tmp_text);
if(num_children > 0)
{
for (inx = 0;inx < num_children; inx ++)
{
theUfSession.Modl.AskFeatType(children_array[inx],out feat_type);
tmp_text = " child is " + inx + " = " + children_array[inx]
+ " is of feature type " + feat_type + "\n";
theUfSession.Ui.WriteListingWindow(tmp_text);
}
}