exturded下冲头拉伸得到的是 uf_list_t ,后续操作上没有tag_t来的方便,
UF_MODL_create_extruded( objects, taper_angle, limit1,point, direction, sign_ex, &features );
改用UF_MODL_create_extrusion(generators,face_num,trim_data,tape_angle,limit1,offsets,region_point,false,true,dir,sign,&objects_e,&obj_cnt);
获得的objects_e,为tag_t
后面打孔采用三步走策略
UF_MODL_ask_feat_faces(*objects_e,&objects);
UF_MODL_ask_list_item(objects,2,&face_d2);
UF_MODL_create_simple_hole(origin2,direction1,&d2,"70","120",face_d2,face_t1,&hole_2);
UF_MODL_delete_list( &objects );
UF_free(objects_e);
下面是源代码:
/*****************************************************************************
**
** NX8_Open1_EJ.cpp
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
include
include
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
else
include
include
endif
include
include
include
include
include
include
include
include
include
include
include
include< uf_facet.h>
include //test
include //test
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);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Unigraphics Startup
** This entry point activates the application at Unigraphics startup */
extern DllExport void ufsta( char *param, int returnCode, int rlen )
{
/ Initialize the API environment /
if( UF_CALL(UF_initialize()) )
{
/ Failed to initialize */
return;
}
/* TODO: Add your application code here */
//交互数据声明
double k=1.20,g=0.01,ic=12.7,s=4.76,r1=1.191,r2=r1,d=5.156,r=0,d_in=0,ang=80,ang_hole=0;
//double pi=3.1415926;
//外部特征声明
UF_FEATURE_SIGN sign=UF_NULLSIGN;//UF_NEGATIVE;
double origin[3]={0,0,0};
double dir [ 3 ] ={0,0,1};
tag_t cyl_obj_id;
double location[3]={0,0,9};
tag_t face;
tag_t boss_obj_id;
uf_list_p_t boss_list;
//Chamfer声明
uf_list_p_t blend_edge_list = NULL;
//extrude 声明
UF_CURVE_line_t sline1, sline2, sline3, sline4;
tag_t line1, line2, line3, line4;
int i;
double j=0.3;
uf_list_p_t objects;
tag_t generators[4];
char *taper_angle = "0.0";
char *limit[ 2 ] = { "75", "90" };
char *limit1[ 2 ] = { "34", "75" };
double point[ 3 ] = { 0.0, 0.0, 0.0 };
double direction[ 3 ] = { 0.0, 0.0, 1.0 };
uf_list_p_t features,features1;
UF_FEATURE_SIGN sign_ex=UF_POSITIVE;//UF_POSITIVE,,UF_NULLSIGN
//temporary
char text[132];
tag_t view_tag = NULL_TAG;
UF_VIEW_visualization_t view_data;
double view_rotate_axis[3] = { 0.0, 0.0, 1.0 };
double view_rotate_delta_angle = 1;
int view_rotate_time = 45;
//Hole声明
tag_t hole_bot_id,hole_2;
tag_t face_li,face_d2;
tag_t face_t1=null_tag;
tag_t face_t2;
double origin2[3]={0,0,75};
double direction1[ 3 ] = { 0.0, 0.0, -1 };
double d2_1=ceil((d*k+1.25)*2)/2;
char d2;
//Extrude声明
//int face_num=1;
//Boolean声明
int num_result=0;
tag_t *resulting_bodies=NULL;
//主体框架
UF_MODL_create_cyl1(sign, origin,"9","45",dir, &cyl_obj_id );
UF_MODL_ask_feat_faces(cyl_obj_id,&boss_list);
UF_MODL_ask_list_item(boss_list,1,&face);
UF_MODL_create_boss(location,dir,"32","25","0",face,&boss_obj_id);
//Boolen
//UF_MODL_subtract_bodies(cyl_obj_id,boss_obj_id,&num_result,&resulting_bodies );
//创建沉头孔
UF_MODL_ask_list_item(boss_list,0,&face_li);
UF_MODL_delete_list( &boss_list );
UF_MODL_create_c_bore_hole(origin,dir,"12","24","20","1","90",face_li,face_t1,&hole_bot_id);
//Chamfer
//Line&&Extrude0
//L1
sline1.start_point[0] =ceil(ic*k/2*1000)/1000-j;
sline1.start_point[1] =-ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000+j;
sline1.start_point[2] = 0.0;
sline1.end_point[0] =-ceil(ic*k/2*1000)/1000+j;
sline1.end_point[1] = -ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000+j;
sline1.end_point[2] = 0.0;
UF_CURVE_create_line(&sline1,&line1);
//L2
sline2.start_point[0] =-ceil(ic*k/2*1000)/1000+j;
sline2.start_point[1] =-ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000+j;
sline2.start_point[2] = 0.0;
sline2.end_point[0] =-ceil(ic*k/2*1000)/1000+j;
sline2.end_point[1] =ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000-j;
sline2.end_point[2] = 0.0;
UF_CURVE_create_line(&sline2,&line2);
//L3
sline3.start_point[0] =-ceil(ic*k/2*1000)/1000+j;
sline3.start_point[1] =ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000-j;
sline3.start_point[2] = 0.0;
sline3.end_point[0] =ceil(ic*k/2*1000)/1000-j;
sline3.end_point[1] =ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000-j;
sline3.end_point[2] = 0.0;
UF_CURVE_create_line(&sline3,&line3);
//L4
sline4.start_point[0] =ceil(ic*k/2*1000)/1000-j;
sline4.start_point[1] =ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000-j;
sline4.start_point[2] = 0.0;
sline4.end_point[0] =ceil(ic*k/2*1000)/1000-j;
sline4.end_point[1] =-ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000+j;
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;
/* 把四根线的tag放入数组 */
generators[0] = line1;
generators[1] = line2;
generators[2] = line3;
generators[3] = line4;
/* 创建一个链表,以存放扫描的截面线串 */
UF_MODL_create_list( &objects );
for ( i = 0; i < 4; i++ )
{
UF_MODL_put_list_item( objects, generators[ i ] );
}
//Extrude0
UF_MODL_SWEEP_TRIM_object_p_t trim_data=NULL;
tag_t *objects_e;
char *tape_angle="0";
char *offsets[2] = {"0.0", "0.0"};
double region_point[ 3 ]={0,0,0};
int obj_cnt,face_num=4;
UF_MODL_create_extrusion(generators,face_num,trim_data,tape_angle,limit1,offsets,region_point,false,true,
dir,sign,&objects_e,&obj_cnt);
UF_free(objects_e);
//UF_MODL_create_extruded( objects, taper_angle, limit1,point, direction, sign_ex, &features );
//UF_MODL_delete_list( &objects );
//hole3
//声明
UF_UI_selection_p_t select_=NULL;
tag_p_t * objs=NULL ;
int * count=0;
//UF_MODL_ask_feat_faces(features,&boss_list);
//UF_MODL_create_list(&features);
//UF_FACET_ask_face_id_of_solid_face(features[0], );
UF_UI_ask_sel_object_list(select_,count,objs);//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~☆
UF_free(objs);
///*
UF_MODL_ask_list_item(features,0,&face_d2);
UF_MODL_ask_list_item(features,1,&face_t2);
UF_MODL_delete_list( &features );
gcvt(d2_1,3,&d2);
UF_MODL_create_simple_hole(origin2,direction1,"d2","70","120",face_d2,face_t2,&hole_2);
//*/
//Extrude1
//L1
sline1.start_point[0] =ceil(ic*k/2*1000)/1000;
sline1.start_point[1] =-ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000;
sline1.start_point[2] = 0.0;
sline1.end_point[0] =-ceil(ic*k/2*1000)/1000;
sline1.end_point[1] = -ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000;
sline1.end_point[2] = 0.0;
UF_CURVE_create_line(&sline1,&line1);
//L2
sline2.start_point[0] =-ceil(ic*k/2*1000)/1000;
sline2.start_point[1] =-ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000;
sline2.start_point[2] = 0.0;
sline2.end_point[0] =-ceil(ic*k/2*1000)/1000;
sline2.end_point[1] =ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000;
sline2.end_point[2] = 0.0;
UF_CURVE_create_line(&sline2,&line2);
//L3
sline3.start_point[0] =-ceil(ic*k/2*1000)/1000;
sline3.start_point[1] =ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000;
sline3.start_point[2] = 0.0;
sline3.end_point[0] =ceil(ic*k/2*1000)/1000;
sline3.end_point[1] =ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000;
sline3.end_point[2] = 0.0;
UF_CURVE_create_line(&sline3,&line3);
//L4
sline4.start_point[0] =ceil(ic*k/2*1000)/1000;
sline4.start_point[1] =ceil(ic*k/2/tan(ang*PI/180/2)*1000)/1000;
sline4.start_point[2] = 0.0;
sline4.end_point[0] =ceil(ic*k/2*1000)/1000;
sline4.end_point[1] =-ceil(ic*k/2*tan(ang*PI/180/2)*1000)/1000;
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;
/* 把四根线的tag放入数组 */
generators[0] = line1;
generators[1] = line2;
generators[2] = line3;
generators[3] = line4;
/* 创建一个链表,以存放扫描的截面线串 */
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_ex, &features1 );
UF_MODL_delete_list( &objects );
/*test_temporary
UF_UI_open_listing_window();
sprintf(text,"%f",tan(ang*PI/180/2));
UF_UI_write_listing_window(text);*/
//Hole
/* 设置视图 */
UF_VIEW_ask_work_view( &view_tag );
UF_VIEW_ask_visualization( view_tag, &view_data );
UF_VIEW_fit_view( view_tag, 0.3 );
view_data.display_mode = UF_VIEW_FULLY_SHADED;
UF_VIEW_set_visualization( view_tag, &view_data );
UF_VIEW_rotate_view( view_tag, view_rotate_axis,
view_rotate_delta_angle, view_rotate_time );
view_rotate_axis[0] = -1.0;
view_rotate_axis[2] = 0.0;
UF_VIEW_rotate_view( view_tag, view_rotate_axis,
view_rotate_delta_angle, view_rotate_time );
UF_VIEW_fit_view( view_tag, 0.7 );
UF_LAYER_set_all_but_work( UF_LAYER_INACTIVE_LAYER );
/* 保存部件文件 */
UF_PART_save( );
UF_terminate();
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
extern int ufusr_ask_unload (void)
{
/* 设置UF程序运行以后立刻从内存中卸除,即当重新修改、编译成新的DLL文件时,UG无须关闭重启动,就可调用此新的*.DLL文件 */
return (UF_UNLOAD_IMMEDIATELY);
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". /
/extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_UG_TERMINATE );
}
*/