//CESHI_ARC // Mandatory UF Includes #include "C:\\all_uf.h" #include <uf.h> #include <uf_modl.h> #include <uf_disp.h> #include<vector> // Internal Includes #include <NXOpen/ListingWindow.hxx> #include <NXOpen/NXMessageBox.hxx> #include <NXOpen/UI.hxx> // Internal+External 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> #include <uf_defs.h> #include <NXOpen/NXException.hxx> #include <NXOpen/ModelingView.hxx> #include <NXOpen/ModelingViewCollection.hxx> #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/Session.hxx> #include <NXOpen/UI.hxx> #include <NXOpen/selection.hxx> #include <NXOpen/Features_Feature.hxx> #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/ListingWindow.hxx> #include <NXOpen/NXObject.hxx> #include <NXOpen/NXObjectManager.hxx> // Std C++ Includes #include <iostream> #include <sstream> 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 C_ARC { // class members public: static Session *theSession; static UI *theUI; C_ARC(); ~C_ARC(); void do_it(); void print(const NXString &); void print(const string &); void print(const char*); private: Part *workPart, *displayPart; NXMessageBox *mb; ListingWindow *lw; }; //------------------------------------------------------------------------------ // Initialize static variables //------------------------------------------------------------------------------ Session *(C_ARC::theSession) = NULL; UI *(C_ARC::theUI) = NULL; //------------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------------ C_ARC::C_ARC() { // Initialize the NX Open C++ API environment C_ARC::theSession = NXOpen::Session::GetSession(); C_ARC::theUI = UI::GetUI(); mb = theUI->NXMessageBox(); lw = theSession->ListingWindow(); workPart = theSession->Parts()->Work(); displayPart = theSession->Parts()->Display(); } //------------------------------------------------------------------------------ // Destructor //------------------------------------------------------------------------------ C_ARC::~C_ARC() { } //------------------------------------------------------------------------------ // Print string to listing window or stdout //------------------------------------------------------------------------------ void C_ARC::print(const NXString &msg) { if(! lw->IsOpen() ) lw->Open(); lw->WriteLine(msg); } void C_ARC::print(const string &msg) { if(! lw->IsOpen() ) lw->Open(); lw->WriteLine(msg); } void C_ARC::print(const char * msg) { if(! lw->IsOpen() ) lw->Open(); lw->WriteLine(msg); } //预选高亮 static int select_filter_proc_fn(tag_t object, int type[3], void* user_data, UF_UI_selection_p_t select) { if (object == NULL) { return UF_UI_SEL_REJECT; } else { return UF_UI_SEL_ACCEPT; } } static int init_proc(UF_UI_selection_p_t select, void* user_data) { int num_triples = 1;//可选类型的数量 UF_UI_mask_t mask_triples[] = { UF_circle_type, UF_circle_open_subtype };//可选对象类型 UF_UI_set_sel_mask(select, UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, num_triples, mask_triples); if ((UF_UI_set_sel_procs(select, select_filter_proc_fn, NULL, user_data)) == 0) { return UF_UI_SEL_SUCCESS; } else { return UF_UI_SEL_FAILURE; } } //------------------------------------------------------------------------------ // Do something //------------------------------------------------------------------------------ void C_ARC::do_it() { // TODO: add your code here UF_initialize(); //单对象选择对话框 char sCue[] = "单对象选择对话框"; char sTitle[] = "单对象选择对话框"; int iScope = UF_UI_SEL_SCOPE_NO_CHANGE; int iResponse; tag_t tObject; tag_t tView; double adCursor[3]; UF_UI_select_with_single_dialog(sCue, sTitle, iScope, init_proc, NULL, &iResponse, &tObject, adCursor, &tView); UF_CURVE_arc_t Obj_data; UF_CURVE_ask_arc_data(tObject, &Obj_data); char aa[256]; if (tObject > 0) { double Sp = Obj_data.start_angle/PI*180.0; double Ep = Obj_data.end_angle /PI*180.0; sprintf(aa, "%f\n%f", Sp,Ep); uc1601(aa, 1); } UF_DISP_set_highlight(tObject,0); UF_terminate(); } //------------------------------------------------------------------------------ // Entry point(s) for unmanaged internal NXOpen C/C++ programs //------------------------------------------------------------------------------ // Explicit Execution extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen ) { try { // Create NXOpen C++ class instance C_ARC *theC_ARC; theC_ARC = new C_ARC(); theC_ARC->do_it(); delete theC_ARC; } 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."); } } //------------------------------------------------------------------------------ // Unload Handler //------------------------------------------------------------------------------ extern "C" DllExport int ufusr_ask_unload() { return (int)NXOpen::Session::LibraryUnloadOptionImmediately; }
部分代码转自https://www.cnblogs.com/nxopen2018/p/10957188.html卢尚宇