ug API 二次开发实例程序(含最终模型图)

  • 时间:
  • 浏览:8
  • 来源:跟我学网络

一、最终模型图 二、C++程序 /******************************************************************** ********* ** ** example732.cpp ** ** Description: ** Main file for the application. ** ********************************************************************* ********/ /* Include files */ #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun ) # include <strstream> # include <iostream> using std::ostrstream; using std::endl; using std::ends; using std::cerr; #else # include <strstream.h> # include <iostream.h> #endif #include"stdafx.h" #include <uf.h> #include<stdlib.h> #include<uf_part.h> #include<uf_modl.h> #include<uf_view.h> #include<uf_layer.h> #include<uf_obj.h> #include<uf_view_ugopenint.h> #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))) static int report_error( char *file, int line, char *call, int irc) { if (irc) { char err[133], msg[133]; sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ", irc, line, file); UF_get_fail_message(irc, err); UF_print_syslog(msg, FALSE); UF_print_syslog(err, FALSE); UF_print_syslog("\n", FALSE); UF_print_syslog(call, FALSE); UF_print_syslog(";\n", FALSE); } return(irc); } /* Main routine */ extern void main( char argc, char *argv[] ) { /* Initialize the API environment */ if( UF_CALL(UF_initialize()) ) { /* Failed to initialize */ return; } /* TODO: Add your application code here */ tag_t view_tag=NULL_TAG; /*创建 part 文件*/ char * part_name="f:\\UG_TEST\\example732"; int units=1; tag_t part_tag; UF_CALL(UF_PART_new(part_name,units,&part_tag)); /*创建圆柱的变量声明区*/ double cyl_origin[3]={0.0,0.0,0.0}; char * cyl_height="20.0"; char * cyl_diam="10.0"; double cyl_direction[3]={0.0,0.0,1.0}; tag_t cyl_obj_id; uf_list_p_t face_list; /*创建相对基准平面的变量声明区*/ int num_refs=1; tag_t object_tags[3]; tag_t object_tags1[3]; int point_select[3]={0,1,0}; int which_plane=1; char*offset_string="5.0"; int num_dplanes; tag_t dplane_tag[2]; tag_t dplane_tag1[2]; int layer_fea_nu; tag_t * layer_fea_id; /*创建孔特征的变量声明区*/ double location[3]={5.0,0.0,10.0}; double direction[3]={-1.0,0.0,0.0}; char* diame="5.0"; char* depth="20.0"; char* angle="0.0"; tag_t face_li; tag_t face_tl; tag_t hole_obj_id; /*创建圆柱体*/ UF_CALL(UF_MODL_create_cyl1(UF_NULLSIGN,cyl_origin,cyl_height,cyl_diam,cy l_direction,&cyl_obj_id)); /*获取圆柱体所有的面,存入链表*/ UF_CALL(UF_MODL_ask_feat_faces(cyl_obj_id,&face_list)); UF_CALL(UF_MODL_ask_list_item(face_list,2,&object_tags[0])); UF_CALL(UF_MODL_delete_list(&face_list)); /*创建基准平面*/ UF_CALL(UF_MODL_create_relative_dplane(num_refs,object_tags,point_select, which_plane,NULL,NULL,"0.0",&num_dplanes,dplane_tag)); object_tags1[0]=dplane_tag[0]; UF_CALL(UF_MODL_ask_feat_object(dplane_tag[0],&layer_fea_nu,&layer_fea_i d)); UF_CALL(UF_OBJ_set_blank_status(layer_fea_id[0],UF_OBJ_BLANKED)); UF_free(layer_fea_id); UF_CALL(UF_MODL_create_relative_dplane(1,object_tags1,point_select,which_ plane,NULL,NULL,offset_string,&num_dplanes,dplane_tag1)); face_li=dplane_tag1[0]; face_tl=object_tags[0]; UF_CALL(UF_MODL_create_simple_hole(location,direction,diame,depth,angle,fa ce_li,face_tl,&hole_obj_id)); /*UF_CALL(UF_VIEW_ask_work_view(&view_tag)); UF_VIEW_fit_view(view_tag,0.7);*/ /* Terminate the API environment */ UF_CALL(UF_PART_save()); UF_CALL(UF_terminate()); } /******************************************************************** ********* ** Utilities ********************************************************************* ********/