#include <NXOpen/MeasureBuilder.hxx>
#include <NXOpen/MeasureDistance.hxx>
#include <NXOpen/MeasureDistanceBuilder.hxx>
#include <NXOpen/MeasureManager.hxx>
#include <NXOpen/DirectionCollection.hxx>
double WCSToEdgeDistance(Point3d WcsOrigin,Edge *ScrewEdge);// 测量边到WCS的距离
double TwoFaceProjectionDistance(Face *Disface1,NXOpen::Vector3d DisDirection,Face *Disface2);// 测量面到面的投影距离
double HoleTable::WCSToEdgeDistance(Point3d WcsOrigin,Edge *ScrewEdge)// 测量边到点的距离
{
try
{
double distance;
std::vector<double> measureValue;//测量的值(double型)
NXObject *nullNXObject(NULL);
MeasureDistanceBuilder *measureDistanceBuilder1;
measureDistanceBuilder1 = workPart->MeasureManager()->CreateMeasureDistanceBuilder(nullNXObject);
measureDistanceBuilder1->SetMtype(MeasureDistanceBuilder::MeasureTypeMinimum);
NXOpen::Point *WCSPoint1 = workPart->Points()->CreatePoint(WcsOrigin);
measureDistanceBuilder1->Object1()->SetValue(WCSPoint1);//第一个对象
measureDistanceBuilder1->Object2()->SetValue(ScrewEdge);//第二个对象
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
MeasureDistance *measureDistance1;
measureDistance1 = workPart->MeasureManager()->NewDistance(unit1, MeasureManager::MeasureTypeMinimum, WCSPoint1, ScrewEdge);
//Measure *measure1;
//measure1 = measureDistance1->CreateFeature();//只需得到值不创建
distance = measureDistance1->Value();//获取测量的值
return double(distance);
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
HoleTable::theUI->NXMessageBox()->Show("测量边到点的距离", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
double HoleTable::TwoFaceProjectionDistance(Face *Disface1,NXOpen::Vector3d DisDirection,Face *Disface2)// 测量面到面的投影距离
{
try
{
NXObject *nullNXObject(NULL);
MeasureDistanceBuilder *measureDistanceBuilder1;
measureDistanceBuilder1 = workPart->MeasureManager()->CreateMeasureDistanceBuilder(nullNXObject);
Direction *direction1;
direction1 = workPart->Directions()->CreateDirection(WcsOrigin, DisDirection, SmartObject::UpdateOptionAfterModeling);
measureDistanceBuilder1->SetProjectionVector(direction1);//设置投影方向
//设置第一个面
measureDistanceBuilder1->Object1()->SetValue(Disface1);
//设置第二个面
measureDistanceBuilder1->Object2()->SetValue(Disface2);
//创建,类型为投影距离
MeasureDistance *measureDistance1;
measureDistance1 = workPart->MeasureManager()->NewDistance(NULL, Disface1, Disface2, direction1, MeasureManager::ProjectionTypeMinimum);
//获得距离
double Distance = measureDistance1->Value();
//销毁删除
delete measureDistance1;
return double(Distance);
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
HoleTable::theUI->NXMessageBox()->Show("测量面到面的投影距离", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}