NX/UG二次开发—CAM—设置程序修剪边界Boundary

最近做了一个设置CAM程序边界的小工具,分享一下经验(官方的代码在文章末尾处),以下均以修剪边界曲线为例。

NX/UG二次开发—CAM—设置程序修剪边界Boundary_第1张图片

NX/UG二次开发—CAM—设置程序修剪边界Boundary_第2张图片

以下为官方提供的源码:

/***************************** Include Files **********************************/
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


#define     MAX_BND      20

/*******************************************************************/
static UF_CAMBND_boundary_data_p_t create_and_init_bnd_data
(
    UF_CAM_boundary_type_t   type,
    int                      plane_type,
    double                   *origin,
    double                   *matrix,
    UF_CAM_material_side_t   material_side,
    int                      ignore_holes,
    int                      ignore_islands,
    int                      ignore_chamfers,
    UF_CAMBND_app_data_p_t   app_data
);
static UF_CAMBND_app_data_p_t create_and_init_bnd_app_data(void);
static int init_proc1(UF_UI_selection_p_t select, void *user_data);
static int init_proc2(UF_UI_selection_p_t select, void *user_data);

/*******************************************************************/
static void do_cambnd_api(void)
{
    UF_CAMBND_boundary_data_p_t  bnd_data, bnd_data_list[MAX_BND];
    UF_CAMBND_app_data_p_t       app_data_list[MAX_BND]; 
    tag_t                        part_tag, *objects, entity_list[MAX_BND];
    int                          i, j, object_count, part_count, part_item_count;
    int                          type, subtype;
    UF_CAMBND_boundary_t         *part_bnd_list;
    UF_CAMBND_item_t             *part_item_list;

    /* Get the displayed part. */
    part_tag = UF_PART_ask_display_part( );
    
    if( part_tag != null_tag )
    {
        /* Get the highlighted/selected objects from Navigation Tool. */
        UF_UI_ONT_ask_selected_nodes( &object_count, &objects ); 

        if (object_count > 0)
        {
            tag_t     eid, view;
            double    cursor[3], origin[3], matrix[9];
            int       entity_count, response;

            char      cue_face[]   = "Select faces";
            char      cue_edge[]   = "Select edges";
            char      title[]      = "Boundary Selection";

            entity_count = 0;

            /* Allow the user to select faces. */
            while (TRUE)
            {
                UF_UI_select_with_single_dialog(cue_face, title,
                                                UF_UI_SEL_SCOPE_NO_CHANGE, init_proc1, NULL,
                                                &response, &eid, cursor, &view);

                if (response == UF_UI_OBJECT_SELECTED)
                {                    
                    entity_list[entity_count] = eid;

                    /* Allocate the memory for the boundary data of an item without app data.  */
                    bnd_data_list[entity_count] = create_and_init_bnd_data(UF_CAM_boundary_type_closed,
                                                                           1, origin, matrix, 
                                                                           UF_CAM_material_side_out_right,
                                                                           0, 0, 0, NULL);

                    entity_count++;
                }
                else if (response == UF_UI_OK || response == UF_UI_CANCEL || 
                         response == UF_UI_BACK)
                {
                    /* Geometry selection is finished. */
                    break;
                }
            }

            /* Append the face boundaries. */
            if (entity_count > 0)
            {
                for(i=0; i 0)
            {
                bnd_data = create_and_init_bnd_data(UF_CAM_boundary_type_open,
                                                    1, origin, matrix, 
                                                    UF_CAM_material_side_out_right,
                                                    0, 0, 0, NULL);
                for(i=0; iboundary_type = type;
    bnd_data->plane_type = plane_type ;
    for (i=0; i<3; i++)
        bnd_data->origin[i] = origin[i] ;
    for (i=0; i<9; i++)
        bnd_data->matrix[i] = matrix[i] ;
    bnd_data->material_side = material_side;
    bnd_data->ignore_holes = ignore_holes ;
    bnd_data->ignore_islands = ignore_islands ; 
    bnd_data->ignore_chamfers = ignore_chamfers ;    
    bnd_data->app_data = app_data;

    return(bnd_data);
}

static UF_CAMBND_app_data_p_t create_and_init_bnd_app_data(void)
{
    UF_CAMBND_app_data_p_t  app_data; 
    int                     err_code;

    app_data = (UF_CAMBND_app_data_p_t) UF_allocate_memory(
                                          sizeof(UF_CAMBND_app_data_t), &err_code);

    if (err_code)
return(NULL);

    /* Set flags. */
    app_data->has_stock = 1;
    app_data->has_tolerances = 0 ;
    app_data->has_feedrate = 0 ;
    app_data->has_blank_distance = 0;
    app_data->has_tool_position = 0;
    
    /* Set values. */
    app_data->stock = 0.1 ;
    app_data->tolerances[0] = 0.1 ;
    app_data->tolerances[1] = 0.1 ;
    app_data->feedrate_unit = UF_CAM_feedrate_unit_per_minute ;
    app_data->feedrate_value = 0.1 ;
    app_data->blank_distance = 0.0 ;
    app_data->tool_position = UF_CAM_tool_position_tanto;

    return(app_data);
}

/*ARGSUSED*/
void ufusr(char *param, int *retcode, int param_len)
{
    UF_initialize();

    do_cambnd_api();

    UF_terminate();
}

int ufusr_ask_unload(void)
{
 return (UF_UNLOAD_IMMEDIATELY);
}

 

你可能感兴趣的:(CAM)