//**1、模板文件添加头文件**
#include <NXOpen/Features_CylinderBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/AxisCollection.hxx>
//**2、函数声明**
NXOpen::Features::Feature* CreateCylinderFeature(double CylinderDiameter, double CylinderHeight, double OriginPoint[3], double Direction[3], NXOpen::Part* workPart);
//**3、函数定义**
NXOpen::Features::Feature* MyClass::CreateCylinderFeature(double CylinderDiameter, double CylinderHeight, double OriginPoint[3], double Direction[3], NXOpen::Part* workPart)
{
char Diameterchar[256];
sprintf(Diameterchar, "%f", CylinderDiameter);
char Heightchar[256];
sprintf(Heightchar, "%f", CylinderHeight);
NXOpen::Features::Feature* nullNXOpen_Features_Feature(NULL);
NXOpen::Features::CylinderBuilder* cylinderBuilder1;//圆柱特征构造器
cylinderBuilder1 = workPart->Features()->CreateCylinderBuilder(nullNXOpen_Features_Feature);
cylinderBuilder1->BooleanOption()->SetType(NXOpen::GeometricUtilities::BooleanOperation::BooleanTypeCreate);//布尔类型创建
cylinderBuilder1->SetType(NXOpen::Features::CylinderBuilder::Types::TypesAxisDiameterAndHeight);//创建圆柱通过轴、直径和高度
NXOpen::Point3d AxisOriginPoint(OriginPoint[0], OriginPoint[1], OriginPoint[2]);
NXOpen::Vector3d AxisDirection(Direction[0], Direction[1], Direction[2]);
NXOpen::Axis* axis1;
axis1 = workPart->Axes()->CreateAxis(AxisOriginPoint, AxisDirection, NXOpen::SmartObject::UpdateOptionWithinModeling);//创建非关联轴
cylinderBuilder1->SetAxis(axis1);
cylinderBuilder1->Diameter()->SetFormula(Diameterchar);
cylinderBuilder1->Height()->SetFormula(Heightchar);
NXOpen::Features::Feature* cyfeature;
cyfeature = cylinderBuilder1->CommitFeature();
cylinderBuilder1->Destroy();
return cyfeature;
}
//**4、主程序**
NXOpen::Session* theSession = NXOpen::Session::GetSession();
NXOpen::Part* workPart(theSession->Parts()->Work());//工作部件
NXOpen::Part* displayPart(theSession->Parts()->Display());
double CylinderDiameter = 100.0;//圆柱直径
double CylinderHeight = 10.0;//圆柱高度
double OriginPoint[3] = {0.0,0.0,0.0};//圆柱轴原点
double Direction[3] = { 0.0,0.0,1.0 };//圆柱轴方向
NXOpen::Features::Feature* cyfeature;
cyfeature=CreateCylinderFeature(CylinderDiameter, CylinderHeight, OriginPoint, Direction, workPart);//调用创建圆柱特征函数
NXOpen::Body* CYbody(dynamic_cast<NXOpen::Body*>(workPart->Bodies()->FindObject(cyfeature->JournalIdentifier())));//获取圆柱特征创建的体
NXopen 创建圆柱特征通过轴、直径和高度
于 2024-03-30 23:32:56 首次发布