lugan2
Mechanical
- Apr 10, 2013
- 42
Hi all
I want to subtract a object(maybe a hole) from another object using UF_MODL_subtract_bodies. However, when I save the result part, the program fails and the gdb gives segmental fault. The code is list in below. It seems that the program fails when the subtracted part is inside of the other part. If the 'hole' is on the edge or only intersect with the other block, the result is ok. Is it because I was using wrong command to save the result parts? I tried both 'UF_PART_save( )' and 'UF_PART_save_all', they have the same result.
Anyone know why, please? Thanks!
int main()
{
UF_initialize();
tag_t part;
int english_units = 2;
char *part_name = "arm";
UF_PART_new(part_name, english_units, &part);
{
/* varibles for block*/
double blk_corner[ 3 ] = { 0.0, 0.0, 0.0 };
char *blk_edge_len[ 3 ] = { "20.0", "20.0", "20.0" };
tag_t blk_obj_id;
tag_t blk_body_id;
/* varibles for cylinder */
double cyl_origin[ 3 ] = { 5.0, 5.0, 0.0 };
char *cyl_height = "20.0";
char *cyl_diam = "10.0";//this will fail if diameter is less then 10, which means, if the cylinder is inside of the block
double cyl_direction[ 3 ] = { 0.0, 0.0, 1.0 };
tag_t cyl_obj_id;
tag_t cyl_body_id;
int num_result = 0;
tag_t *resulting_bodies = NULL;
/* create a block */
UF_MODL_create_block1( UF_NULLSIGN, blk_corner, blk_edge_len, &blk_obj_id );
UF_MODL_ask_feat_body( blk_obj_id, &blk_body_id );
/* creat a cylinder */
UF_MODL_create_cyl1( UF_NULLSIGN, cyl_origin, cyl_height, cyl_diam, cyl_direction, &cyl_obj_id );
UF_MODL_ask_feat_body( cyl_obj_id, &cyl_body_id );
/* doing boolen operation */
UF_MODL_subtract_bodies( blk_body_id, cyl_body_id, &num_result, &resulting_bodies );
if ( num_result > 0 )
{
UF_free( resulting_bodies );
resulting_bodies = NULL;
}
/* save the part */
UF_PART_save( );
/*
int count;
tag_t * part_list;
int * error_list ;
UF_PART_save_all (&count, &part_list,&error_list );
*/
}
UF_terminate();
}
I want to subtract a object(maybe a hole) from another object using UF_MODL_subtract_bodies. However, when I save the result part, the program fails and the gdb gives segmental fault. The code is list in below. It seems that the program fails when the subtracted part is inside of the other part. If the 'hole' is on the edge or only intersect with the other block, the result is ok. Is it because I was using wrong command to save the result parts? I tried both 'UF_PART_save( )' and 'UF_PART_save_all', they have the same result.
Anyone know why, please? Thanks!
Code:
{
UF_initialize();
tag_t part;
int english_units = 2;
char *part_name = "arm";
UF_PART_new(part_name, english_units, &part);
{
/* varibles for block*/
double blk_corner[ 3 ] = { 0.0, 0.0, 0.0 };
char *blk_edge_len[ 3 ] = { "20.0", "20.0", "20.0" };
tag_t blk_obj_id;
tag_t blk_body_id;
/* varibles for cylinder */
double cyl_origin[ 3 ] = { 5.0, 5.0, 0.0 };
char *cyl_height = "20.0";
char *cyl_diam = "10.0";//this will fail if diameter is less then 10, which means, if the cylinder is inside of the block
double cyl_direction[ 3 ] = { 0.0, 0.0, 1.0 };
tag_t cyl_obj_id;
tag_t cyl_body_id;
int num_result = 0;
tag_t *resulting_bodies = NULL;
/* create a block */
UF_MODL_create_block1( UF_NULLSIGN, blk_corner, blk_edge_len, &blk_obj_id );
UF_MODL_ask_feat_body( blk_obj_id, &blk_body_id );
/* creat a cylinder */
UF_MODL_create_cyl1( UF_NULLSIGN, cyl_origin, cyl_height, cyl_diam, cyl_direction, &cyl_obj_id );
UF_MODL_ask_feat_body( cyl_obj_id, &cyl_body_id );
/* doing boolen operation */
UF_MODL_subtract_bodies( blk_body_id, cyl_body_id, &num_result, &resulting_bodies );
if ( num_result > 0 )
{
UF_free( resulting_bodies );
resulting_bodies = NULL;
}
/* save the part */
UF_PART_save( );
/*
int count;
tag_t * part_list;
int * error_list ;
UF_PART_save_all (&count, &part_list,&error_list );
*/
}
UF_terminate();
}