1UG二次开发模板目录第一章技巧规则···························································································(2)第二章函数模板···························································································(4)第三章功能模板·························································································(11)第四章udop··································································································(24)注:连接:Ctrl+单击鼠标左键2第一章技巧规则1,内存原则:【规则1】用malloc或new申请内存之后,应该立即检查指针值是否为NULL。防止使用指针值为NULL的内存。【规则2】不要忘记为数组和动态内存赋初值。防止将未被初始化的内存作为右值使用。【规则3】避免数组或指针的下标越界,特别要当心发生“多1”或者“少1”操作。【规则4】动态内存的申请与释放必须配对,防止内存泄漏。【规则5】用free或delete释放了内存之后,立即将指针设置为NULL,防止产生“野指针”。2,数组要么在静态存储区被创建(如全局数组),要么在栈上被创建。数组名对应着(而不是指向)一块内存,其地址与容量在生命期内保持不变,只有数组的内容可以改变。指针可以随时指向任意类型的内存块,它的特征是“可变”,所以我们常用指针来操作动态内存。指针远比数组灵活,但也更危险。注意当数组作为函数的参数进行传递时,该数组自动退化为同类型的指针。new/delete的功能完全覆盖了malloc/free,为什么C++不把malloc/free淘汰出局呢?这是因为C++程序经常要调用C函数,而C程序只能用malloc/free管理动态内存。2,分配空间double(*point)[3];point=newdouble[count][3];delete[]point;//正确的用法/*deletepoint;//错误的用法=deletepoint[0]*/3,UF_MODL_update();//使用UF_MODL_edit时用来刷新4UF_UI_ONT_refresh();//刷新导航器头文件#includeuf_ui_ont.hUF_DISP_refresh();//去除临时文件#includeuf_disp.h5调试工具1)uc1601//显示消息对话框3头文件:#includeuf_ui.h用法1:charinf[100];sprintf(inf,%f,);uc1601(inf,1);用法2:uc1601(,1);2)UF_UI_write_listing_window//显示文本框头文件:#includeuf_ui.hcharinf[100];UF_UI_open_listing_window();sprintf(inf,%,);UF_UI_write_listing_window(inf);6,隐藏中间过程#includeuf_disp.hUF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY);//打开隐藏UF_DISP_set_display(UF_DISP_UNSUPPRESS_DISPLAY);//关闭隐藏4第二章函数模板1,uc1600//获取字符串头文件:#includeuf_ui.hintres=0;intlen=0;charstring[100]=;res=uc1600(,string,&len);//string:Input/Outputif(res==5||(res==3&&len0)){}else{}2,uc1603//头文件:#includeuf_ui.h用法1:chartitle[100]=菜单;charitems[3][38]={选项1,选项2,选项3};choice=uc1603(title,0,items,3);if(choice==1||choice==2){UF_terminate();}else{if(choice==){}}用法2:5charitems[3][38]={选项1,选项2,选项3};response=uc1603(菜单,0,items,3);switch(response){case1:case2:break;case4:case5:}3,选择对话框头文件头文件1:init_proc_facestaticintinit_proc_face(UF_UI_selection_p_tselect,void*user_data){intnums=1;UF_UI_mask_tmasks[]={UF_solid_type,0,UF_UI_SEL_FEATURE_ANY_FACE};if((UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,nums,masks))==0){return(UF_UI_SEL_SUCCESS);}else{return(UF_UI_SEL_FAILURE);}}头文件2:init_proc_bodystaticintinit_proc_body(UF_UI_selection_p_tselect,void*user_data){intnum_triples=1;6UF_UI_mask_tmask_triples[]={UF_solid_type,0,UF_UI_SEL_FEATURE_BODY};/*enableonlylinesandedges*/if((UF_CALL(UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples,mask_triples)))==0){return(UF_UI_SEL_SUCCESS);}else{return(UF_UI_SEL_FAILURE);}}4,UF_UI_select_with_single_dialog头文件:#includeuf_ui.hchartitle[]=;charcue[]=;intresponse=0;doublecursor[3];tag_tface=NULL;tag_tview=NULL;if(!UF_CALL(UF_UI_select_with_single_dialog(cue,title,UF_UI_SEL_SCOPE_NO_CHANGE,init_proc_face,NULL,&response,&face,cursor,&view))){if(response==UF_UI_OBJECT_SELECTED||response==UF_UI_OBJECT_SELECTED_BY_NAME){printf(objecttag=%d\n,face);}UF_DISP_set_highlight(face,0);//关高亮}5,UF_UI_select_with_class_dialog头文件:#includeuf_ui.h7voidclass_sel_dlg(int*count,tag_p_t*objects){charcue[]=;chartitle[]=;intresponse,sel_count,i;tag_p_tsel_objects;if((UF_CALL(UF_UI_select_with_class_dialog(cue,title,UF_UI_SEL_SCOPE_NO_CHANGE,init_proc_face,NULL,&response,&sel_count,&sel_objects)))==0){printf(objectcount=%d\n,sel_count);if(response==UF_UI_OK&&sel_count0){*objects=sel_objects;*count=sel_count;for(i=0;isel_count;i++){printf(objecttag=%d\n,sel_objects[i]);UF_DISP_set_highlight(sel_objects[i],0);}UF_free(objects);}}}6,UF_MODL_delete_object_parms//消参头文件:#includeuf_modl.h#includeuf_modl_utilities.huf_list_p_tobj_list;UF_CALL(UF_MODL_create_list(&obj_list));UF_CALL(UF_MODL_put_list_item(obj_list,));UF_CALL(UF_MODL_put_list_item(obj_list,));UF_MODL_delete_object_parms(obj_list);UF_MODL_delete_list(&obj_list);UF_OBJ_delete_object();87,UF_CURVE_create_arc//通过圆心,半径画圆头文件:#includeuf_csys.h#includeuf_curve.htag_tarc,wcs_tag;UF_CSYS_ask_wcs(&wcs_tag);UF_CURVE_arc_tarc_coords;UF_CSYS_ask_matrix_of_object(wcs_tag,&wcs_tag);arc_coords.matrix_tag=wcs_tag;arc_coords.start_angle=0.0;arc_coords.end_angle=360.0*DEGRA;arc_coords.arc_center[0]=center[0];//arc_coords.arc_center[1]=center[1];//arc_coords.arc_center[2]=center[2];//arc_coords.radius=500;UF_CURVE_create_arc(&arc_coords,&arc_id);8,UF_OBJ_set_name(tag,name);//设置名字头文件#includeuf_obj.h9,name开关intname_status;UF_DISP_ask_name_display_status(&name_status);if(name_status==UF_DISP_NAME_DISPLAY_OFF){name_status=UF_DISP_NAME_DISPLAY_ON;}else{name_status=UF_DISP_NAME_DISPLAY_OFF;}UF_DISP_set_name_display_status(name_status);10,UF_OBJ_set_color(tag,color);//设置颜色9头文件#includeuf_obj.h11,UF_OBJ_set_layer(tag,layer);//设置层头文件#includeuf_obj.h12,UF_CALL头文件#includeuf.hintUF_CALL(interrorCode){if(errorCode){charmessage[133]=;UF_get_fail_message(errorCode,message);uc1601(message,1);}return(errorCode);}13,UF_PAR