NX11+VS2013
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/WCS.hxx>
#include <NXOpen/CartesianCoordinateSystem.hxx>
#include <NXOpen/CoordinateSystem.hxx>
#include <NXOpen/CoordinateSystemCollection.hxx>
using namespace NXOpen;
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
//获取WCS相关信息
NXOpen::CartesianCoordinateSystem* WcsData = workPart->WCS()->CoordinateSystem();
//获得WCS的向量方向
NXOpen::Vector3d xDirection;
NXOpen::Vector3d yDirection;
WcsData->GetDirections(&xDirection, &yDirection);
//获得WCS的原点坐标
Point3d WcsOrigin = workPart->WCS()->Origin();
//围绕指定的轴旋转WCS
double Angle = 45.0;
workPart->WCS()->Rotate(NXOpen::WCS::AxisXAxis, Angle);
//在工作部件中创建一个新的笛卡尔坐标系,即使WCS属于显示部件
NXOpen::CartesianCoordinateSystem* WcsNew = workPart->WCS()->Save();
//将WCS的坐标系更改为一个新的坐标系
//返回值是旧的坐标系。将WCS移动到新的坐标系位置后,将显示旧坐标系。
NXOpen::Point3d origin1 = { 150.0, 0.0, 0.0 };
NXOpen::Vector3d xDirection1 = { 1.0, 0.0, 0.0 };
NXOpen::Vector3d yDirection1 = { 0.0, 1.0, 0.0 };
NXOpen::CartesianCoordinateSystem *newCs = workPart->CoordinateSystems()->CreateCoordinateSystem(origin1, xDirection1, yDirection1);
NXOpen::CartesianCoordinateSystem* WcsOld = workPart->WCS()->SetCoordinateSystem(newCs);
//在新的坐标系中创建一个WCS
//返回值是WCS的旧坐标系
NXOpen::Point3d origin2 = { 150.0, 0.0, 0.0 };
NXOpen::Vector3d xDirection2 = { 1.0, 0.0, 0.0 };
NXOpen::Vector3d yDirection2 = { 0.0, 1.0, 0.0 };
NXOpen::CartesianCoordinateSystem *newCs1 = workPart->CoordinateSystems()->CreateCoordinateSystem(origin2, xDirection2, yDirection2);
NXOpen::CartesianCoordinateSystem* WcsOld1 = workPart->WCS()->SetCoordinateSystemCartesianAtCsys(newCs1);
//设置WCS原点
Point3d WcsOri = { 100.0, 100.0, 100.0 };
workPart->WCS()->SetOrigin(WcsOri);
//设置WCS的原点和方向矩阵
Point3d WcsOri1 = { 100.0, 100.0, 100.0 };
Matrix3x3 matrix = { , , , , , , , , };
workPart->WCS()->SetOriginAndMatrix(WcsOri1, matrix);
//设置WCS的可见性
workPart->WCS()->SetVisibility(false);
//得到WCS的tag
tag_t WcsTag = workPart->WCS()->Tag();
//获得WCS的可见性
bool WcsVis = workPart->WCS()->Visibility();
2019年8月17日
Caesar卢尚宇