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

上传人(卖家):刘殿科 文档编号:5856019 上传时间:2023-05-12 格式:DOC 页数:24 大小:4.60MB
下载 相关 举报
NX二次开发习题及源码.doc_第1页
第1页 / 共24页
NX二次开发习题及源码.doc_第2页
第2页 / 共24页
NX二次开发习题及源码.doc_第3页
第3页 / 共24页
NX二次开发习题及源码.doc_第4页
第4页 / 共24页
NX二次开发习题及源码.doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

1、1、创建NXhello界面代码:#include 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_ask_display_part();if(obj = NULL_TAG) ll文件时,就直接跑到建模环境了,没有信息提示框。当然你可以多申明几个tag_tchar part_name13 = F:;/ UF_get_fail_message(error_code, fa

2、il_message); UF_UI_set_status (fail_message); printf ( %sn, fail_message ); UF_terminate(); return;extern int ufusr_ask_unload (void) return ( UF_UNLOAD_IMMEDIATELY );extern void ufusr_cleanup (void) return;int CHANGE_apply_cb ( int dialog_id,void * client_data,UF_STYLER_item_value_type_p_t callback

3、_data) if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); / UF_get_fail_message(error_code, fail_message); UF_UI_set_status (fail_message); printf ( %sn, fail_message ); UF_terminate(); return;extern int ufusr_ask_unload (void) /* unload immediately after application exits*/ return ( UF

4、_UNLOAD_IMMEDIATELY ); /*via the unload selection dialog. */ /*return ( UF_UNLOAD_SEL_DIALOG ); */ /*when UG terminates. */ /*return ( UF_UNLOAD_UG_TERMINATE ); */extern void ufusr_cleanup (void) return;int CHANGE_apply_cb ( int dialog_id, void * client_data, UF_STYLER_item_value_type_p_t callback_d

5、ata) /* Make sure User Function is available. */ if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); /* - Enter your callback code here - */ UF_terminate (); /* Callback acknowledged, do not terminate dialog */ /* A return value of UF_UI_CB_EXIT_DIALOG will not be accepted */ /* for this

6、 callback type. You must respond to your apply button.*/ return (UF_UI_CB_CONTINUE_DIALOG); int CHANGE_action_1_act_cb ( int dialog_id, void * client_data, UF_STYLER_item_value_type_p_t callback_data) /* Make sure User Function is available. */ if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_D

7、IALOG ); /* - Enter your callback code here - */ UF_UI_create_filebox ( prompt_string, title_string, filter_string, default_name, filename, &response); /* 从文件中读信息*/ int error; fstream file1(filename); char *file_contents = (char*)UF_allocate_memory(sizeof(char*)*16,&error); int i=0; while(!() file_c

8、ontentsi = (char*)UF_allocate_memory(MAX_LINE_SIZE+1,&error); file1file_contentsi; UF_UI_write_listing_window(file_contentsi); UF_UI_write_listing_window(n); i+; UF_STYLER_item_value_type_t data; = MTXT_0; = UF_STYLER_VALUE; = UF_STYLER_STRING_PTR_VALUE; = i; = file_contents; UF_STYLER_set_value(dia

9、log_id,&data); UF_STYLER_free_value(&data); (); UF_terminate (); /* Callback acknowledged, do not terminate dialog */ return (UF_UI_CB_CONTINUE_DIALOG); /* or Callback acknowledged, terminate dialog. */ /* return ( UF_UI_CB_EXIT_DIALOG ); */int CHANGE_action_2_act_cb ( int dialog_id, void * client_d

10、ata, UF_STYLER_item_value_type_p_t callback_data) /* Make sure User Function is available. */ if ( UF_initialize() != 0) return ( UF_UI_CB_CONTINUE_DIALOG ); /* - Enter your callback code here - */ UF_STYLER_item_value_type_t data; = MTXT_0; = UF_STYLER_VALUE; UF_STYLER_ask_value(dialog_id,&data); c

11、har prompt_string=Select File; char title_string=File Access; char filter_stringUF_CFI_MAX_PATH_NAME_SIZE+1=*.txt; char default_name133=; char filenameUF_CFI_MAX_PATH_NAME_SIZE; int response; int error = UF_UI_create_filebox(prompt_string, title_string, filter_string, default_name, filename, &respon

12、se); if(error !=0 ) return UF_UI_CB_CONTINUE_DIALOG; fstream file2(filename); for (int i=0;i;i+) if(!(file2&file2endl) (); UF_STYLER_free_value(&data); UF_terminate (); /* Callback acknowledged, do not terminate dialog */ return (UF_UI_CB_CONTINUE_DIALOG); /* or Callback acknowledged, terminate dial

13、og. */ /* return ( UF_UI_CB_EXIT_DIALOG ); */ 注意:这个项目需要在UG中创建一个人机交互界面8、(1)创建点收集器,创建参考点并返回点的坐标代码如下:#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,

14、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) bject;UF_UI_open_listing_window(); char str 133;for(int i=0;i3;i+)sprintf(str,%f,points0.pti);nn,msg);exit(1);static void report_error(int

15、result,char *alt_msg)char err_message200;int found = UF_get_fail_message(result,err_message);if (found != 0)error_return(alt_msg);elseerror_return(err_message);static void create_blo( double origin_y, char *blo_length,char*blo_width,char*blo_height ) UF_FEATURE_SIGN sign = UF_NULLSIGN; tag_t taget =

16、 NULL_TAG; double blo_origin 3 = 0,0,0; */ if(UF_CALL(UF_UI_select_with_class_dialog(cue, title, UF_UI_SEL_SCOPE_NO_CHANGE ,init_proc, NULL, &response, &count, &objects) = 0) 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.

17、*/tag_t root_occ = UF_ASSEM_ask_root_part_occ(display_part);if(root_occ=null_tag)rom_part_occ = from_part_occ;0.from_status = UF_ASSEM_ok;0.from = UF_ASSEM_ask_prototype_of_occ( objs0 );0.from_type = UF_ASSEM_planar_face;0.to = UF_ASSEM_ask_prototype_of_occ( objs1 );0.to_part_occ = to_part_occ;0.to_

18、status = UF_ASSEM_ok;0.to_type = UF_ASSEM_planar_face;0.mate_type = UF_ASSEM_align;UF_ASSEM_mc_status_t status;UF_ASSEM_dof_t dof;double transform_matrix44; UF_MODL_ask_exp_tag_value(target1,&value); /创建孔特征的变量声明区 double location3=, ; double direction = ,; tag_t obj=null_tag; char *diam=30; char *ang

19、le=0; tag_t bottom,top; tag_t feature_obj_id ; /链表,把圆柱所有的面放进去 uf_list_p_t face_list; UF_MODL_create_list(&face_list);/Retrieves an object from a linked list of objects UF_MODL_ask_feat_faces(cyl_feat_tag,&face_list); int count=0; UF_MODL_ask_list_count(face_list,&count);/Retrieves the count from a l

20、inked list of objects for(int i=0;icount;i+) UF_MODL_ask_list_item(face_list,i,&obj); int type; double point 3 ; double dir 3 ; 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);/Queries the data associated with a

21、 face if(type=22)/“22”代表有界平面 if(fabs(point2-origin2) bottom=obj; if(fabs(point2-value) UF_MODL_ask_feat_location(obj,location); top=obj; UF_MODL_create_simple_hole(location,direction,diam,height,angle,top,bottom,&feature_obj_id);UF_MODL_ask_feat_faces(feature_obj_id,&face_list);UF_MODL_ask_list_coun

22、t(face_list,&count);for(int i=0;icount;i+) UF_MODL_ask_list_item(face_list,i,&obj);/Retrieves an object from a linked list of objects int typel; UF_MODL_ask_face_type(obj,&typel); /倒圆角 if(typel= UF_MODL_CYLINDRICAL_FACE ) uf_list_p_t facesl; UF_MODL_create_list(&facesl); UF_MODL_ask_shared_edges(top

23、,obj,&facesl); const char * radius=3; int smooth_overflow=0; int cliff_overflow=0; int notch_overflow=0; double vrb_tool=3; tag_t feature_obj_idl; UF_MODL_create_blend(radius, facesl, smooth_overflow, cliff_overflow, notch_overflow, vrb_tool, &feature_obj_id ); void ufusr(char *param, int *retcode,

24、int param_len) if (!UF_CALL(UF_initialize() do_ugopen_api(); UF_CALL(UF_terminate(); int ufusr_ask_unload(void) return (UF_UNLOAD_IMMEDIATELY);运行结果截屏如下:(2)创建一个对象,使其沿着X轴平移100,以Z轴为旋转轴旋转90度。代码如下:#include #include#include#include#include#include#includeextern void ufusr(char *param, int *retcode, int pa

25、ramLen) if(UF_initialize()!=0) return; /获取实体 tag_t display_part = UF_PART_ask_display_part(); tag_t objects = NULL_TAG; UF_OBJ_cycle_objs_in_part(display_part,UF_solid_type,&objects); /返回平移的矩阵 double translation3=,; double matrix116; uf5943(translation,matrix1); /返回旋转的矩阵 double origin3=,; double dir

26、ection3=,; double degrees_rotation=; double matrix216; int status1; uf5945(origin,direction,°rees_rotation,matrix2,&status1); /实现平移及旋转 const int n_objects=1 ; const int move_or_copy=1; const int dest_layer=0 ; const int trace_curves=2 ; tag_t copies; tag_t trace_curve_group; int status2; uf5947(m

27、atrix1,&objects,&n_objects,&move_or_copy,&dest_layer, &trace_curves,&copies,&trace_curve_group,&status2); uf5947(matrix2,&objects,&n_objects,&move_or_copy,&dest_layer, &trace_curves,&copies,&trace_curve_group,&status2); UF_terminate(); int ufusr_ask_unload(void) return (UF_UNLOAD_IMMEDIATELY); void ufusr_cleanup(void)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 办公、行业 > 待归类文档
版权提示 | 免责声明

1,本文(NX二次开发习题及源码.doc)为本站会员(刘殿科)主动上传,163文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。
2,用户下载本文档,所消耗的文币(积分)将全额增加到上传者的账号。
3, 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(发送邮件至3464097650@qq.com或直接QQ联系客服),我们立即给予删除!


侵权处理QQ:3464097650--上传资料QQ:3464097650

【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。


163文库-Www.163Wenku.Com |网站地图|