//创建操作的函数 // Mandatory UF Includes #include uf.h #include uf_object_types.h // Internal Includes #include NXOpen/ListingWindow.hxx #include NXOpen/NXMessageBox.hxx #include NXOpen/UI.hxx // InternalExternal Includes #include NXOpen/Annotations.hxx #include NXOpen/Assemblies_Component.hxx #include NXOpen/Assemblies_ComponentAssembly.hxx #include NXOpen/Body.hxx #include NXOpen/BodyCollection.hxx #include NXOpen/Face.hxx #include NXOpen/Line.hxx #include NXOpen/NXException.hxx #include NXOpen/NXObject.hxx #include NXOpen/Part.hxx #include NXOpen/PartCollection.hxx #include NXOpen/Session.hxx // Std C Includes #include iostream #include sstream #includeuf_modl.h using namespace NXOpen; using std::string; using std::exception; using std::stringstream; using std::endl; using std::cout; using std::cerr; //------------------------------------------------------------------------------ // NXOpen c test class //------------------------------------------------------------------------------ class MyClass { // class members public: static Session *theSession; static UI *theUI; MyClass(); ~MyClass(); void do_it(); void print(const NXString ); void print(const string ); void print(const char*); private: BasePart *workPart, *displayPart; NXMessageBox *mb; ListingWindow *lw; LogFile *lf; }; //------------------------------------------------------------------------------ // Initialize static variables //------------------------------------------------------------------------------ Session *(MyClass::theSession) NULL; UI *(MyClass::theUI) NULL; //------------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------------ MyClass::MyClass() { // Initialize the NX Open C API environment MyClass::theSession NXOpen::Session::GetSession(); MyClass::theUI UI::GetUI(); mb theUI-NXMessageBox(); lw theSession-ListingWindow(); lf theSession-LogFile(); workPart theSession-Parts()-BaseWork(); displayPart theSession-Parts()-BaseDisplay(); } //------------------------------------------------------------------------------ // Destructor //------------------------------------------------------------------------------ MyClass::~MyClass() { } //------------------------------------------------------------------------------ // Print string to listing window or stdout //------------------------------------------------------------------------------ void MyClass::print(const NXString msg) { if(! lw-IsOpen() ) lw-Open(); lw-WriteLine(msg); } void MyClass::print(const string msg) { if(! lw-IsOpen() ) lw-Open(); lw-WriteLine(msg); } void MyClass::print(const char * msg) { if(! lw-IsOpen() ) lw-Open(); lw-WriteLine(msg); } //------------------------------------------------------------------------------ // Do something //------------------------------------------------------------------------------ void MyClass::do_it() { // TODO: add your code here //创建一个体 double coner[3] { 0,0,0 }; char *edge[3] { 100,60,40 }; tag_t blk_tag; UF_MODL_create_block1(UF_NULLSIGN, coner, edge, blk_tag); //create a blend start char *radius 20; uf_list_p_t blend_list, face_list, edge_list; tag_t body_tag, tem_face, tem_edge, faces[6], edges[12], blend_feature; int face_count, edge_count; // 遍历面 UF_MODL_create_list(face_list); UF_MODL_ask_feat_body(blk_tag, body_tag); UF_MODL_ask_body_faces(body_tag, face_list); UF_MODL_ask_list_count(face_list, face_count); for (int i 0; i face_count; i) { UF_MODL_ask_list_item(face_list, i, tem_face); faces[i] tem_face; } UF_MODL_delete_list(face_list); //遍历边 UF_MODL_create_list(edge_list); UF_MODL_ask_body_edges(body_tag, edge_list); UF_MODL_ask_list_count(edge_list, edge_count); for (int j 0; j edge_count; j) { UF_MODL_ask_list_item(edge_list, j, tem_edge); edges[j] tem_edge; } UF_MODL_delete_list(edge_list); // 创建阵列 UF_MODL_create_list(blend_list); UF_MODL_put_list_item(blend_list, edges[6]); UF_MODL_create_blend(radius, blend_list, 0, 0, 0, 0.5, blend_feature); UF_MODL_delete_list(blend_list); // 创建孔 double location[3] { 80,40,40 }; double direction[3] { 0,0,-1 }; const char * diame 15; const char * depth 5; const char * angle 0; tag_t hole_id; UF_MODL_create_simple_hole(location, direction, diame, depth, angle, faces[0], faces[1], hole_id); // create instance double origin[3] { 10,10,0 }; double dir[3] { 0,0,1 }; tag_t cyl_tag; UF_MODL_create_cyl1(UF_NEGATIVE, origin, 20, 10, dir, cyl_tag); char * number_in_x 2; char * distance_x 30; char * number_in_y 2; char * distance_y 30; tag_t feature_obj_id; uf_list_p_t feature_list; UF_MODL_create_list(feature_list); UF_MODL_put_list_item(feature_list, cyl_tag); UF_MODL_create_linear_iset(0, number_in_x, distance_x, number_in_y, distance_y, feature_list, feature_obj_id); UF_MODL_delete_list(feature_list); } //------------------------------------------------------------------------------ // Entry point(s) for unmanaged internal NXOpen C/C programs //------------------------------------------------------------------------------ // Explicit Execution extern C DllExport void ufusr( char *parm, int *returnCode, int rlen ) { UF_initialize();//入口函数 try { // Create NXOpen C class instance MyClass *theMyClass; theMyClass new MyClass(); theMyClass-do_it(); delete theMyClass; } catch (const NXException e1) { UI::GetUI()-NXMessageBox()-Show(NXException, NXOpen::NXMessageBox::DialogTypeError, e1.Message()); } catch (const exception e2) { UI::GetUI()-NXMessageBox()-Show(Exception, NXOpen::NXMessageBox::DialogTypeError, e2.what()); } catch (...) { UI::GetUI()-NXMessageBox()-Show(Exception, NXOpen::NXMessageBox::DialogTypeError, Unknown Exception.); } UF_terminate();//出口函数 } //------------------------------------------------------------------------------ // Unload Handler //------------------------------------------------------------------------------ extern C DllExport int ufusr_ask_unload() { return (int)NXOpen::Session::LibraryUnloadOptionImmediately; }