1 NX11+VS2013
2
3 #include <NXOpen/Part.hxx>
4 #include <NXOpen/PartCollection.hxx>
5 #include <NXOpen/Session.hxx>
6 #include <NXOpen/WCS.hxx>
7 #include <NXOpen/CartesianCoordinateSystem.hxx>
8 #include <NXOpen/CoordinateSystem.hxx>
9 #include <NXOpen/CoordinateSystemCollection.hxx>
10 using namespace NXOpen;
11
12
13 NXOpen::Session *theSession = NXOpen::Session::GetSession();
14 NXOpen::Part *workPart(theSession->Parts()->Work());
15 NXOpen::Part *displayPart(theSession->Parts()->Display());
16
17 //获取WCS相关信息
18 NXOpen::CartesianCoordinateSystem* WcsData = workPart->WCS()->CoordinateSystem();
19
20 //获得WCS的向量方向
21 NXOpen::Vector3d xDirection;
22 NXOpen::Vector3d yDirection;
23 WcsData->GetDirections(&xDirection, &yDirection);
24
25 //获得WCS的原点坐标
26 Point3d WcsOrigin = workPart->WCS()->Origin();
27
28 //围绕指定的轴旋转WCS
29 double Angle = 45.0;
30 workPart->WCS()->Rotate(NXOpen::WCS::AxisXAxis, Angle);
31
32 //在工作部件中创建一个新的笛卡尔坐标系,即使WCS属于显示部件
33 NXOpen::CartesianCoordinateSystem* WcsNew = workPart->WCS()->Save();
34
35 //将WCS的坐标系更改为一个新的坐标系
36 //返回值是旧的坐标系。将WCS移动到新的坐标系位置后,将显示旧坐标系。
37 NXOpen::Point3d origin1 = { 150.0, 0.0, 0.0 };
38 NXOpen::Vector3d xDirection1 = { 1.0, 0.0, 0.0 };
39 NXOpen::Vector3d yDirection1 = { 0.0, 1.0, 0.0 };
40 NXOpen::CartesianCoordinateSystem *newCs = workPart->CoordinateSystems()->CreateCoordinateSystem(origin1, xDirection1, yDirection1);
41 NXOpen::CartesianCoordinateSystem* WcsOld = workPart->WCS()->SetCoordinateSystem(newCs);
42
43 //在新的坐标系中创建一个WCS
44 //返回值是WCS的旧坐标系
45 NXOpen::Point3d origin2 = { 150.0, 0.0, 0.0 };
46 NXOpen::Vector3d xDirection2 = { 1.0, 0.0, 0.0 };
47 NXOpen::Vector3d yDirection2 = { 0.0, 1.0, 0.0 };
48 NXOpen::CartesianCoordinateSystem *newCs1 = workPart->CoordinateSystems()->CreateCoordinateSystem(origin2, xDirection2, yDirection2);
49 NXOpen::CartesianCoordinateSystem* WcsOld1 = workPart->WCS()->SetCoordinateSystemCartesianAtCsys(newCs1);
50
51 //设置WCS原点
52 Point3d WcsOri = { 100.0, 100.0, 100.0 };
53 workPart->WCS()->SetOrigin(WcsOri);
54
55 //设置WCS的原点和方向矩阵
56 Point3d WcsOri1 = { 100.0, 100.0, 100.0 };
57 Matrix3x3 matrix = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
58 workPart->WCS()->SetOriginAndMatrix(WcsOri1, matrix);
59
60 //设置WCS的可见性
61 workPart->WCS()->SetVisibility(false);
62
63 //得到WCS的tag
64 tag_t WcsTag = workPart->WCS()->Tag();
65
66 //获得WCS的可见性
67 bool WcsVis = workPart->WCS()->Visibility();
2019年8月17日
Caesar卢尚宇