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盧尚宇