NX二次开发习题及源码(共58页).docx
《NX二次开发习题及源码(共58页).docx》由会员分享,可在线阅读,更多相关《NX二次开发习题及源码(共58页).docx(58页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上1、创建NXhello界面代码:#include /包含UF_initialize()和UF_terminate()函数原型的头文件#include /包含uc1601()函数原型的头文件extern void ufusr(char *param, int *retcode, int param_len) if (UF_initialize()!=0)/获取NX openapi的执行权限 return;uc1601(Hello NX,1);/弹出消息窗口,显示“Hello NX”UF_terminate();/释放NX OPEN API的执行权限 运行结果截图:2、创
2、建一个模型,并在信息窗口显示模型的tag值。代码:#include #include #include #include #include #include static void do_ugopen_api(void) typedef unsigned int tag_t;UF_FEATURE_SIGN sign = UF_NULLSIGN;/无布尔运算double cyl_orig3 = 0,0,0;/圆柱的圆心坐标char *cyl_height=100;char *cyl_diam=40;double direction3=0,0,1;/延Z轴正方向tag_t obj=NULL_TAG
3、;UF_MODL_create_cyl1(sign, cyl_orig,cyl_height,cyl_diam,direction, &obj);UF_UI_open_listing_window(); /显示信息框:tag/*Returns the tag of the current display part. In a non-assembly part, this is the same as the work part. If there currently isnt a displayed part, a NULL_TAG is returned. */obj=UF_PART_as
4、k_display_part();if(obj = NULL_TAG) /没有部件的时候显示的信息提示框 uc1601 ( 当前没有任何文件可供操作!,1); else char s10;sprintf(s, %d,obj); /sprinf()功能:把格式化的数据写入某个字符串UF_UI_write_listing_window(s);return;extern void ufusr( char *param, int *retcode, int rlen )/提供入口点if(UF_initialize()!=0)return;do_ugopen_api ();UF_terminate();
5、return;extern int ufusr_ask_unload(void)return(UF_UNLOAD_IMMEDIATELY);运行结果截图:(1)无部件时的输出(2)有部件时的输出结果3、open part 用户入口实例创建open part user exit在用户点击“open”时创建新部件,在其中创建sphere详细说明user exit设置文件过程代码如下:#include #include #include #include #include #include #include #define UF_CALL(X) (report( _FILE_, _LINE_, #X
6、, (X)static int report( char *file, int line, char *call, int irc)if (irc)char messg133;printf(%s, line %d: %sn, file, line, call);(UF_get_fail_message(irc, messg) ?printf( returned a %dn, irc) :printf( returned error %d: %sn, irc, messg);return(irc);static void do_ugopen_api(void)UF_FEATURE_SIGN si
7、gn = UF_NULLSIGN;tag_t part=null_tag;/如果没有赋值的话,直接就是tag_t part,当你执行.dll文件时,就直接跑到建模环境了,没有信息提示框。当然你可以多申明几个tag_tchar part_name13 = F:long.prt;/设置part名字以及存储路径double center 3 =0,0,0;/球心坐标char * diam=100;int units =1; uc1601(创建直径为100的球,1);UF_PART_new (part_name, units, &part);/在当前的会话框中创建新的part,并把其作为工作部件/试比
8、较下面两个函数UF_MODL_create_sphere(sign,part,center,diam, &part );/UF_MODL_create_sphere1(sign,center,diam, &part);extern void ufusr(char *param, int *retcode, int paramLen) if (!UF_CALL(UF_initialize() do_ugopen_api();UF_CALL(UF_terminate(); extern int ufusr_ask_unload(void)return (UF_UNLOAD_IMMEDIATELY)
9、;运行结果截图:4、创建一个block,并指定某一特定面高亮显示。代码如下图:#include #include #include #include#include#include#include#define UF_CALL(X) (report( _FILE_, _LINE_, #X, (X)static int report( char *file, int line, char *call, int irc)if (irc)char messg133;printf(%s, line %d: %sn, file, line, call);(UF_get_fail_message(irc,
10、 messg) ?printf( returned a %dn, irc) :printf( returned error %d: %sn, irc, messg);return(irc);static void do_ugopen_api(void)UF_FEATURE_SIGN sign=UF_NULLSIGN; tag_t obj=null_tag;double center 3=0,0,0 ; char *edge_len3=10,10,10;tag_t blk_feat;int units=2;/此行代码的赋值,经过调试,貌似只有1和2可以,它们的区别就是生成模型的默认大小不同,可以
11、自己调调看。char part_name13=F:long.part;/此段代码有点小重要,注意一定要保证完整性,不完整的话,估计会出现好多问题,绕好多路。uc1601(创建一个正方体,并指定下表面高亮显示,1);UF_PART_new(part_name,units,&obj);/UF_MODL_create_block(sign,obj,center,edge_len,&blk_feat);UF_MODL_create_block1(sign,center,edge_len,&blk_feat);uf_list_p_t face_list;/链表UF_MODL_create_list(&f
12、ace_list);/创建链表UF_MODL_ask_feat_faces(blk_feat,&face_list);/获取实体的个表面特征,并放入链表中int count=0;UF_MODL_ask_list_count(face_list,&count);for(int i=0;icount;i+)UF_MODL_ask_list_item(face_list,i,&obj);/从链表中取出对象int type;double point 20 ; double dir 20 ;double box 6;double radius;double rad_data; int norm_dir;
13、UF_MODL_ask_face_data(obj,&type,point,dir,box,&radius,&rad_data,&norm_dir);/这个函数非常重要,可以说是本段代码中最核心的部分。if(dir0=0&dir1=0&dir2=-1)/确定高亮显示的那个面的法向量UF_DISP_set_highlight(obj,1);/UF_OBJ_set_color(obj, 186);break;/*ARGSUSED*/extern void ufusr(char *param, int *retcode, int paramLen)if (!UF_CALL(UF_initialize
14、()do_ugopen_api();UF_CALL(UF_terminate();extern int ufusr_ask_unload(void)return (UF_UNLOAD_IMMEDIATELY);运行结果截图:注:和高亮显示还有一个类似的设置,就是给实体上色,所用到的函数是:UF_OBJ_set_color(obj, 186);上面的这个函数是把对象显示成红色,如下图:“186”是红色的代号。这些数字可以在UG交互模式下的对象显示里查到,如下图:5、用遍历的形式输出当前part所有面的tag至listing window代码如下:#include #include #includ
15、e #include #include #include #include #include #define UF_CALL(X) (report( _FILE_, _LINE_, #X, (X)static int report( char *file, int line, char *call, int irc)if (irc)char messg133;printf(%s, line %d: %sn, file, line, call);(UF_get_fail_message(irc, messg) ?printf( returned a %dn, irc) :printf(retur
16、ned error %d: %sn, irc, messg);return(irc);static void do_ugopen_api(void)UF_FEATURE_SIGN sign = UF_NULLSIGN;double center 3 = 0,0,0; char * edge_len 3 =100,100,100; tag_t blk_feat =null_tag;char * part_name=F:long;int units=1;tag_t part =NULL_TAG;uc1601(创建一个block,并显示每个面的tag,1);UF_PART_new(part_name
17、,units,&part);/在当前会话窗口中创建一个part,并使其成为工作部件UF_CALL(UF_MODL_create_block1(sign,center,edge_len, &blk_feat);if(blk_feat = NULL_TAG) uc1601 ( 当前没有任何文件可供操作!,1); elseint type=70;int subtype=2;tag_t obj=null_tag;tag_t display_part=UF_PART_ask_display_part();UF_OBJ_cycle_objs_in_part(display_part,70,&obj);wh
18、ile(obj!=null_tag)UF_OBJ_ask_type_and_subtype(obj,&type,&subtype);/返回一个被标记的对象的对象类型和子类型UF_OBJ_cycle_objs_in_part (display_part,UF_solid_type,&obj);/查询遍历对象if(subtype= UF_solid_face_subtype)char s50;sprintf(s, %d, obj);UF_CALL(UF_UI_open_listing_window();UF_CALL(UF_UI_write_listing_window(s);UF_CALL(UF
19、_UI_write_listing_window(n);void ufusr(char *param, int *retcode, int paramLen)if (!UF_CALL(UF_initialize()do_ugopen_api();UF_CALL(UF_terminate();int ufusr_ask_unload(void)return (UF_UNLOAD_IMMEDIATELY);运行结果截屏:6、遍历当前part中所有features,输出其类型至listing window,UF_MODL_ask_feat_type()代码如下:#include #include #
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- NX 二次开发 习题 源码 58
限制150内