思路:
1.添加操作,也就是平面铣,轮廓铣,多轴铣…成为主类型,由UF_CAM_opt_ask_types得到;
每个下面有许多子类型,由UF_CAM_opt_ask_subtypes得到,改变第二个参数可以改变得到的四个视图是哪个视图。然后想要那个子类型就添加就好了
程序里有打印子类型的方法,可以试一下看看有哪些子类型和主类型
2.添加程序组
3.将操作加入到程序组里面
代码如下
int type_count = 0;
int subtype_count = 0;
int error_code = 0;
int ii = 0, jj = 0, kk = 0;
int ll = 1;
int uchoice = 0;
int prog_sub_cnt = 0;
int mthd_sub_cnt = 0;
int geom_sub_cnt = 0;
int tool_sub_cnt = 0;
int knt = 0;
int choice = 0;
int numop = 0;
int obj_count = 1;
int istr;
char const **type_names, **subtype_names = 0;
char const **prog_sub_names, **mthd_sub_names, **geom_sub_names, **tool_sub_names;
char reason[UF_NCGROUP_MAX_REASON_BUFSIZE];
char errorstrg[133];
char *uTool[3] = {"Tool_1","Tool_2","Tool_3"};
char *uMethod[3] = {"Roughing","Semi-Finish","Flowcut"};
char uOper[] [38] = {"CAVITY_MILL","CONTOUR_AREA","FLOWCUT_SINGLE"};
char *uPrognam = {"UserGroup"};
tag_t *operTag = 0;
tag_t setupTag;
tag_t partTag, progTag = NULL_TAG, mthdTag, geomTag = NULL_TAG, toolTag;
tag_t progRootTag, mthdRootTag, geomRootTag, toolRootTag;
tag_t prog_null;
tag_t geom_null;
tag_t mthd_null;
tag_t tool_null;
tag_t wrkp_tag;
logical answer;
logical generate;
char buffer[256];//以上参数直接从ug自带实例复制过来的,有的没用到
// TODO: add your code here
UF_initialize();
UF_CAM_opt_ask_types( &type_count, &type_names );//得到主类型
UF_UI_open_listing_window();
if(type_count > 0)//此循环将主类型打印出来
{
sprintf(buffer, "type count = %d\n", type_count );
UF_UI_write_listing_window(buffer);
for ( knt = 0; knt < type_count; knt++ )
{
sprintf(buffer,"TypeName(%d) is %s\n", knt, type_names[knt]);
UF_UI_write_listing_window(buffer);
}
}
UF_SETUP_ask_setup( &setupTag );
if(type_count > 0)//次循环打印多轴铣的操作子类型
{
UF_CAM_opt_ask_subtypes( type_names[2], UF_CAM_OPT_STYPE_CLS_OPER, &subtype_count, &subtype_names );
sprintf(buffer, "subtype count = %d\n", subtype_count );
UF_UI_write_listing_window(buffer);
for ( knt = 0; knt < subtype_count; knt++ )
{
sprintf(buffer,"SubTypeName(%d) is %s\n", knt, subtype_names[knt]);
UF_UI_write_listing_window(buffer);
}
}
UF_CAM_opt_ask_subtypes( type_names[2], UF_CAM_OPT_STYPE_CLS_PROG, &prog_sub_cnt,&prog_sub_names );//此处得到程序视图的所有文件
sprintf(buffer, "prog_subtype count = %d\n", prog_sub_cnt );
UF_UI_write_listing_window(buffer);
for ( knt = 0; knt < prog_sub_cnt; knt++ )
{
sprintf(buffer,"prog_SubTypeName(%d) is %s\n", knt, prog_sub_names[knt]);
UF_UI_write_listing_window(buffer);
}
//创建操作(我用的是多轴铣,所以直接就选择了type_names[2])
operTag = (tag_t *)UF_allocate_memory( sizeof( operTag ) * subtype_count, &error_code );
UF_OPER_create( (char *) type_names[2], (char *)subtype_names[0], &operTag[0]);
//创建程序组
UF_NCPROG_create( (char *)type_names[2], (char *)prog_sub_names[0], &progTag );
UF_OBJ_set_name( progTag, uPrognam );
UF_SETUP_ask_program_root( setupTag, &progRootTag );
UF_NCGROUP_accept_member( progRootTag, progTag );
//在程序组中加入操作
UF_NCGROUP_accept_member( progTag, operTag[0] );
UF_DISP_refresh ();
UF_terminate();
注意: