NXopen c++ 有界平面 BoundedPlane 测量平面面积周长 NewFaceProperties

通过建立三条关联直线创建有界平面,并测量其周长和面积

//1、模板文件添加头文件*
#include <NXOpen/Features_BoundedPlane.hxx>
#include <NXOpen/Features_BoundedPlaneBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/Features_AssociativeLineBuilder.hxx>
#include <NXOpen/SelectPoint.hxx>
#include <NXOpen/Features_BaseFeatureCollection.hxx>
#include <NXOpen/CurveCollection.hxx>
#include <NXOpen/PointCollection.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <uf_curve.h>
#include <NXOpen/CurveDumbRule.hxx>
#include <NXOpen/ScRuleFactory.hxx>
#include <NXOpen/MeasureFaces.hxx>
#include <NXOpen/UnitCollection.hxx>
#include <NXOpen/Unit.hxx>
//**2、函数声明**
NXOpen::Point* pointcreat(double PTcoordinates[3], NXOpen::Part* part);
//**3、函数定义**
NXOpen::Point* MyClass::pointcreat(double PTcoordinates[3], NXOpen::Part* part)
{
	NXOpen::Point3d coordinates(PTcoordinates[0], PTcoordinates[1], PTcoordinates[2]);
	NXOpen::Point* point;
	point = part->Points()->CreatePoint(coordinates);
	return point;
}
//**4、主程序**
    NXOpen::Session* theSession = NXOpen::Session::GetSession();
	NXOpen::Part* workPart(theSession->Parts()->Work());
	NXOpen::Part* displayPart(theSession->Parts()->Display());

	double P1coordinates[3] = { 0.0,0.0,0.0 };
	NXOpen::Point* Point1;
	Point1 = pointcreat(P1coordinates, workPart);//创建点Point1

	double P2coordinates[3] = {2.0,2.0,0.0 };
	NXOpen::Point* Point2;
	Point2 = pointcreat(P2coordinates, workPart);//创建点Point2

	double P3coordinates[3] = { 4.0,0.0,0.0 };
	NXOpen::Point* Point3;
	Point3 = pointcreat(P3coordinates, workPart);//创建点Point3

	NXOpen::Line* Line1 = workPart->Curves()->CreateLine(Point1, Point2);//创建直线Line1 通过点Point1和点Point2


	NXOpen::Line* Line2 = workPart->Curves()->CreateLine(Point2, Point3);//创建直线Line2通过点Point2和点Point3

	NXOpen::Line* Line3 = workPart->Curves()->CreateLine(Point3, Point1);//创建直线Line3 通过点Point3和点Point1

	NXOpen::Features::BoundedPlane* nullNXOpen_Features_BoundedPlane(NULL);
	NXOpen::Features::BoundedPlaneBuilder* boundedPlaneBuilder1;//有界平面构造器
	boundedPlaneBuilder1 = workPart->Features()->CreateBoundedPlaneBuilder(nullNXOpen_Features_BoundedPlane);
	boundedPlaneBuilder1->BoundingCurves()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);


	std::vector<NXOpen::IBaseCurve*> curves1;
	curves1.push_back(Line1);
	curves1.push_back(Line2);
	curves1.push_back(Line3);
	NXOpen::CurveDumbRule* curveDumbRule1;
	curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);

	std::vector<NXOpen::SelectionIntentRule*> rules1(1);
	rules1[0] = curveDumbRule1;
	NXOpen::NXObject* nullNXOpen_NXObject(NULL);
	NXOpen::Point3d helpPoint1;
	boundedPlaneBuilder1->BoundingCurves()->AddToSection(rules1, Line1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1, NXOpen::Section::ModeCreate, false);

	NXOpen::NXObject* nXObject1;
	nXObject1 = boundedPlaneBuilder1->Commit();
	NXOpen::Features::Feature* boundedPlane1;
	boundedPlane1 = boundedPlaneBuilder1->CommitFeature();
	std::vector< NXOpen::Face* >BoundedFaces = boundedPlane1->GetFaces();//获取有界平面特征的face对象

	std::vector< IParameterizedSurface*> objects1(1);
	objects1[0] = BoundedFaces[0];
	MeasureFaces* measureFaces1;
	Unit* unit1 = workPart->UnitCollection()->FindObject("SquareMilliMeter");
	Unit* unit2 = workPart->UnitCollection()->FindObject("MilliMeter");
	measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.9999, objects1);
//NewFaceProperties方法仅可返回面的面积和周长
	double areaValue = measureFaces1->Area();
	double PerimeterValue = measureFaces1->Perimeter();

	char msg[256];
	sprintf(msg, "面积:%f", areaValue);
	theSession->ListingWindow()->WriteLine(msg);

	sprintf(msg, "面积:%f", PerimeterValue);
	theSession->ListingWindow()->WriteLine(msg);

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值