NX11+VS2013

#include <NXOpen/Line.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
#include <uf.h>
#include <uf_curve.h>
#include <uf_ui.h>
#include <NXOpen/Edge.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <uf_eval.h>

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

UF_initialize();

//创建一条直线
UF_CURVE_line_t Line_Coords;
Line_Coords.start_point[0] = 10.0;
Line_Coords.start_point[1] = 0.0;
Line_Coords.start_point[2] = 0.0;
Line_Coords.end_point[0] = 100.0;
Line_Coords.end_point[1] = 0.0;
Line_Coords.end_point[2] = 0.0;
tag_t LineTag = NULL_TAG;
UF_CURVE_create_line(&Line_Coords, &LineTag);

//方法1:UFUN方法
//获得一条直线两个端点坐标、直线长度、向量方向

//函数1(UF_CURVE_ask_line_data)
UF_CURVE_line_t AskLinePoint;
UF_CURVE_ask_line_data(LineTag, &AskLinePoint);
double UF1LinePoint1[3] = { AskLinePoint.start_point[0], AskLinePoint.start_point[1], AskLinePoint.start_point[2] };//获得直线起点坐标
double UF1LinePoint2[3] = { AskLinePoint.end_point[0], AskLinePoint.end_point[1], AskLinePoint.end_point[2] };//获得直线终点坐标

//函数2(UF_EVAL_ask_line)
UF_EVAL_p_t evaluator;
UF_EVAL_initialize(LineTag, &evaluator);

UF_EVAL_line_t line;
UF_EVAL_ask_line(evaluator, &line);
double UFLineLength = line.length;//获得直线长度
double UF2LinePoint1[3] = { line.start[0], line.start[1], line.start[2] };//获得直线起点坐标
double UF2LinePoint2[3] = { line.end[0], line.end[1], line.end[2] };//获得直线终点坐标
double UFLineVec[3] = { line.unit[0], line.unit[1], line.unit[2] };//获得直线向量方向

char msg[256];
sprintf_s(msg, "直线的长度为:%.3f\n直线的起点坐标X为:%.3f  直线的起点坐标Y为:%.3f  直线的起点坐标Z为:%.3f\n直线的终点坐标X为%.3f  直线的终点坐标Y为:%.3f 直线的终点坐标Z为:%.3f\n直线的向量方向为:%.0f,%.0f,%.0f",
	UFLineLength, UF2LinePoint1[0], UF2LinePoint1[1], UF2LinePoint1[2], UF2LinePoint2[0], UF2LinePoint2[1], UF2LinePoint2[2], UFLineVec[0], UFLineVec[1], UFLineVec[2]);

lw->Open();
lw->WriteLine(msg);

UF_EVAL_free(evaluator);

//方法2:NXOpen方法
//获得一条直线两个端点坐标、直线长度
std::vector<Line*> LineVector;
LineVector.push_back(dynamic_cast<Line*>(NXObjectManager::Get(LineTag)));

for (int i = 0; i < LineVector.size(); i++)
{
	double NXLineLength = LineVector[i]->GetLength();//获得直线长度
	Point3d NXLinePoint1 = LineVector[i]->StartPoint();//获得直线起点坐标
	//char msg[200];
	//sprintf_s(msg, "%.3f,%.3f,%.3f", NXLinePoint1.X, NXLinePoint1.Y, NXLinePoint1.Z);
	//uc1601(msg, 1);
	Point3d NXLinePoint2 = LineVector[i]->EndPoint();//获得直线终点坐标
	//sprintf_s(msg, "%.3f,%.3f,%.3f", NXLinePoint2.X, NXLinePoint2.Y, NXLinePoint2.Z);
	//uc1601(msg, 1);
}

UF_terminate();

Caesar卢尚宇  [email protected]

NX二次开发-查询直线函数UF_EVAL_ask_line与NXOpen::Line查询直线的用法

相关文章:

  • 2021-06-04
  • 2022-02-18
  • 2021-11-17
  • 2021-11-17
  • 2021-09-28
  • 2022-01-26
  • 2021-09-05
  • 2021-05-29
猜你喜欢
  • 2021-12-19
  • 2022-01-28
  • 2021-07-31
  • 2021-08-20
  • 2022-01-21
  • 2021-06-28
  • 2022-02-15
相关资源
相似解决方案