天天看點

NX二次開發-UFUN根據矩陣移動或複制對象uf5947

#include <uf.h>
#include <uf_ui.h>
#include <uf_trns.h>


//設定class_dialog選擇過濾
static int init_proc(UF_UI_selection_p_t select,void* user_data)
{
    int num_triples = 1;
    //實體 片體
    UF_UI_mask_t mask_triples[] = {UF_solid_type,0,0};
    /* enable only lines and edges */
    if((UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num_triples, mask_triples)) == 0)
    {
        return (UF_UI_SEL_SUCCESS);
    }
    else
    {
        return (UF_UI_SEL_FAILURE);
    }
}

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 */
    UF_initialize();

    //select_with_class_dialog
    char message[]="類選擇對話框";
    char title[]="按類選擇:";
    int scope=UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
    int response=0;
    int count=0;
    tag_t* objects=NULL;
    //5943
    double translation[3]={0.0,500.0,500.0};
    double matrix_value[16]={0.0};
    /*
        絕對坐标系 的平移距離
        translation[0] x向的距離
        translation[1] y向的距離
        translation[2] z向的距離
    */
    //5947
    tag_t *objects_array=NULL;
    int move_or_copy=2;//1 - Move  2 - copy
    int dest_layer=0;//0 - the original layer,  -1 - the work layer,  1 - 256 - the specified layer
    int trace_curves=2;//軌迹曲線狀态1 means on, 2 means off.
    tag_t *copies=NULL;//這是當move_or_copy等于1(移動)時不使用。當move_or_copy為2(副本)時,應設定一個為空tag_t
    tag_t trace_curve_group=NULL;//當trace_curves=2時,此處設定為null
    int status_value=0;
    //多選對話框
    UF_UI_select_with_class_dialog (message,title,scope,init_proc,NULL,&response,&count,&objects);
    //配置設定記憶體
    objects_array=(tag_t*)malloc(sizeof(tag_t)*count);
    if (response == UF_UI_OK && count > 0)
    {
        for (int i=0; i<count; i++)
        {
            objects_array[i]=objects[i];
            UF_DISP_set_highlight(objects[i], 0);
        }

    }
    //傳回矩陣以執行線性變換,沿着  絕對坐标系  的X軸,Y軸和Z軸。
    uf5943(translation,matrix_value);
    //配置設定記憶體
    copies=(tag_t*)malloc(sizeof(tag_t)*count);
    //平移
    uf5947(matrix_value,objects_array,&count,&move_or_copy,&dest_layer,&trace_curves,copies,&trace_curve_group,&status_value);
    //釋放記憶體
    free(copies);
    free(objects_array);
    /*
    注意:
    1.坐标系問題
        注意平移變換 這個玩意是按  絕對坐标系 方向來的(坐标系不統一時先把坐标系統一)
    2.注意記憶體的配置設定。
    3.如果是有參數的體 經過 uf5947 平移變換後變成 去參後的體。

    4.trace_curves 軌迹曲線狀态 ps:我也不明白是什麼意思,求大神什麼解釋
    */

    UF_terminate();

    /* Terminate the API environment */
    UF_CALL(UF_terminate());
}

Caesar盧尚宇
2020年5月21日      
NX二次開發-UFUN根據矩陣移動或複制對象uf5947