1. 程式人生 > >NX二次開發-Block UI各種控制元件的獲取(持續補充)

NX二次開發-Block UI各種控制元件的獲取(持續補充)

用Block UI作NX二次開發的時候,不需要在使用UFUN函式的時候加UF_initialize();和UF_terminate();。 可以直接加在CPP裡這個位置:

extern "C" DllExport void  ufusr(char *param, int *retcod, int param_len)
{
    TwoPointCyl *theTwoPointCyl = NULL;
    try
    {
		UF_initialize();//初始化
		
        theTwoPointCyl = new TwoPointCyl();
        // The following method shows the dialog immediately
        theTwoPointCyl->Show();
	
		UF_terminate();//終止
    }
    catch(exception& ex)
    {
        //---- Enter your exception handling code here -----
        TwoPointCyl::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    if(theTwoPointCyl != NULL)
    {
        delete theTwoPointCyl;
        theTwoPointCyl = NULL;
    }
}

Specify Point(指定點)控制元件的獲取

//獲取點XYZ座標
PropertyList *SelectPoint1Props = point01->GetProperties();
Point3d SelectPoint1 = SelectPoint1Props->GetPoint("Point");
delete SelectPoint1Props;
SelectPoint1Props = NULL;

//得到的是Point3d型別,使用時直接 .X,.Y,.Z,來獲得XYZ座標。
例子:
double pnt1[3] = {SelectPoint1.X, SelectPoint1.Y, SelectPoint1.Z};

Object Color Picker(物件顏色拾取器)控制元件的獲取

//獲取顏色值
PropertyList *blockColorProps = colorPicker0->GetProperties();
std::vector<int> color = blockColorProps->GetIntegerVector("Value");
delete blockColorProps;
blockColorProps = NULL;

//得到的是int型別,存在vector數組裡,使用時取數組裡的第一個值[0]。
例子:
UF_OBJ_set_color(BodyTag, color[0]);

Caesar.lu  
[email protected]