NX二次开发-NXOpen获取边的端点NXOpen::Edge::GetVertices

NX9+VS2012

#include <NXOpen/Features_BlockFeatureBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Edge.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXopen/UI.hxx>
#include <NXOpen/DisplayManager.hxx>

using namespace NXOpen;

NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());

ListingWindow *lw;
lw = theSession->ListingWindow();


//NXOpen方式创建块
NXOpen::Features::Feature *nullNXOpen_Features_Feature(NULL);
NXOpen::Features::BlockFeatureBuilder *blockFeatureBuilder1;
blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);

std::vector<NXOpen::Body *> targetBodies1(1);
NXOpen::Body *nullNXOpen_Body(NULL);
targetBodies1[0] = nullNXOpen_Body;
blockFeatureBuilder1->BooleanOption()->SetTargetBodies(targetBodies1);

blockFeatureBuilder1->SetType(NXOpen::Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);//设置创建类型

NXOpen::Point3d originPoint1(120.0, 103.0, 154.0);
blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "142", "132", "118");//设置原点

blockFeatureBuilder1->SetBooleanOperationAndTarget(NXOpen::Features::Feature::BooleanTypeCreate, nullNXOpen_Body);//设置布尔

NXOpen::Features::Feature *feature1;
feature1 = blockFeatureBuilder1->CommitFeature();



//NXOpen方式设置颜色
NXOpen::DisplayModification *displayModification1;
displayModification1 = theSession->DisplayManager()->NewDisplayModification();

displayModification1->SetNewColor(108);//设置颜色

std::vector<NXOpen::DisplayableObject *> objects1(1);
NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
objects1[0] = body1;
displayModification1->Apply(objects1);


//NXOpen特征获取体
NXOpen::Body *MyBody(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));


//NXOpen体获取边
std::vector<NXOpen::Edge*> MyEdge = MyBody->GetEdges();

char msg1[256];
char msg2[256];
sprintf_s(msg1, "当前体有%d条边\n每条边的两个端点如下:\n", MyEdge.size());//转换

//打印
lw->Open();
lw->WriteLine(msg1);

for (int i = 0; i < MyEdge.size(); i++)
{
	MyEdge[i]->Highlight();//高亮所有边
	NXOpen::Point3d Vertex1[3];//端点1
	NXOpen::Point3d Vertex2[3];//端点2
	MyEdge[i]->GetVertices(Vertex1, Vertex2);//由边获取端点

	sprintf_s(msg2, "X坐标:%.0f,  Y坐标:%.0f, Z坐标:%.0f\nX坐标:%.0f,  Y坐标:%.0f,  Z坐标:%.0f\n", Vertex1->X, Vertex1->Y, Vertex1->Z, Vertex2->X, Vertex2->Y, Vertex2->Z);//转换
	lw->WriteLine(msg2);//打印
}

Caesar卢尚宇  [email protected]

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/lu1287580078/article/details/82962440
今日推荐