ImageVerifierCode 换一换
格式:DOCX , 页数:70 ,大小:1.45MB ,
资源ID:6789509      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6789509.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(NX二次开发习题及源码.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

NX二次开发习题及源码.docx

1、NX二次开发习题及源码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=NU

3、LL_TAG; 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=

4、UF_PART_ask_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

5、(); UF_terminate(); 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) (repor

6、t( _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( returned error %d: %sn, irc, messg); return(irc);static void do_ugopen

7、_api(void) UF_FEATURE_SIGN sign = UF_NULLSIGN; tag_t part=null_tag;/如果没有赋值的话,直接就是tag_t part,当你执行.dll文件时,就直接跑到建模环境了,没有信息提示框。当然你可以多申明几个tag_t char 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, &p

8、art);/在当前的会话框中创建新的part,并把其作为工作部件 /试比较下面两个函数 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_un

9、load(void) return (UF_UNLOAD_IMMEDIATELY);运行结果截图: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,

10、 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 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 u

11、nits=2;/此行代码的赋值,经过调试,貌似只有1和2可以,它们的区别就是生成模型的默认大小不同,可以自己调调看。 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,&

12、blk_feat); uf_list_p_t face_list;/链表 UF_MODL_create_list(&face_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

13、 dir 20 ; double box 6; double radius; double rad_data; int norm_dir; 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 vo

14、id 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);运行结果截图:注:和高亮显示还有一个类似的设置,就是给实体上色,所用到的函数是:UF_OBJ_set_color(obj, 186);上面的这个函数是把对象显示成红色,如下图:“186”是红色的代号。这些数字可以在UG交互模式下的

15、对象显示里查到,如下图:5、用遍历的形式输出当前part所有面的tag至listing window代码如下:#include #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,

16、 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 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:

17、long; int units=1; tag_t part =NULL_TAG; uc1601(创建一个block,并显示每个面的tag,1); UF_PART_new(part_name,units,&part);/在当前会话窗口中创建一个part,并使其成为工作部件 UF_CALL(UF_MODL_create_block1(sign,center,edge_len, &blk_feat); if(blk_feat = NULL_TAG) uc1601 ( 当前没有任何文件可供操作!,1); else int type=70; int subtype=2; tag_t obj=null_t

18、ag; tag_t display_part=UF_PART_ask_display_part(); UF_OBJ_cycle_objs_in_part(display_part,70,&obj); while(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 s5

19、0; sprintf(s, %d, obj); UF_CALL(UF_UI_open_listing_window(); UF_CALL(UF_UI_write_listing_window(s); UF_CALL(UF_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_U

20、NLOAD_IMMEDIATELY);运行结果截屏:6、遍历当前part中所有features,输出其类型至listing window,UF_MODL_ask_feat_type()代码如下:#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, l

21、ine %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) char * part_name=F:NX; UF_FEATURE_SIGN sign = UF_NULLSIGN; tag_t part=null_tag; double center 3 =0,0,0; char * di

22、am=100; int units =1; uc1601(创建直径为100的球,并显示其实体特征。,1); UF_PART_new (part_name, units, &part);/在当前的会话框中创建新的part,并把其作为工作部件 UF_MODL_create_sphere1(sign,center,diam, &part); int count = 0; char* solid_feature; tag_t found = NULL_TAG; tag_t display_part = UF_PART_ask_display_part(); UF_UI_open_listing_win

23、dow(); UF_OBJ_cycle_objs_in_part(display_part,UF_feature_type,&found); while( found != NULL_TAG ) count+; UF_CALL(UF_MODL_ask_feat_type(found,&solid_feature);/获取输入的特征的类型 UF_CALL(UF_UI_write_listing_window(feature:); UF_CALL(UF_UI_write_listing_window(solid_feature); UF_CALL(UF_UI_write_listing_windo

24、w(n); UF_CALL(UF_OBJ_cycle_objs_in_part(display_part,UF_feature_type,&found); 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);运行结果截屏:6、创建人机交互界面新建圆柱体,并可以随意选

25、择原点和矢量方向。代码如下:#include #include #include #include #include #include #include #include #include #include #include #include cylinder.h#define CHANGE_CB_COUNT ( 3 + 1 ) /* Add 1 for the terminator */ tag_t blk_tag= null_tag; double blk_orig = 0,0,0; double direction 3 ; char * part_name=F:long; int uni

26、ts=1;static UF_STYLER_callback_info_t CHANGE_cbsCHANGE_CB_COUNT = UF_STYLER_DIALOG_INDEX, UF_STYLER_APPLY_CB , 0, CHANGE_apply_cb, CHANGE_ACTION_2 , UF_STYLER_ACTIVATE_CB , 1, CHANGE_action_2_act_cb, CHANGE_ACTION_3 , UF_STYLER_ACTIVATE_CB , 1, CHANGE_action_3_act_cb, UF_STYLER_NULL_OBJECT, UF_STYLE

27、R_NO_CB, 0, 0 ;static UF_MB_styler_actions_t actions = cylinder.dlg, NULL, CHANGE_cbs, UF_MB_STYLER_IS_NOT_TOP , NULL, NULL, NULL, 0 /* This is a NULL terminated list */;static int init_proc(UF_UI_selection_p_t select,void *user_data);extern void ufusr (char *param, int *retcode, int rlen) uc1601(创建一个圆柱,并指明原点和矢量,1); UF_PART_new(part_name,units,&blk_tag); int response = 0; int error_code = 0; if ( ( UF_initialize() ) != 0 ) return;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1