- 438.00 KB
- 2022-04-22 11:21:58 发布
- 1、本文档共5页,可阅读全部内容。
- 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
- 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
- 文档侵权举报电话:19940600175。
'基于UG平台的二次开发习题解答盐城工学院优集学院二○一○年二月55
基于NX平台的二次开发课程习题解答课程代码:22021021学时数:32适用专业:机械设计制造及其自动化第1章二次开发应用初步1、创建一个“Hello,你的姓名”消息对话框。要求:利用UG自带的向导创建二次开发工程项目;利用单按钮消息对话框(UC1601())创建“Hello”加你的姓名。源程序:extern"C"DllExportvoidufusr(char*parm,int*returnCode,intrlen){/*InitializetheAPIenvironment*/interrorCode=UF_initialize();if(0==errorCode){/*TODO:Addyourapplicationcodehere*/uc1601("Hello,你的姓名",1);/*TerminatetheAPIenvironment*/errorCode=UF_terminate();}/*Printoutanyerrormessages*/PrintErrorMessage(errorCode);}55
第2章二次开发应用框架1、创建圆柱体要求:创建一个Win32项目,并设置工程项目的属性,使其能够编译UG二次开发工程项目;创建基本体素特征圆柱体。源程序:#include#include#include#includestaticvoiddo_ugopen_api(void){UF_FEATURE_SIGNsign=UF_NULLSIGN;doublecyl_orig[3]={0.0,0.0,0.0};char*cyl_height="100";char*cyl_diam="100";doubledirection[3]={-1,0,0};tag_tcyl_obj;UF_MODL_create_cyl1(sign,cyl_orig,cyl_height,cyl_diam,direction,&cyl_obj);}externvoidufusr(char*param,int*retcode,intrlen){if((UF_initialize())!=0)return;do_ugopen_api();UF_terminate();return;}externintufusr_ask_unload(void){return(UF_UNLOAD_IMMEDIATELY);}externvoidufusr_cleanup(void){return;}2、创建一个凸台要求:凸台高H为你的学号,下底面直径B55
_diam为高h的两倍,上底面直径T_diam与高h相等。源程序:#include#include#include#includestaticvoidcreate_block(void){UF_FEATURE_SIGNsign=UF_NULLSIGN;UF_FEATURE_SIGNsign1=UF_POSITIVE;doublecone_orig[3]={0.0,0.0,20.0};char*height=“height=20.0”;char*diam[2]={“.0”,“.0”};doubledirection[3]={0.0,0.0,-1.0};tag_tcone_obj;UF_MODL_create_cone1(sign,cone_orig,height,diam,direction,&cone_obj);}externvoidufusr(char*param,int*retcode,intrlen){if((UF_initialize())!=0)return;create_block();UF_terminate();return;}externintufusr_ask_unload(void){return(UF_UNLOAD_IMMEDIATELY);}externvoidufusr_cleanup(void){return;}55
第3章编程基础1、创建一个垫圈要求:采用表达式控制平垫圈的参数(建立垫圈,已知道d2=d1/2;h=d1/4。要求在执行程序后h=d1/2);改变平垫圈颜色为红色。源程序:#include#include#include#include#include#defineUF_CALL(X)(report(__FILE__,__LINE__,#X,(X)))staticintreport(char*file,intline,char*call,intirc){if(irc){charmessg[133];printf("%s,line%d:%sn",file,line,call);(UF_get_fail_message(irc,messg))?printf("returneda%dn",irc):printf("returnederror%d:%sn",irc,messg);}return(irc);}staticvoidcreate_gasket(void){UF_FEATURE_SIGNsign=UF_NULLSIGN;UF_FEATURE_SIGNsign1=UF_NEGATIVE;doubleorigin[3]={0.0,0.0,0.0};doubledirection[3]={0.0,0.0,1.0};UF_MODL_create_exp("length=150");char*diam="length/3";char*diam1="length/5";char*height="length/75";char*height1="length/75";55
tag_tcyl_obj;tag_tcyl_obj1;tag_tgasket_obj_id;UF_CALL(UF_MODL_create_cyl1(sign,origin,height,diam,direction,&cyl_obj));UF_CALL(UF_MODL_create_cyl1(sign1,origin,height1,diam1,direction,&cyl_obj1));uc1601("请按下OK键,实体的颜色将会变成红色",1);UF_MODL_ask_feat_body(cyl_obj1,&gasket_obj_id);UF_OBJ_set_color(gasket_obj_id,186);}/*ARGSUSED*/voidufusr(char*param,int*retcode,intparamLen){if(!UF_CALL(UF_initialize())){create_gasket();UF_CALL(UF_terminate());}}intufusr_ask_unload(void){return(UF_UNLOAD_IMMEDIATELY);}2、创建表达式要求:创建两个矩形块两点间的距离表达式,并为距离表达式重命名,最后将当前部件中的表达式输出到信息窗口中。源程序:#include#include#include#include#include#include#include#include#include55
#includevoidufusr(char*param,int*retcode,intparam_len){if(!UF_initialize()){/*定义Block的参数*/doubleblock_orig[3]={0.0,0.0,0.0};doubleblock_orig1[3]={5.0,5.0,5.0};char*block_len[3]={"1","2","3"};tag_tblk_obj,blk_obj1;/*定义表达式的参数*/char*string;tag_t*exps;intnumber_of_exps=0,i=0;charbuf[UF_UI_MAX_STRING_LEN+1];tag_tpart,feat_tag,exp_tag,solid,solid_body[2];inttype,subtype;/*重命名距离表达式的参数*/char*exp_string,*lhs_str,*rhs_str;char*exp_name;tag_texp1_tag;/*创建两个Block*/UF_MODL_create_block1(UF_NULLSIGN,block_orig,block_len,&blk_obj);UF_MODL_create_block1(UF_NULLSIGN,block_orig1,block_len,&blk_obj1);UF_UI_open_listing_window();/*找出所有的Solid实体*/if((part=UF_PART_ask_display_part())==NULL_TAG){UF_UI_write_listing_window("Failedtogetparttagn");return;}solid=NULL_TAG;while(i<2){type=UF_solid_type;UF_OBJ_cycle_objs_in_part(part,type,&solid);UF_OBJ_ask_type_and_subtype(solid,&type,&subtype);if(subtype==UF_solid_body_subtype)solid_body[i++]=solid;}/*创建一个距离表达式*/55
UF_GEXP_create_distance(solid_body[0],NULL_TAG,solid_body[1],NULL_TAG,&feat_tag,&exp_tag);/*为距离表达式重新命名*/UF_MODL_ask_exp_tag_string(exp_tag,&exp_string);UF_MODL_dissect_exp_string(exp_string,&lhs_str,&rhs_str,&exp1_tag);UF_MODL_rename_exp(lhs_str,"geo_exp");UF_free(exp_string);UF_free(lhs_str);UF_free(rhs_str);/*获取表达式的数量*/UF_MODL_ask_exps_of_part(part,&number_of_exps,&exps);sprintf(buf,"当前部件文件一共有%d个表达式。n",number_of_exps);UF_UI_write_listing_window(buf);UF_UI_write_listing_window("其中几何表达式为:n");/*获取距离表达式并显示在列表框中*/for(i=0;i#include#include#include#include#includeexternvoidufusr(char*param,int*retcod,intparam_len){/*对话框设置*/char*cp1="请选择";intip2=0;charcp3[4][38]={"创建一个块(Block)","创建一个圆柱(Cylinder)","创建一个圆锥(Cone)","创建一个球体(Sphere)"};intip4=4;intvalue;tag_tview_tag=NULL_TAG;UF_FEATURE_SIGNsign=UF_NULLSIGN;/*Block的变量声明区*/doubleblk_corner[3]={0.0,0.0,0.0};char*blk_edge_len[3]={"10.0","20.0","30.0"};tag_tblk_obj_id;55
/*Cylinder的变量声明区*/doublecyl_origin[3]={0.0,0.0,0.0};char*cyl_height="20.0";char*cyl_diam="10.0";doublecyl_direction[3]={0.0,0.0,1.0};tag_tcyl_obj_id;/*Cone的变量声明区*/doublecone_origin[3]={0.0,0.0,0.0};char*cone_height="20.0";char*cone_diam[2]={"30.0","20.0"};doublecone_direction[3]={0.0,0.0,1.0};tag_tcone_obj_id;/*Sphere的变量声明区*/doublesphere_center[3]={0.0,0.0,0.0};char*sphere_diam="30.0";tag_tsphere_obj_id;if(!UF_initialize()){/*显示菜单*/value=uc1603(cp1,ip2,cp3,ip4);switch(value){case5:/*创建Block(块)*/UF_MODL_create_block1(sign,blk_corner,blk_edge_len,&blk_obj_id);break;case6:/*创建Cylinder(圆柱)*/UF_MODL_create_cyl1(sign,cyl_origin,cyl_height,cyl_diam,cyl_direction,&cyl_obj_id);break;case7:/*创建Cone(圆锥)*/UF_MODL_create_cone1(sign,cone_origin,cone_height,cone_diam,cone_direction,&cone_obj_id);break;case8:/*创建Sphere(球体)*/55
UF_MODL_create_sphere1(sign,sphere_center,sphere_diam,&sphere_obj_id);break;default:uc1601("发生了错误!",0);}/*调整视图到合适的大小*/UF_VIEW_ask_work_view(&view_tag);UF_VIEW_fit_view(view_tag,0.7);/*保存文件*/UF_PART_save();UF_terminate();}}2、利用UIStyler、Menu等工具创建一个对话框来生成垫圈。要求:对话框通过菜单和工具条激活;平垫圈的尺寸由用户通过对话框输入,对话框如下图如示:源程序:(a)菜单文件xx.menVERSION120!------------------------------55
EDITUG_GATEWAY_MAIN_MENUBARTOP_MENUCASCADE_BUTTONCUSTOM_MYMENULABEL实例END_OF_TOP_MENUMENUCUSTOM_MYMENUBUTTONMAKE_GASKETLABEL创建垫圈...ACTIONSDianQuan.dlgEND_OF_MENU(b)工具条文件xx.tbrTITLE实例VERSION170!------------------------------BUTTONMAKE_GASKETLABEL创建垫圈(c)主程序代码intZ_ok_cb(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data){UF_STYLER_item_value_type_tdate;UF_FEATURE_SIGNsign=UF_NULLSIGN;doubleorigin[3]={0.0,0.0,0.0};charheight[10];//厚度chardiam[10];//外径doubledirection[3]={0.0,0.0,1.0};tag_tcyl_obj_id;doublelocation[3]={0.0,0.0,0.0};doublehole_dir[3]={0.0,0.0,-1.0};charhole_diam[10];//内径constchar*angle="0";tag_tface_li;tag_tface_t1;tag_thole_feat_id;uf_list_p_tface_list;/*MakesureUserFunctionisavailable.*/if(UF_initialize()!=0)return(UF_UI_CB_CONTINUE_DIALOG);/*----Enteryourcallbackcodehere-----*/55
date.item_attr=UF_STYLER_VALUE;date.item_id=Z_REAL_IN;UF_STYLER_ask_value(dialog_id,&date);sprintf(hole_diam,"%f",date.value.real);UF_STYLER_free_value(&date);date.item_attr=UF_STYLER_VALUE;date.item_id=Z_REAL_OUT;UF_STYLER_ask_value(dialog_id,&date);sprintf(diam,"%f",date.value.real);UF_STYLER_free_value(&date);date.item_attr=UF_STYLER_VALUE;date.item_id=Z_REAL_H;UF_STYLER_ask_value(dialog_id,&date);sprintf(height,"%f",date.value.real);UF_STYLER_free_value(&date);UF_MODL_create_cyl1(sign,origin,height,diam,direction,&cyl_obj_id);UF_MODL_ask_feat_faces(cyl_obj_id,&face_list);UF_MODL_ask_list_item(face_list,0,&face_li);UF_MODL_ask_list_item(face_list,1,&face_t1);UF_MODL_create_simple_hole(location,direction,hole_diam,height,angle,face_li,face_t1,&hole_feat_id);UF_terminate();/*Callbackacknowledged,terminatedialog*//*ItisSTRONGLYrecommendedthatyouexityour*//*callbackwithUF_UI_CB_EXIT_DIALOGinaokcallback.*//*return(UF_UI_CB_EXIT_DIALOG);*/return(UF_UI_CB_EXIT_DIALOG);}3、创建一个点收集器要求:能够收集用户所选择的点,并在单击“OK”和“Yes”按钮后,将用户所选的点的坐标信息在UG信息窗口中显示出来。源程序:55
voiddo_ugopen_api(){charsMessage[]="点收集器_朱佳乐";logicallCoincidentpoints=true;UF_UI_chained_points_p_tchained_points;intiCount;intiResponse;UF_UI_select_point_collection(sMessage,lCoincidentpoints,&chained_points,&iCount,&iResponse);char*str=newchar[100];if(iResponse==UF_UI_OK){UF_UI_open_listing_window();UF_UI_write_listing_window("");UF_UI_write_listing_window("X坐标:");UF_UI_write_listing_window("");UF_UI_write_listing_window("Y坐标:");UF_UI_write_listing_window("");UF_UI_write_listing_window("Z坐标:");UF_UI_write_listing_window("n");for(inti=1;i<=iCount;i++){sprintf(str,"%12f,%12f,%12f",chained_points->pt[0],chained_points->pt[1],chained_points->pt[2]);UF_UI_write_listing_window(str);UF_UI_write_listing_window("n");chained_points++;}}delete[]str;}55
第5章外部数据访问1、访问外部Excel数据。要求:利用存贮在外部Excel中的数据创建圆柱。ab501050305050源程序:#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include55
#defineUF_CALL(X)(report(__FILE__,__LINE__,#X,(X)))staticintreport(char*file,intline,char*call,intirc){if(irc){charsFailMessage[133];UF_get_fail_message(irc,sFailMessage);charsWholeMessage[256];sprintf(sWholeMessage,"FileName:%snLine:%dnFunction:%snErrorCode:%dnMessage:%s",file,line,call,irc,sFailMessage);MessageBox(NULL,sWholeMessage,"ErrorinFunction",MB_OK|MB_ICONWARNING|MB_SYSTEMMODAL);}return(irc);}staticvoiderror_return(char*msg){fprintf(stderr,"n+++ERROR:%s.nn",msg);exit(1);}staticvoidreport_error(intresult,char*alt_msg){charerr_message[200];intfound=UF_get_fail_message(result,err_message);if(found!=0)error_return(alt_msg);elseerror_return(err_message);}staticvoidcreate_cyl(doubleorigin_y,char*cyl_height,char*cyl_diam){UF_FEATURE_SIGNsign=UF_NULLSIGN;doublecyl_origin[3]={0.0,0.0,0.0};doublecyl_direction[3]={0.0,0.0,1.0};tag_tcyl_obj_id;55
cyl_origin[1]=origin_y;UF_MODL_create_cyl1(sign,cyl_origin,cyl_height,cyl_diam,cyl_direction,&cyl_obj_id);}staticvoiddo_ugopen_api(void){CDatabaseDatabase;//定义一个MFC的CDatabse数据库类对象DatabseCStringSQLCommand="select*fromppdc";//SQL查询语句DWORDdwOptions=0;//设置连接的建立方式CDBVarianttemp;//数据库数据通用类型intresult;//储存返回值的变量charcyl_height[133];charcyl_diam[133];double*cyl=NULL;try{result=Database.OpenEx("DSN=ugsc",dwOptions);//打开数据库if(result!=0)//如果成功打开{CRecordsetrs(&Database);//定义记录集if(rs.Open(CRecordset::snapshot,SQLCommand)!=false){rs.MoveFirst();shortnFields=rs.GetODBCFieldCount();//获取记录的字段数目while(!rs.IsEOF()){cyl=(double*)malloc(nFields*sizeof(double));for(shortindex=0;indexm_strError);pe->Delete();}}voidufusr(char*param,int*retcode,intparam_len){if(!UF_CALL(UF_initialize())){do_ugopen_api();UF_CALL(UF_terminate());}}externintufusr_ask_unload(void){/*unloadimmediatelyafterapplicationexits*/return(UF_UNLOAD_IMMEDIATELY);}2、创建标准件六角头螺栓参数化设计系统。要求:六角头螺栓几何参数存储在外部Access数据库(.mdb)中,采用ODBC或ADO访问外部数据;根据用户选择的相应规格创建六角头螺栓,界面如下图所示。55
源程序:#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#defineSCREW_CB_COUNT(3+1)#defineSCREW_BITMAP_SCREW("BITMAP_SCREW")#defineSCREW_SEP_1("SEP_1")#defineSCREW_OPTION_CHOICE("OPTION_CHOICE")#defineSCREW_DIALOG_OBJECT_COUNT(3)#defineSCREW_OPTION_CHOICE_COUNT14#defineLAYER_SOLID1#defineLAYER_SKETCH21#defineLAYER_CURVE4155
classCscrew:publicCRecordset{public:Cscrew(CDatabase*pDatabase=NULL);DECLARE_DYNAMIC(Cscrew)CStringm_spec;//螺纹规格doublem_d;//螺栓轴直径doublem_b;//螺纹长度doublem_a;//a(max)doublem_e;//螺栓帽外接圆直径doublem_k;//公称doublem_r;//r(min)doublem_s;//螺栓帽内接圆直径doublem_l;//螺栓轴长度doublem_weight;//100mm长的重量(kg)public:virtualCStringGetDefaultSQL();virtualvoidDoFieldExchange(CFieldExchange*pFX);};intSCREW_ok_cb(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data);intSCREW_cancel_cb(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data);intSCREW_constructor(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data);voidfitview(void);voidcreate(Cscrew*ScrewSet);IMPLEMENT_DYNAMIC(Cscrew,CRecordset)staticUF_STYLER_callback_info_tSCREW_cbs[SCREW_CB_COUNT]={{UF_STYLER_DIALOG_INDEX,UF_STYLER_CONSTRUCTOR_CB,0,SCREW_constructor},{UF_STYLER_DIALOG_INDEX,UF_STYLER_OK_CB,0,SCREW_ok_cb},{UF_STYLER_DIALOG_INDEX,UF_STYLER_CANCEL_CB,0,SCREW_cancel_cb},{UF_STYLER_NULL_OBJECT,UF_STYLER_NO_CB,0,0}};staticUF_MB_styler_actions_tactions[]={{"screw.dlg",NULL,SCREW_cbs,UF_MB_STYLER_IS_NOT_TOP},{NULL,NULL,NULL,0}};Cscrew::Cscrew(CDatabase*pdb):CRecordset(pdb){m_spec=L"";m_d=0.0;m_b=0.0;55
m_a=0.0;m_e=0.0;m_k=0.0;m_r=0.0;m_s=0.0;m_l=0.0;m_weight=0.0;m_nFields=10;m_nDefaultType=snapshot;}CStringCscrew::GetDefaultSQL(){return_T("[screw]");}voidCscrew::DoFieldExchange(CFieldExchange*pFX){pFX->SetFieldType(CFieldExchange::outputColumn);RFX_Text(pFX,_T("[spec]"),m_spec);RFX_Double(pFX,_T("[d]"),m_d);RFX_Double(pFX,_T("[b]"),m_b);RFX_Double(pFX,_T("[a]"),m_a);RFX_Double(pFX,_T("[e]"),m_e);RFX_Double(pFX,_T("[k]"),m_k);RFX_Double(pFX,_T("[r]"),m_r);RFX_Double(pFX,_T("[s]"),m_s);RFX_Double(pFX,_T("[l]"),m_l);RFX_Double(pFX,_T("[weight]"),m_weight);}externvoidufsta(char*param,int*retcode,intrlen){interror_code;if((UF_initialize())!=0)return;if((error_code=UF_MB_add_styler_actions(actions))!=0){charfail_message[133];UF_get_fail_message(error_code,fail_message);printf("%sn",fail_message);}UF_terminate();return;}/*构造函数*/55
intSCREW_constructor(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data){if(UF_initialize()!=0)return(UF_UI_CB_CONTINUE_DIALOG);UF_STYLER_item_value_type_tdata;char*names[SCREW_OPTION_CHOICE_COUNT];try{CDatabasedatabase;database.OpenEx("DSN=screw",CDatabase::noOdbcDialog);CscrewScrewSet;ScrewSet.Open(CRecordset::snapshot,"select*fromscrew_table");inti=0;do{if(ScrewSet.IsEOF())break;strcpy(names[i++]=(char*)malloc(sizeof(char)*4),ScrewSet.m_spec);ScrewSet.MoveNext();}while(1);database.Close();data.item_id=SCREW_OPTION_CHOICE;data.item_attr=UF_STYLER_SUBITEM_VALUES;data.count=SCREW_OPTION_CHOICE_COUNT;data.value.strings=names;UF_STYLER_set_value(dialog_id,&data);data.item_attr=UF_STYLER_VALUE;data.value.integer=0;UF_STYLER_set_value(dialog_id,&data);for(i=0;im_strError);pe->Delete();}UF_terminate();return(UF_UI_CB_CONTINUE_DIALOG);55
}intSCREW_ok_cb(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data){if(UF_initialize()!=0)return(UF_UI_CB_CONTINUE_DIALOG);/*如果当前没有打开一个PART文件的话,退出*/tag_tis_part_opened;is_part_opened=UF_PART_ask_display_part();if(NULL_TAG==is_part_opened){AfxMessageBox("请先新建一个部件文件,然后再进行此项操作。");return(UF_UI_CB_EXIT_DIALOG);}/*获取选择的项目,从数据库里找出相应的记录*/UF_STYLER_item_value_type_tdata0,data1;data0.item_id=SCREW_OPTION_CHOICE;data1.item_id=SCREW_OPTION_CHOICE;data0.item_attr=UF_STYLER_VALUE;data1.item_attr=UF_STYLER_SUBITEM_VALUES;UF_STYLER_ask_value(dialog_id,&data0);UF_STYLER_ask_value(dialog_id,&data1);charbuf[4];strcpy(buf,data1.value.strings[data0.value.integer]);UF_STYLER_free_value(&data1);charsql[1000];sprintf(sql,"Select*fromscrew_tablewherespec="%s"",buf);CDatabasedatabase;database.OpenEx("DSN=screw",CDatabase::noOdbcDialog);CscrewScrewSet;ScrewSet.Open(CRecordset::snapshot,sql);database.Close();/*创建螺栓*/create(&ScrewSet);/*调整视图显示模式及比例*/fitview();/*保存部件文件*/UF_PART_save();55
UF_terminate();return(UF_UI_CB_EXIT_DIALOG);}intSCREW_cancel_cb(intdialog_id,void*client_data,UF_STYLER_item_value_type_p_tcallback_data){if(UF_initialize()!=0)return(UF_UI_CB_CONTINUE_DIALOG);AfxMessageBox("用户取消了本次操作!");UF_terminate();return(UF_UI_CB_EXIT_DIALOG);/*UF_UI_CB_CONTINUE_DIALOG*/}/*调整视图显示模式及比例*/voidfitview(void){tag_tview_tag=NULL_TAG;UF_VIEW_visualization_tview_data;UF_VIEW_ask_work_view(&view_tag);UF_VIEW_ask_visualization(view_tag,&view_data);view_data.display_mode=UF_VIEW_FULLY_SHADED;UF_VIEW_set_visualization(view_tag,&view_data);UF_VIEW_fit_view(view_tag,0.7);}/*创建螺栓*/voidcreate(Cscrew*ScrewSet){/*创建六条直线并拉伸*/uf_list_p_tskt_line_list;UF_CURVE_line_tskt_lines[6];tag_tskt_line_tags[6];UF_LAYER_set_status(LAYER_SKETCH,UF_LAYER_WORK_LAYER);skt_lines[0].start_point[0]=ScrewSet->m_e/2.0;skt_lines[0].start_point[1]=0.0;skt_lines[0].end_point[0]=ScrewSet->m_e/2.0*cos(60.0*DEGRA);skt_lines[0].end_point[1]=ScrewSet->m_e/2.0*sin(60.0*DEGRA);skt_lines[1].start_point[0]=skt_lines[0].end_point[0];skt_lines[1].start_point[1]=skt_lines[0].end_point[1];skt_lines[1].end_point[0]=-skt_lines[1].start_point[0];skt_lines[1].end_point[1]=skt_lines[1].start_point[1];55
skt_lines[2].start_point[0]=skt_lines[1].end_point[0];skt_lines[2].start_point[1]=skt_lines[1].end_point[1];skt_lines[2].end_point[0]=-skt_lines[0].start_point[0];skt_lines[2].end_point[1]=skt_lines[0].start_point[1];skt_lines[3].start_point[0]=skt_lines[2].end_point[0];skt_lines[3].start_point[1]=skt_lines[2].end_point[1];skt_lines[3].end_point[0]=-skt_lines[0].end_point[0];skt_lines[3].end_point[1]=-skt_lines[0].end_point[1];skt_lines[4].start_point[0]=skt_lines[3].end_point[0];skt_lines[4].start_point[1]=skt_lines[3].end_point[1];skt_lines[4].end_point[0]=-skt_lines[4].start_point[0];skt_lines[4].end_point[1]=skt_lines[4].start_point[1];skt_lines[5].start_point[0]=skt_lines[4].end_point[0];skt_lines[5].start_point[1]=skt_lines[4].end_point[1];skt_lines[5].end_point[0]=skt_lines[0].start_point[0];skt_lines[5].end_point[1]=skt_lines[0].start_point[1];UF_MODL_create_list(&skt_line_list);for(inti=0;i<6;i++){skt_lines[i].start_point[2]=0.0;skt_lines[i].end_point[2]=0.0;UF_CURVE_create_line(&skt_lines[i],&skt_line_tags[i]);UF_MODL_put_list_item(skt_line_list,skt_line_tags[i]);}charskt_name[30]="SKT_BASE";doubleskt_matrix[9]={1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0};tag_tskt_tag;UF_SKET_initialize_sketch(skt_name,&skt_tag);UF_SKET_create_sketch(skt_name,2,skt_matrix,NULL,NULL,1,&skt_tag);UF_SKET_add_objects(skt_tag,6,skt_line_tags);UF_SKET_terminate_sketch();UF_LAYER_set_status(LAYER_SOLID,UF_LAYER_WORK_LAYER);UF_LAYER_set_all_but_work(UF_LAYER_INACTIVE_LAYER);charlimit0[10];charlimit1[10];char*limit[2]={limit0,limit1};doublepoint[3]={0.0,0.0,0.0};doubledirection[3]={0.0,0.0,1.0};55
uf_list_p_tfeature_list;tag_tbase_tag;strcpy(limit0,"0.0");sprintf(limit1,"%.3f",ScrewSet->m_k);UF_MODL_create_extruded2(skt_line_list,"0.0",limit,point,direction,UF_NULLSIGN,&feature_list);UF_MODL_ask_list_item(feature_list,0,&base_tag);UF_MODL_delete_list(&feature_list);UF_MODL_delete_list(&skt_line_list);/*修剪拉伸体*/UF_LAYER_set_status(LAYER_CURVE,UF_LAYER_WORK_LAYER);skt_lines[0].start_point[0]=ScrewSet->m_e/2.0;skt_lines[0].start_point[2]=0.0;skt_lines[0].end_point[0]=skt_lines[0].start_point[0]*0.85;skt_lines[0].end_point[2]=skt_lines[0].start_point[2];skt_lines[1].start_point[0]=skt_lines[0].end_point[0];skt_lines[1].start_point[2]=skt_lines[0].end_point[2];skt_lines[1].end_point[0]=skt_lines[0].start_point[0];skt_lines[1].end_point[2]=ScrewSet->m_k*0.2;skt_lines[2].start_point[0]=skt_lines[1].end_point[0];skt_lines[2].start_point[2]=skt_lines[1].end_point[2];skt_lines[2].end_point[0]=skt_lines[0].start_point[0];skt_lines[2].end_point[2]=skt_lines[0].start_point[2];UF_MODL_create_list(&skt_line_list);for(i=0;i<3;i++){skt_lines[i].start_point[1]=0.0;skt_lines[i].end_point[1]=0.0;UF_CURVE_create_line(&skt_lines[i],&skt_line_tags[i]);UF_MODL_put_list_item(skt_line_list,skt_line_tags[i]);}UF_LAYER_set_status(LAYER_SOLID,UF_LAYER_WORK_LAYER);UF_LAYER_set_all_but_work(UF_LAYER_INACTIVE_LAYER);strcpy(limit0,"0.0");strcpy(limit1,"360.0");tag_trevolve_tag;UF_MODL_create_revolved1(skt_line_list,limit,point,direction,UF_NEGATIVE,base_tag,&feature_list);UF_MODL_ask_list_item(feature_list,0,&revolve_tag);UF_MODL_delete_list(&skt_line_list);55
/*在拉伸体上创建凸台*/uf_list_p_tbase_face_list;chardiame[10];charheight[10];tag_tface_li;tag_tboss_tag;UF_MODL_ask_feat_faces(base_tag,&base_face_list);UF_MODL_ask_list_item(base_face_list,7,&face_li);point[2]=ScrewSet->m_k;sprintf(diame,"%.3f",ScrewSet->m_d);sprintf(height,"%.3f",ScrewSet->m_l);UF_MODL_create_boss(point,direction,diame,height,"0.0",face_li,&boss_tag);UF_MODL_delete_list(&base_face_list);/*在凸台上打螺纹*/UF_MODL_symb_thread_data_tthread_parameters;tag_tsymb_thread_tag;uf_list_p_tboss_face_list;UF_MODL_ask_feat_faces(boss_tag,&boss_face_list);UF_MODL_ask_list_item(boss_face_list,1,&thread_parameters.cyl_face);UF_MODL_ask_list_item(boss_face_list,0,&thread_parameters.start_face);UF_MODL_delete_list(&boss_face_list);thread_parameters.axis_direction[0]=0.0;thread_parameters.axis_direction[1]=0.0;thread_parameters.axis_direction[2]=-1.0;thread_parameters.include_instances=UF_MODL_INCL_INSTANCES;thread_parameters.rotation=UF_MODL_RIGHT_HAND;thread_parameters.length_flag=UF_MODL_FIXED_LENGTH;thread_parameters.tapered=UF_MODL_NON_TAPERED;thread_parameters.num_starts=1;thread_parameters.form="Metric";thread_parameters.method="CUT";thread_parameters.callout=NULL;charmajor_dia[10];charminor_dia[10];chartapped_dia[10];charlength[10];charpitch[10];thread_parameters.major_dia=major_dia;thread_parameters.minor_dia=minor_dia;thread_parameters.tapped_dia=tapped_dia;thread_parameters.length=length;thread_parameters.pitch=pitch;sprintf(major_dia,"%.3f",ScrewSet->m_d);55
sprintf(minor_dia,"%.3f",ScrewSet->m_d*0.8);sprintf(tapped_dia,"%.3f",ScrewSet->m_d*0.9);sprintf(length,"%.3f",ScrewSet->m_l);sprintf(pitch,"%.3f",ScrewSet->m_d*0.125);thread_parameters.angle="60.0";UF_MODL_create_symb_thread(&thread_parameters,&symb_thread_tag);}55
第6章零件设计1、利用函数UF_MODL_create_extruded创建拉伸特征要求:创建四根直线用来定义拉伸特征截面线串,由于在函数UF_MODL_create_extruded中定义截面线串采用链表格式,因此需要将定义拉伸特征截面线的四根直线放进链表中。源程序:#include#include#include#include#includevoidufusr(char*param,int*retcode,intparamLen){inti;tag_tview_tag=NULL_TAG;/*定义四根线,作为扫描的截面线串*/UF_CURVE_line_tsline1,sline2,sline3,sline4;tag_tline1,line2,line3,line4;tag_tgenerators[4];/*定义拉伸特征参数*/uf_list_p_tobjects;char*taper_angle="0.0";char*limit[2]={"2.0","5.0"};doublepoint[3]={0.0,0.0,0.0};doubledirection[3]={0.0,0.0,1.0};UF_FEATURE_SIGNsign=UF_NULLSIGN;uf_list_p_tfeatures;if(!UF_initialize()){/*创建线#1*/sline1.start_point[0]=0.0;sline1.start_point[1]=0.0;sline1.start_point[2]=0.0;sline1.end_point[0]=0.0;sline1.end_point[1]=1.0;55
sline1.end_point[2]=0.0;UF_CURVE_create_line(&sline1,&line1);/*创建线#2*/sline2.start_point[0]=0.0;sline2.start_point[1]=1.0;sline2.start_point[2]=0.0;sline2.end_point[0]=2.5;sline2.end_point[1]=3.5;sline2.end_point[2]=0.0;UF_CURVE_create_line(&sline2,&line2);/*创建线#3*/sline3.start_point[0]=2.5;sline3.start_point[1]=3.5;sline3.start_point[2]=0.0;sline3.end_point[0]=1.0;sline3.end_point[1]=0.0;sline3.end_point[2]=0.0;UF_CURVE_create_line(&sline3,&line3);/*创建线#4*/sline4.start_point[0]=1.0;sline4.start_point[1]=0.0;sline4.start_point[2]=0.0;sline4.end_point[0]=0.0;sline4.end_point[1]=0.0;sline4.end_point[2]=0.0;UF_CURVE_create_line(&sline4,&line4);/*把四根线的tag放入数组*/generators[0]=line1;generators[1]=line2;generators[2]=line3;generators[3]=line4;/*拉伸(extruded)*//*创建一个链表,以存放扫描的截面线串*/UF_MODL_create_list(&objects);for(i=0;i<4;i++){UF_MODL_put_list_item(objects,generators[i]);}UF_MODL_create_extruded(objects,taper_angle,limit,point,direction,sign,&features);UF_MODL_delete_list(&objects);/*调整视图到合适的大小*/55
UF_VIEW_ask_work_view(&view_tag);UF_VIEW_fit_view(view_tag,0.7);/*保存部件文件*/UF_PART_save();UF_terminate();}}2、创建成型特征矩形腔要求:利用矩形腔必须与两个基准面进行相对定位源程序:/*定义全局变量,用于转递相对定位的目标边*/tag_tedge_blk[12];/*注册型腔定位的用户函数*/intrpo_routine_pocket(tag_tobj_id){intirc=0,i;uf_list_p_tedge_list;intcount_list;tag_ttem_tag,*edge_pock;edge_pock=(tag_t*)malloc(12*sizeof(tag_t));tag_t*obj_id_target,*obj_id_tool;obj_id_target=(tag_t*)malloc(3*sizeof(tag_t));55
obj_id_tool=(tag_t*)malloc(3*sizeof(tag_t));char*constraint_value[]={"0.0","15.0"};char*constraint_array[]={"PARA_EDGE_PARMS","PARA_EDGE_PARMS"};inttarget_qualifier[]={UF_MODL_ENDPOINT_1,UF_MODL_ENDPOINT_1};inttool_qualifier[]={UF_MODL_ENDPOINT_1,UF_MODL_ENDPOINT_1};UF_MODL_ask_feat_edges(obj_id,&edge_list);UF_MODL_ask_list_count(edge_list,&count_list);for(i=0;i#include#include#include#include#include#include#include#include#defineEPSILON0.01#defineMAX(x,y)((x)>(y)?(x):(y))#defineMIN(x,y)((x)<(y)?(x):(y))voidufusr(char*param,int*retcode,intparamLen){if(!UF_initialize()){/*临时变量*/inti;intcount;tag_tobject;55
intobject_type;doubleobject_point[3];doubleobject_dir[3];doubleobject_box[6];doubleobject_radius;doubleobject_rad_data;intobject_sense;/*定义创建块特征的参数*/UF_FEATURE_SIGNblk_sign=UF_NULLSIGN;doubleblk_corner_pt[]={0.0,0.0,0.0};char*blk_edge_len_p[]={"60","60","20"};tag_tblk_obj_id;uf_list_p_tblk_obj_list_faces=NULL;/*定义创建拔模特征的参数*/doubletaper_location[]={0.0,0.0,0.0};doubletaper_direction[]={0.0,0.0,1.0};chartaper_angle[]={"10.0"};uf_list_p_ttaper_face_list=NULL;tag_ttaper_obj_id;uf_list_p_ttaper_obj_list_edges=NULL;/*定义创建边倒圆特征的参数*/charblend_radius[]={"10"};uf_list_p_tblend_edge_list=NULL;intblend_smooth_overflow=0;intblend_cliff_overflow=0;intblend_notch_overflow=0;doubleblend_vrb_tool=0.5;tag_tblend_obj_id;doubleproto_point1[3];doubleproto_point2[3];intvertex_count=0;/*定义创建挖空特征的参数*/charhollow_thickness[]={"10"};uf_list_p_thollow_face_list=NULL;tag_thollow_obj_id;/*创建块特征*/UF_MODL_create_block1(blk_sign,blk_corner_pt,blk_edge_len_p,&blk_obj_id);UF_MODL_ask_feat_faces(blk_obj_id,&blk_obj_list_faces);/*获得块上面的标识,用于确定拔模面*/55
UF_MODL_create_list(&taper_face_list);UF_MODL_ask_list_count(blk_obj_list_faces,&count);for(i=0;iEPSILON){UF_MODL_put_list_item(blend_edge_list,object);}}UF_MODL_delete_list(&taper_obj_list_edges);taper_obj_list_edges=NULL;/*创建边倒圆特征*/UF_MODL_create_blend(blend_radius,blend_edge_list,blend_smooth_overflow,blend_cliff_overflow,blend_notch_overflow,blend_vrb_tool,&blend_obj_id);UF_MODL_delete_list(&blend_edge_list);blend_edge_list=NULL;/*获得挖空特征的安置面*/55
UF_MODL_create_list(&hollow_face_list);UF_MODL_ask_list_count(blk_obj_list_faces,&count);for(i=0;i=0.5){UF_MODL_put_list_item(hollow_face_list,object);break;}}UF_MODL_delete_list(&blk_obj_list_faces);blk_obj_list_faces=NULL;/*创建挖空特征*/UF_MODL_create_hollow(hollow_thickness,hollow_face_list,&hollow_obj_id);UF_MODL_delete_list(&hollow_face_list);hollow_face_list=NULL;/*保存部件文件*/UF_PART_save();UF_terminate();}}4、在当前工作部件中,创建零件模型(如下图)。要求:工作部件中只有一个body;零件参数化,可在部件导航器中编辑该零件。55
源程序:tag_tedge_blk[20];staticvoiddo_ugopen_api(){UF_FEATURE_SIGNsign=UF_NULLSIGN;UF_FEATURE_SIGNsign1=UF_POSITIVE;UF_FEATURE_SIGNsign2=UF_NEGATIVE;//创建一个圆柱doubleorigin[3]={0.0,0.0,0.0};doubledirection[3]={0.0,0.0,1.0};char*diam="1.5*10";char*height="2.0*10";tag_tcyl_obj;UF_MODL_create_cyl1(sign,origin,height,diam,direction,&cyl_obj);//创建凸垫doubleblock_orig[3]={-0.625*10,0.0*10,1.125*10};char*block_len[3]={"1.25*10","3.125*10","0.375*10"};tag_tblk_obj;UF_MODL_create_block1(sign1,block_orig,block_len,&blk_obj);//创建凸垫doubleblock_orig1[3]={-0.625*10,2.75*10,0.0*10};char*block_len1[3]={"1.25*10","0.375*10","1.5*10"};tag_tblk_obj1;UF_MODL_create_block1(sign1,block_orig1,block_len1,&blk_obj1);//创建孔char*diam1="0.75*10";tag_tcyl_obj1;UF_MODL_create_cyl1(sign2,origin,height,diam1,direction,&cyl_obj1);55
//创建孔doubleorigin1[3]={0.0,2.125*10,1.125*10};char*diam2="0.5*10";char*height1="0.375*10";tag_tcyl_obj2;UF_MODL_create_cyl1(sign2,origin1,height1,diam2,direction,&cyl_obj2);//创建孔doubleorigin2[3]={0.0,2.75*10,0.5*10};doubledirection1[3]={0.0,1.0,0.0};tag_tcyl_obj3;UF_MODL_create_cyl1(sign2,origin2,height1,diam2,direction1,&cyl_obj3);//创建倒角tag_tparts_obj_id;tag_ttem_tag;UF_MODL_ask_feat_body(cyl_obj3,&parts_obj_id);uf_list_p_tedge_list;intcount_list;UF_MODL_ask_body_edges(parts_obj_id,&edge_list);UF_MODL_ask_list_count(edge_list,&count_list);for(inti=0;i#include#include#include#include#include#include#include#include#include/*设置尺寸参数*/voidset_dimension_parameters(void){/*设置变量定义*/charmessage[133];intmpi_array[100];doublempr_array[70];charrad_symbol[27],dia_symbol[27];UF_UI_open_listing_window();UF_UI_write_listing_window("n设置前的系统工程图参数:nn");/*查询设置前的系统制图参数*/UF_DRF_ask_preferences(mpi_array,mpr_array,rad_symbol,dia_symbol);sprintf(message,"尺寸值的小数位数:mpi[3]=%dn公差值的小数位数:mpi[4]=%dn",mpi_array[3],mpi_array[4]);UF_UI_write_listing_window(message);sprintf(message,"公差类型:mpi[6]=%dn上公差:mpr[24]=%fn下公差:mpr[25]=%fn",mpi_array[6],mpr_array[24],mpr_array[25]);UF_UI_write_listing_window(message);/*设置尺寸、公差等制图参数*/mpi_array[3]=2;/*设置尺寸值的小数位*/mpi_array[4]=4;/*设置公差值小数位*/mpi_array[6]=4;/*设置公差类型(单线双向类)*/mpr_array[24]=0.00002;/*设置上公差*/55
mpr_array[25]=0.00002;/*设置下公差*/UF_DRF_set_preferences(mpi_array,mpr_array,rad_symbol,dia_symbol);UF_UI_write_listing_window("nn设置后的系统工程图参数:nn");/*查询设置后的系统制图参数*/UF_DRF_ask_preferences(mpi_array,mpr_array,rad_symbol,dia_symbol);sprintf(message,"尺寸值的小数位数:mpi[3]=%dn公差值的小数位数:mpi[4]=%dn",mpi_array[3],mpi_array[4]);UF_UI_write_listing_window(message);sprintf(message,"公差类型:mpi[6]=%dn上公差:mpr[24]=%fn下公差:mpr[25]=%fn",mpi_array[6],mpr_array[24],mpr_array[25]);UF_UI_write_listing_window(message);}/*设置视图比例*/voidset_view_scale(void){intnum_views=0;logicalauto_update;tag_tdrawing_tag=NULL_TAG;tag_p_tview_list=NULL;tag_texp_tag=NULL_TAG;/*查询当前图纸标识*/UF_DRAW_ask_current_drawing(&drawing_tag);/*获得当前图纸的视图个数及标识*/UF_DRAW_ask_views(drawing_tag,&num_views,&view_list);/*设置视图自动更新*/auto_update=true;if(num_views>0)UF_DRAW_set_auto_update(view_list[0],&auto_update);/*设置视图比例*/UF_MODL_create_exp_tag("1.5",&exp_tag);UF_DRAW_set_view_parm_scale(view_list[0],exp_tag);UF_free(view_list);}externvoidufusr(char*param,int*retcod,intparam_len){if(!UF_initialize()){/*对话框设置参数*/char*cp1="设置制图参数";intip2=0;charcp3[2][38]={"设置尺寸参数","设置视图比例"};intip4=2;intvalue;55
value=uc1603(cp1,ip2,cp3,ip4);switch(value){case5:/*设置尺寸参数*/set_dimension_parameters();break;case6:/*设置视图比例*/set_view_scale();break;default:uc1601("发生了错误!",0);}UF_terminate();}}2、创建和查询工程图。要求:首先创建一张图纸命名为“first_drawing”,并查询当前图纸的参数,在当前图纸参数的基础上创建第二张图纸命名为“second_drawing”,将第一张图纸更名为“my_first_drawing”,并打开第一张图纸;同时将当前部件的图纸数量输出到消息框中。源程序:#include#include#include#include#includeexternvoidufusr(char*param,int*retcode,intparam_len){if(!UF_initialize()){intnum_drawings;charmessage[MAX_LINE_SIZE+1];/*创建第一张图纸的变量定义*/tag_tfdrawing_tag=NULL_TAG;charfdrawing_name[MAX_ENTITY_NAME_SIZE]="first_drawing";55
UF_DRAW_info_tfdrawing_info;/*创建第二张图纸的变量定义*/tag_tsdrawing_tag=NULL_TAG;charsdrawing_name[MAX_ENTITY_NAME_SIZE]="second_drawing";UF_DRAW_info_tsdrawing_info;/*设置图纸的参数*/fdrawing_info.drawing_scale=1.0;fdrawing_info.projection_angle=UF_DRAW_THIRD_ANGLE_PROJECTION;fdrawing_info.size.metric_size_code=UF_DRAW_A1;fdrawing_info.size_state=UF_DRAW_METRIC_SIZE;fdrawing_info.units=UF_PART_METRIC;/*创建第一张图纸*/UF_DRAW_create_drawing(fdrawing_name,&fdrawing_info,&fdrawing_tag);/*获得第一张图纸的参数*/UF_DRAW_ask_drawing_info(fdrawing_tag,&sdrawing_info);/*在第一张图纸参数的基础上创建第二张图纸*/sdrawing_info.drawing_scale=2.0;sdrawing_info.size.metric_size_code=UF_DRAW_A3;UF_DRAW_create_drawing(sdrawing_name,&sdrawing_info,&sdrawing_tag);/*为第一张图纸更名*/UF_DRAW_rename_drawing(fdrawing_tag,"my_first_drawing");UF_DRAW_open_drawing(fdrawing_tag);/*获得当前部件文件中图纸的数量,并输出到消息框中*/UF_DRAW_ask_num_drawings(&num_drawings);UF_UI_open_listing_window();sprintf(message,"当前部件文件共有:%d张图纸。",num_drawings);UF_UI_write_listing_window(message);UF_terminate();}}3、插入视图、创建正交视图和查询视图参数。要求:首先创建并打开名为“my_drawing”的图纸,在图纸上插入前视图和轴测图,并基于前视图创建俯视图和左视图,并查询当前图纸上视图的个数,同时输出到消息框中。源程序:#include#include#include55
#include#include#include#includevoidufusr(char*param,int*retcode,intparamLen){if(!UF_initialize()){intnum_views;charmessage[MAX_LINE_SIZE+1];/*定义图纸变量*/chardrawing_name[MAX_ENTITY_NAME_SIZE]="my_drawing";UF_DRAW_info_tdrawing_info;tag_tdrawing_tag=NULL_TAG;tag_tview_tag=NULL_TAG;/*定义前视图变量*/tag_tfront_view_tag=NULL_TAG;char*front_view_name="FRONT";doublefront_reference_point[2]={210.0,400.0};/*定义轴测视图变量*/tag_ttri_view_tag=NULL_TAG;char*tri_view_name="TFR-TRI";doubletri_reference_point[2]={630.0,120.0};/*定义俯视图变量*/UF_DRAW_proj_dir_tbottom_projection_direction=UF_DRAW_project_below;doublebottom_reference_point[2]={210.0,120.0};tag_tbottom_view_tag=NULL_TAG;/*定义左视图变量*/UF_DRAW_proj_dir_tleft_projection_direction=UF_DRAW_project_left;doubleleft_reference_point[2]={630.0,400.0};tag_tleft_view_tag=NULL_TAG;/*创建并打开图纸*/drawing_info.drawing_scale=1.0;drawing_info.projection_angle=UF_DRAW_THIRD_ANGLE_PROJECTION;drawing_info.size.metric_size_code=UF_DRAW_A1;drawing_info.size_state=UF_DRAW_METRIC_SIZE;drawing_info.units=UF_PART_METRIC;UF_DRAW_create_drawing(drawing_name,&drawing_info,&drawing_tag);UF_DRAW_open_drawing(drawing_tag);/*设置视图参数*/UF_DRAW_view_info_tview_info;UF_DRAW_initialize_view_info(&view_info);view_info.view_status=UF_DRAW_ACTIVE_VIEW;55
view_info.anchor_point=NULL_TAG;view_info.view_scale=1.0;view_info.use_ref_pt=TRUE;view_info.inherit_boundary=TRUE;/*创建前视图*/UF_OBJ_cycle_by_name(front_view_name,&view_tag);if(view_tag!=NULL_TAG){UF_DRAW_import_view(drawing_tag,view_tag,front_reference_point,&view_info,&front_view_tag);UF_DRAW_define_view_auto_rect(front_view_tag);}view_tag=NULL_TAG;/*创建轴测视图*/UF_OBJ_cycle_by_name(tri_view_name,&view_tag);if(view_tag!=NULL_TAG){UF_DRAW_import_view(drawing_tag,view_tag,tri_reference_point,&view_info,&tri_view_tag);UF_DRAW_define_view_auto_rect(tri_view_tag);}/*创建俯视图*/if(front_view_tag!=NULL_TAG){UF_DRAW_add_orthographic_view(drawing_tag,front_view_tag,bottom_projection_direction,bottom_reference_point,&bottom_view_tag);UF_DRAW_define_view_auto_rect(bottom_view_tag);}/*创建左视图*/if(front_view_tag!=NULL_TAG){UF_DRAW_add_orthographic_view(drawing_tag,front_view_tag,left_projection_direction,left_reference_point,&left_view_tag);UF_DRAW_define_view_auto_rect(left_view_tag);}/*查询当前图纸的视图个数*/UF_DRAW_ask_num_views(NULL_TAG,&num_views);UF_UI_open_listing_window();sprintf(message,"当前图纸共有:%d个视图。",num_views);UF_UI_write_listing_window(message);UF_terminate();}}55
4、标注尺寸,为视图对象创建标签,在图纸上创建一个注释。要求:首先创建了一个圆柱,然后分别创建圆柱的正视图和俯视图,并在正视图和俯视图上标上圆柱的高度和直径尺寸,同时为圆柱底面创建一个标签,在图纸上方创建了一个注释。源程序:#include#include#include#include#include#include#include#include#include#include#includeexternvoidufusr(char*param,int*retcod,intparam_len){if(!UF_initialize()){/*创建圆柱*/doublecyl_origin[3]={0.0,0.0,0.0};doublecyl_direction[3]={0.0,0.0,1.0};tag_ttag_cyl;UF_MODL_create_cyl1(UF_NULLSIGN,cyl_origin,"cyl_height=6","cyl_diameter=4",cyl_direction,&tag_cyl);/*预设置工程图参数*/charradsym[7],diasym[7];intmpi[100];doublempr[70];UF_DRF_ask_preferences(mpi,mpr,radsym,diasym);mpi[3]=2;/*小数点的位数保留两位*/mpr[32]=0.5;/*设置尺寸文本的高度*/mpr[44]=0.3;/*设置附加文本的高度*/UF_DRF_set_preferences(mpi,mpr,radsym,diasym);/*创建一张图纸*/tag_tdrawing_tag;UF_DRAW_info_tdrawing_info;drawing_info.size_state=UF_DRAW_METRIC_SIZE;55
drawing_info.size.metric_size_code=UF_DRAW_A2;drawing_info.drawing_scale=1.0;drawing_info.units=UF_PART_METRIC;drawing_info.projection_angle=UF_DRAW_THIRD_ANGLE_PROJECTION;UF_DRAW_create_drawing("my_drawing",&drawing_info,&drawing_tag);UF_DRAW_open_drawing(drawing_tag);/*创建前视图*/tag_tview_tag=NULL;UF_OBJ_cycle_by_name("FRONT",&view_tag);doublereference_point[2]={80.0,200.0};UF_DRAW_view_info_tview_info;UF_DRAW_initialize_view_info(&view_info);view_info.view_status=UF_DRAW_ACTIVE_VIEW;view_info.anchor_point=NULL_TAG;view_info.view_scale=1.0;view_info.use_ref_pt=TRUE;view_info.inherit_boundary=FALSE;tag_tfront_view_tag;UF_DRAW_import_view(drawing_tag,view_tag,reference_point,&view_info,&front_view_tag);UF_DRAW_define_view_auto_rect(front_view_tag);/*创建俯视图*/tag_tbottom_view_tag;reference_point[0]=80.0;reference_point[1]=100.0;UF_DRAW_add_orthographic_view(drawing_tag,front_view_tag,UF_DRAW_project_below,reference_point,&bottom_view_tag);UF_DRAW_define_view_auto_rect(bottom_view_tag);tag_tcyl_face_tag=NULL_TAG;uf_list_p_tcyl_face_list;UF_MODL_ask_feat_faces(tag_cyl,&cyl_face_list);UF_MODL_ask_list_item(cyl_face_list,2,&cyl_face_tag);UF_MODL_delete_list(&cyl_face_list);/*在前视图上标注圆柱的高*/tag_tobject=NULL_TAG,front_objects[6];intsubtype,type,count=0;UF_VIEW_cycle_objects(front_view_tag,UF_VIEW_VISIBLE_OBJECTS,&object);while(object!=NULL_TAG){UF_OBJ_ask_type_and_subtype(object,&type,&subtype);if(type==UF_solid_type&&subtype==UF_solid_edge_subtype){front_objects[count]=object;count++;}55
UF_VIEW_cycle_objects(front_view_tag,UF_VIEW_VISIBLE_OBJECTS,&object);}UF_DRF_object_tobject1;UF_DRF_object_tobject2;UF_DRF_init_object_structure(&object1);UF_DRF_init_object_structure(&object2);object1.object_tag=front_objects[0];object1.object_assoc_type=UF_DRF_end_point;object1.object_assoc_modifier=UF_DRF_first_end_point;object1.object_view_tag=front_view_tag;object2.object_tag=front_objects[1];object2.object_assoc_type=UF_DRF_end_point;object2.object_assoc_modifier=UF_DRF_first_end_point;object2.object_view_tag=front_view_tag;UF_DRF_text_tdim_text;dim_text.lines_app_text=0;dim_text.appended_text=NULL;dim_text.user_dim_text=NULL;doubledimension_3d_origin[3]={8.0,11.0,0.0};tag_tdimension_tag=NULL_TAG;UF_DRF_create_vertical_dim(&object1,&object2,&dim_text,dimension_3d_origin,&dimension_tag);/*为圆柱底面创建标签*/chartext[1][132+1];tag_ttext_aid_tag;strcpy(text[0],"bottomfaceofcylinder");doubleorigin[3]={6.0,7.0,0.0};doublebase_pt[3]={6.0,7.0,0.0};UF_DRF_create_label(1,text,origin,UF_DRF_leader_attach_object,&object2,base_pt,&text_aid_tag);/*在俯视图上标注圆柱的直径*/UF_DRF_object_tobject3;UF_DRF_init_object_structure(&object3);UF_VIEW_cycle_objects(bottom_view_tag,UF_VIEW_VISIBLE_OBJECTS,&object);while(object!=NULL_TAG){UF_OBJ_ask_type_and_subtype(object,&type,&subtype);if(type==UF_solid_type&&subtype==UF_solid_edge_subtype){object3.object_tag=object;break;}UF_VIEW_cycle_objects(bottom_view_tag,UF_VIEW_VISIBLE_OBJECTS,&object);}object3.object_view_tag=bottom_view_tag;55
object3.object_assoc_type=UF_DRF_arc_center;dimension_3d_origin[0]=8.0;dimension_3d_origin[1]=2.0;UF_DRF_create_diameter_dim(&object3,&dim_text,dimension_3d_origin,&dimension_tag);/*在图纸上创建一个注释*/intnum_lines_text;char*text_string[2];doubleorigin_3d[3];intorientation;tag_tnote_tag=NULL;num_lines_text=2;text_string[0]="Thisisanote!";text_string[1]="markdimensionforcylinder!";origin_3d[0]=6.0;origin_3d[1]=15.0;origin_3d[2]=0.0;orientation=0;UF_DRF_create_note(num_lines_text,text_string,origin_3d,orientation,¬e_tag);/*更新图纸上所有的视图*/UF_DRAW_upd_out_of_date_views(drawing_tag);UF_terminate();}}55
第8章装配设计1、创建一个已存各部件的装配件。要求:各部件已经存在;创建一个装配部件,将各部件导入并创建部件间的配合关系。源程序:include#include#include#include#include#include#include#include#defineUF_CALL(X)(report(__FILE__,__LINE__,#X,(X)))intreport(char*file,intline,char*call,intirc);voidDoAssembly(void);intreport(char*file,intline,char*call,intirc){if(irc){charerr_msg[UF_UI_MAX_STRING_LEN+1];charmsg[133];charfail_message[133];intlen;UF_get_fail_message(irc,fail_message);sprintf(err_msg,"%s,line%d:error%d:%s",file,line,irc,fail_message);len=strlen(err_msg);len=(len<131)?len:131;strncpy(msg,err_msg,len);msg[len+1]=" 00";uc1601(err_msg,TRUE);}return(irc);55
}externDllExportvoidufusr(char*parm,int*returnCode,intrlen){if(UF_initialize())return;DoAssembly();UF_terminate();}voidDoAssembly(void){if(NULL_TAG==UF_PART_ask_display_part()){uc1601("请新建一个文件再进行本操作!",1);return;}tag_ttagInsCyl=NULL_TAG;tag_ttagInsVBlk=NULL_TAG;tag_ttagOccCyl=NULL_TAG;tag_ttagOccVBlk=NULL_TAG;UF_PART_load_status_tErrorStatus;doubledblzOrigin[3]={0,0,0};doubledblzCsysMatrix[6]={1,0,0,0,1,0};/*装入部件GB2208_80_Vblock.prt*/UF_ASSEM_add_part_to_assembly(UF_PART_ask_display_part(),"G:\NX_open\autoAssem_VBblock.prt",NULL,"VBLOCK",dblzOrigin,dblzCsysMatrix,-1,&tagInsVBlk,&ErrorStatus);/*装入部件Cylinder.prt*/dblzOrigin[1]=50;UF_ASSEM_add_part_to_assembly(UF_PART_ask_display_part(),"G:\NX_open\autoAssem_block.prt",NULL,"BLOCK",dblzOrigin,55
dblzCsysMatrix,-1,&tagInsCyl,&ErrorStatus);tagOccCyl=UF_ASSEM_ask_part_occ_of_inst(NULL_TAG,tagInsCyl);tagOccVBlk=UF_ASSEM_ask_part_occ_of_inst(NULL_TAG,tagInsVBlk);/*创建配合关系*/UF_ASSEM_mating_condition_tMcData;tag_ttagObjectFrom=NULL_TAG;tag_ttagObjectTo=NULL_TAG;tag_ttagPrototypeFrom=NULL_TAG;tag_ttagPrototypeTo=NULL_TAG;/*初始化约束*/UF_ASSEM_init_mc(&McData);/*定义约束,构造配合关系*/McData.mated_object=tagInsCyl;McData.num_constraints=3;McData.name=NULL;McData.user_name=false;//McData.override=false;McData.suppressed=false;//McData.implicit=false;tagObjectFrom=NULL_TAG;tagObjectTo=NULL_TAG;UF_OBJ_cycle_by_name("B1",&tagObjectFrom);UF_OBJ_cycle_by_name("P1",&tagObjectTo);tagPrototypeFrom=UF_ASSEM_ask_prototype_of_occ(tagObjectFrom);tagPrototypeTo=UF_ASSEM_ask_prototype_of_occ(tagObjectTo);McData.constraints[0].from=tagPrototypeFrom;McData.constraints[0].from_part_occ=tagOccCyl;McData.constraints[0].from_status=UF_ASSEM_ok;McData.constraints[0].from_type=UF_ASSEM_planar_face;McData.constraints[0].to=tagPrototypeTo;McData.constraints[0].to_part_occ=tagOccVBlk;McData.constraints[0].to_status=UF_ASSEM_ok;McData.constraints[0].to_type=UF_ASSEM_planar_face;McData.constraints[0].mate_type=UF_ASSEM_mate;McData.constraints[0].offset=NULL_TAG;McData.constraints[0].name=NULL;McData.constraints[0].user_name=false;55
McData.constraints[0].inherited=false;McData.constraints[0].suppressed=false;McData.constraints[0].has_help_point=false;UF_DISP_set_highlight(tagObjectFrom,1);UF_DISP_set_highlight(tagObjectTo,1);uc1601("这两个面进行配对操作",1);UF_DISP_set_highlight(tagObjectFrom,0);UF_DISP_set_highlight(tagObjectTo,0);tagObjectFrom=NULL_TAG;tagObjectTo=NULL_TAG;UF_OBJ_cycle_by_name("B2",&tagObjectFrom);UF_OBJ_cycle_by_name("P2",&tagObjectTo);tagPrototypeFrom=UF_ASSEM_ask_prototype_of_occ(tagObjectFrom);tagPrototypeTo=UF_ASSEM_ask_prototype_of_occ(tagObjectTo);McData.constraints[1].from=tagPrototypeFrom;McData.constraints[1].from_part_occ=tagOccCyl;McData.constraints[1].from_status=UF_ASSEM_ok;McData.constraints[1].from_type=UF_ASSEM_planar_face;McData.constraints[1].to=tagPrototypeTo;McData.constraints[1].to_part_occ=tagOccVBlk;McData.constraints[1].to_status=UF_ASSEM_ok;McData.constraints[1].to_type=UF_ASSEM_planar_face;McData.constraints[1].mate_type=UF_ASSEM_mate;McData.constraints[1].offset=NULL_TAG;McData.constraints[1].name=NULL;McData.constraints[1].user_name=false;McData.constraints[1].inherited=false;McData.constraints[1].suppressed=false;McData.constraints[1].has_help_point=false;UF_DISP_set_highlight(tagObjectFrom,1);UF_DISP_set_highlight(tagObjectTo,1);uc1601("这两个面进行配对操作",1);UF_DISP_set_highlight(tagObjectFrom,0);UF_DISP_set_highlight(tagObjectTo,0);tagObjectFrom=NULL_TAG;tagObjectTo=NULL_TAG;UF_OBJ_cycle_by_name("B3",&tagObjectFrom);UF_OBJ_cycle_by_name("P3",&tagObjectTo);tagPrototypeFrom=UF_ASSEM_ask_prototype_of_occ(tagObjectFrom);tagPrototypeTo=UF_ASSEM_ask_prototype_of_occ(tagObjectTo);McData.constraints[2].from=tagPrototypeFrom;McData.constraints[2].from_part_occ=tagOccCyl;McData.constraints[2].from_status=UF_ASSEM_ok;55
McData.constraints[2].from_type=UF_ASSEM_planar_face;McData.constraints[2].to=tagPrototypeTo;McData.constraints[2].to_part_occ=tagOccVBlk;McData.constraints[2].to_status=UF_ASSEM_ok;McData.constraints[2].to_type=UF_ASSEM_planar_face;McData.constraints[2].mate_type=UF_ASSEM_align;McData.constraints[2].offset=NULL_TAG;McData.constraints[2].name=NULL;McData.constraints[2].user_name=false;McData.constraints[2].inherited=false;McData.constraints[2].suppressed=false;McData.constraints[2].has_help_point=false;UF_DISP_set_highlight(tagObjectFrom,1);UF_DISP_set_highlight(tagObjectTo,1);uc1601("这两个面进行对齐操作",1);UF_DISP_set_highlight(tagObjectFrom,0);UF_DISP_set_highlight(tagObjectTo,0);doubledblzTransform[4][4];UF_ASSEM_dof_tDof;UF_ASSEM_mc_status_tStatus;/*求解约束*/UF_CALL(UF_ASSEM_solve_mc(&McData,&Status,&Dof,dblzTransform));if(UF_ASSEM_mc_solved==Status){uc1601("求解约束成功!",1);UF_ASSEM_mc_structure_state_tStructStatus;/*将约束应用到装配体上*/UF_CALL(UF_ASSEM_apply_mc_data(&McData,&StructStatus,&Status));if(UF_ASSEM_structure_ok==StructStatus){uc1601("应用装配成功!",1);/*更新模型*/UF_MODL_update();UF_DISP_refresh();}elseuc1601("应用装配失败!",1);}elseuc1601("求解约束失败!",1);}55
externintufusr_ask_unload(void){/*unloadimmediatelyafterapplicationexits*/return(UF_UNLOAD_IMMEDIATELY);}55'
您可能关注的文档
- 《土地管理学》复习思考题解答(定).doc
- 《土木工程施工》试题库及参考答案.doc
- 《土木工程材料》习题与解答新指导书通用.doc
- 《土木工程概论B》复习题及参考答案.doc
- 《土木测量工程》习题答案.doc
- 《土质学与土力学》习题库及答案(1).doc
- 《土质学与土力学》考试习题库及答案.doc
- 《地图学》试题集-附答案.doc
- 《地质学基础》复习(含习题及答案).pdf
- 《基础会计》(化工版)各章练习题参考答案.pdf
- 《基础会计》(第三版)教材习题答案.doc
- 《基础会计》(第三版)教材习题答案全.doc
- 《基础会计》练习题参考答案:.doc
- 《基础会计》题库及答案.doc
- 《基础会计》题目及答案大汇总.docx
- 《基础会计习题与案例》答案 陈文铭 第二版东北财经大学出版社.doc
- 《基础会计习题与案例》答案_东北财经大学出版社.doc
- 《基础会计习题与案例》答案_东北财经大学出版社第二版.doc
相关文档
- 施工规范CECS140-2002给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程
- 施工规范CECS141-2002给水排水工程埋地钢管管道结构设计规程
- 施工规范CECS142-2002给水排水工程埋地铸铁管管道结构设计规程
- 施工规范CECS143-2002给水排水工程埋地预制混凝土圆形管管道结构设计规程
- 施工规范CECS145-2002给水排水工程埋地矩形管管道结构设计规程
- 施工规范CECS190-2005给水排水工程埋地玻璃纤维增强塑料夹砂管管道结构设计规程
- cecs 140:2002 给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程(含条文说明)
- cecs 141:2002 给水排水工程埋地钢管管道结构设计规程 条文说明
- cecs 140:2002 给水排水工程埋地管芯缠丝预应力混凝土管和预应力钢筒混凝土管管道结构设计规程 条文说明
- cecs 142:2002 给水排水工程埋地铸铁管管道结构设计规程 条文说明