一、概述
NX二次开发中一般都是多个控件的组合,这里我首先对指定方位控件进行说明并结合选择对象控件,具体如下图所示。
二、实现功能获取方位其在选择面上原点的目标
2.1 在initialize_cb()函数中进行初始化,实现对象选择过滤面
//过滤平面
NXOpen::Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<NXOpen::Selection::MaskTriple>selectionMask_array(1);//括号内数字:maskArray数组大小(有多少种选择就写多少)//具体用法参考MaskTriple
selectionMask_array[0].Type = UF_solid_type;
selectionMask_array[0].Subtype = UF_solid_face_subtype;
selectionMask_array[0].SolidBodySubtype = UF_UI_SEL_FEATURE_ANY_FACE;NXOpen::BlockStyler::PropertyList *selComponentProps = SelectPoint->GetProperties();//selComp为对象收集器的ID
selComponentProps->SetSelectionFilter("SelectionFilter", action, selectionMask_array);
delete selComponentProps;
selComponentProps = NULL;
2.2在update_cb函数中通过选择面获得面上点击屏幕点将其设置为指定方位控件的原点,并通过输入面的TAG值,获得选择平面X、Y的向量值设置为指定方位控件的X、Y向量。
int NXOpen_EngravedText::update_cb(NXOpen::BlockStyler::UIBlock* block)
{try{if(block == SelectPoint){//---------Enter your code here-----------Point3d pickPoint = SelectPoint->PickPoint();//获得指定面上的点std::vector<TaggedObject*> objects = SelectPoint->GetSelectedObjects();GetxyDirection(objects[0]->Tag(), pickPoint);manippickPoint = manip0->Origin();}else if(block == manip0){//---------Enter your code here-----------}}catch(exception& ex){//---- Enter your exception handling code here -----NXOpen_EngravedText::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());}return 0;
}//通过输入面的TAG值,获得选择平面X、Y的向量值
void GetxyDirection(tag_t object, Point3d pickPoint)
{int faceTpye = 0;UF_MODL_ask_face_type(object, &faceTpye);vector<double> Directi;if (faceTpye == UF_MODL_PLANAR_FACE){int type = 0;double point[3];double dir[3];double box[6];double radius;double rad_data[2];int norm_dir = 0;UF_MODL_ask_face_data(object, &type, point, dir, box, &radius, rad_data, &norm_dir);double mtx[9];UF_MTX3_initialize_z(dir, mtx);manip0->SetOrigin(pickPoint);//指定方位器出现的原点Vector3d xDirection1(mtx[0], mtx[1], mtx[2]);Vector3d yDirection1(mtx[3], mtx[4], mtx[5]);manip0->SetXAxis(xDirection1);manip0->SetYAxis(yDirection1);}
}
2.3打印坐标,在void GetxyDirection(tag_t object, Point3d pickPoint)函数中只需将mtx按照X、Y、Z每个三个值分好分别进行打印即可,这里不提供代码。