1 NX11+VS2013 2 3 4 #include <NXOpen/Section.hxx> 5 #include <NXOpen/SectionCollection.hxx> 6 #include <NXOpen/Part.hxx> 7 #include <NXOpen/PartCollection.hxx> 8 #include <NXOpen/CoordinateSystem.hxx> 9 #include <NXOpen/CoordinateSystemCollection.hxx> 10 #include <NXOpen/CartesianCoordinateSystem.hxx> 11 #include <NXOpen/NXMatrix.hxx> 12 #include <NXOpen/NXMatrixCollection.hxx> 13 #include <NXOpen/Xform.hxx> 14 #include <NXOpen/XformCollection.hxx> 15 #include <NXOpen/Scalar.hxx> 16 #include <NXOpen/ScalarCollection.hxx> 17 #include <NXOpen/CylindricalCoordinateSystem.hxx> 18 #include <NXOpen/UI.hxx> 19 #include <NXOpen/NXMessageBox.hxx> 20 21 22 using namespace NXOpen; 23 using namespace std; 24 25 26 NXOpen::Session *theSession = NXOpen::Session::GetSession(); 27 NXOpen::Part *workPart(theSession->Parts()->Work()); 28 NXOpen::Part *displayPart(theSession->Parts()->Display()); 29 30 //創建一個新的笛卡爾坐標系(TRUE和FALSE,如果坐標系是臨時的用TRUE,它將不會顯示,也不會保存在部件中) 31 Point3d WcsOrigin1(100.0, 100.0, 100.0);//原點 32 Matrix3x3 WcsMatrix1 (1, 0, 0, 0, 1, 0, 0, 0, 1);//矩陣 33 NXOpen::CartesianCoordinateSystem* WcsNew1 = workPart->CoordinateSystems()->CreateCoordinateSystem(WcsOrigin1, WcsMatrix1, FALSE); 34 35 //創建一個新的笛卡爾坐標系 36 Point3d WcsOrigin2(200.0, 200.0, 200.0);//原點 37 Vector3d xDirection2(1.0, 0.0, 0.0);//向量 38 Vector3d yDirection2(0.0, 1.0, 0.0); 39 NXOpen::CartesianCoordinateSystem* WcsNew2 = workPart->CoordinateSystems()->CreateCoordinateSystem(WcsOrigin2, xDirection2, yDirection2); 40 41 //創建一個新的笛卡爾坐標系(TRUE和FALSE,如果坐標系是臨時的用TRUE,它將不會顯示,也不會保存在部件中) 42 Point3d WcsOrigin3(300.0, 300.0, 300.0);//原點 43 Matrix3x3 WcsMatrix3(1, 0, 0, 0, 1, 0, 0, 0, 1);//矩陣 44 NXOpen::NXMatrix* Matrix3 = workPart->NXMatrices()->Create(WcsMatrix3);//創建一個新的矩陣 45 NXOpen::CartesianCoordinateSystem* WcsNew3 = workPart->CoordinateSystems()->CreateCoordinateSystem(WcsOrigin3, Matrix3, FALSE); 46 47 //創建一個新的笛卡爾坐標系 48 Point3d WcsOrigin4(400.0, 400.0, 400.0);//原點 49 Vector3d xDirection4(1.0, 0.0, 0.0);//向量 50 Vector3d yDirection4(0.0, 1.0, 0.0); 51 double Scale = 1; 52 NXOpen::Xform* xform = workPart->Xforms()->CreateXform(WcsOrigin4, xDirection4, yDirection4, SmartObject::UpdateOptionWithinModeling, Scale); 53 NXOpen::CartesianCoordinateSystem* WcsNew4 = workPart->CoordinateSystems()->CreateCoordinateSystem(xform, SmartObject::UpdateOptionWithinModeling); 54 WcsNew4->SetVisibility(SmartObject::VisibilityOptionVisible);//設置顯示坐標系 55 56 //創建一個新的圓柱坐標系 57 Point3d WcsOrigin5(500.0, 500.0, 500.0);//原點 58 Vector3d xDirection5(1.0, 0.0, 0.0);//向量 59 Vector3d yDirection5(0.0, 1.0, 0.0); 60 NXOpen::CylindricalCoordinateSystem* WcsNew5 = workPart->CoordinateSystems()->CreateCylindricalCoordinateSystem(WcsOrigin5, xDirection5, yDirection5); 61 62 //創建一個新的圓柱坐標系(TRUE和FALSE,如果坐標系是臨時的用TRUE,它將不會顯示,也不會保存在部件中) 63 Point3d WcsOrigin6(600.0, 600.0, 600.0);//原點 64 Matrix3x3 WcsMatrix6(1, 0, 0, 0, 1, 0, 0, 0, 1);//矩陣 65 NXOpen::NXMatrix* Matrix6 = workPart->NXMatrices()->Create(WcsMatrix6);//創建一個新的矩陣 66 NXOpen::CylindricalCoordinateSystem* WcsNew6 = workPart->CoordinateSystems()->CreateCylindricalCoordinateSystem(WcsOrigin6, Matrix6, FALSE); 67 68 //創建一個新的圓柱坐標系 69 Point3d WcsOrigin7(700.0, 700.0, 700.0);//原點 70 Vector3d xDirection7(1.0, 0.0, 0.0);//向量 71 Vector3d yDirection7(0.0, 1.0, 0.0); 72 double Scale7 = 1; 73 NXOpen::Xform* xform7 = workPart->Xforms()->CreateXform(WcsOrigin7, xDirection7, yDirection7, SmartObject::UpdateOptionWithinModeling, Scale7); 74 NXOpen::CylindricalCoordinateSystem* WcsNew7 = workPart->CoordinateSystems()->CreateCylindricalCoordinateSystem(xform7, SmartObject::UpdateOptionWithinModeling); 75 WcsNew7->SetVisibility(SmartObject::VisibilityOptionVisible);//設置顯示坐標系 76 77 //迭代器遍歷所有坐標系 78 vector<tag_t> AllCoordVector;//定義vector 79 NXOpen::CoordinateSystem* AllCoord;//定義類型 80 NXOpen::CoordinateSystemCollection::iterator Ite;//定義迭代器 81 for (Ite = workPart->CoordinateSystems()->begin(); Ite != workPart->CoordinateSystems()->end(); ++Ite) 82 { 83 AllCoord = (*Ite); 84 AllCoordVector.push_back(AllCoord->Tag());//獲得坐標系的tag 85 } 86 87 char msg[256]; 88 sprintf_s(msg, "坐標系數量為:%d", AllCoordVector.size()); 89 UI::GetUI()->NXMessageBox()->Show("標題", NXMessageBox::DialogTypeWarning, msg); 90 91 92 Caesar盧尚宇 93 2019年8月31日