1 //NX9_NXOpenCPP_Wizard1
2
3 // Mandatory UF Includes
4 #include <uf.h>
5 #include <uf_object_types.h>
6
7 // Internal Includes
8 #include <NXOpen/ListingWindow.hxx>
9 #include <NXOpen/NXMessageBox.hxx>
10 #include <NXOpen/UI.hxx>
11
12 // Internal+External Includes
13 #include <NXOpen/Annotations.hxx>
14 #include <NXOpen/Assemblies_Component.hxx>
15 #include <NXOpen/Assemblies_ComponentAssembly.hxx>
16 #include <NXOpen/Body.hxx>
17 #include <NXOpen/BodyCollection.hxx>
18 #include <NXOpen/Face.hxx>
19 #include <NXOpen/Line.hxx>
20 #include <NXOpen/NXException.hxx>
21 #include <NXOpen/NXObject.hxx>
22 #include <NXOpen/Part.hxx>
23 #include <NXOpen/PartCollection.hxx>
24 #include <NXOpen/Session.hxx>
25
26 #include <uf.h>
27 #include <uf_ui.h>
28 #include <uf_drf.h>
29
30 // Std C++ Includes
31 #include <iostream>
32 #include <sstream>
33
34 using namespace NXOpen;
35 using std::string;
36 using std::exception;
37 using std::stringstream;
38 using std::endl;
39 using std::cout;
40 using std::cerr;
41
42
43 //------------------------------------------------------------------------------
44 // NXOpen c++ test class
45 //------------------------------------------------------------------------------
46 class MyClass
47 {
48 // class members
49 public:
50 static Session *theSession;
51 static UI *theUI;
52
53 MyClass();
54 ~MyClass();
55
56 void do_it();
57 void print(const NXString &);
58 void print(const string &);
59 void print(const char*);
60
61 private:
62 Part *workPart, *displayPart;
63 NXMessageBox *mb;
64 ListingWindow *lw;
65 LogFile *lf;
66 };
67
68 //------------------------------------------------------------------------------
69 // Initialize static variables
70 //------------------------------------------------------------------------------
71 Session *(MyClass::theSession) = NULL;
72 UI *(MyClass::theUI) = NULL;
73
74 //------------------------------------------------------------------------------
75 // Constructor
76 //------------------------------------------------------------------------------
77 MyClass::MyClass()
78 {
79
80 // Initialize the NX Open C++ API environment
81 MyClass::theSession = NXOpen::Session::GetSession();
82 MyClass::theUI = UI::GetUI();
83 mb = theUI->NXMessageBox();
84 lw = theSession->ListingWindow();
85 lf = theSession->LogFile();
86
87 workPart = theSession->Parts()->Work();
88 displayPart = theSession->Parts()->Display();
89
90 }
91
92 //------------------------------------------------------------------------------
93 // Destructor
94 //------------------------------------------------------------------------------
95 MyClass::~MyClass()
96 {
97 }
98
99 //------------------------------------------------------------------------------
100 // Print string to listing window or stdout
101 //------------------------------------------------------------------------------
102 void MyClass::print(const NXString &msg)
103 {
104 if(! lw->IsOpen() ) lw->Open();
105 lw->WriteLine(msg);
106 }
107 void MyClass::print(const string &msg)
108 {
109 if(! lw->IsOpen() ) lw->Open();
110 lw->WriteLine(msg);
111 }
112 void MyClass::print(const char * msg)
113 {
114 if(! lw->IsOpen() ) lw->Open();
115 lw->WriteLine(msg);
116 }
117
118
119
120
121 //------------------------------------------------------------------------------
122 // Do something
123 //------------------------------------------------------------------------------
124 void MyClass::do_it()
125 {
126
127 // TODO: add your code here
128
129 UF_initialize();
130
131 //创建注释
132 char* TextString[] = {"Caesar卢尚宇"};
133 double Origin3d[3] = {100,100,100};
134 tag_t NoteTag = NULL_TAG;
135 UF_DRF_create_note(1, TextString, Origin3d, 0, &NoteTag);
136
137 //询问注释对象的数据。可以通过将ann_data数组传递给UF_DRF_ask_text_data来读取注释的文本数据(老函数用uc5574读取)
138 int search_mask [4];
139 int cycle_flag = 0;
140 int ann_data [10];
141 int ann_data_type = 0;
142 int ann_data_form = 0;
143 int num_segments = 0;
144 double ann_origin [2];
145 double radius_angle = 0;
146 UF_DRF_ask_ann_data(&NoteTag, search_mask, &cycle_flag, ann_data, &ann_data_type, &ann_data_form, &num_segments, ann_origin, &radius_angle);
147
148 //读取注释
149 int ip1 = 1;
150 char* cr3;
151 int ir4 = 0;
152 int ir5 = 0;
153 UF_DRF_ask_text_data(ip1, ann_data, &cr3, &ir4, &ir5);
154
155 //打印
156 uc1601(cr3,1);
157
158 UF_terminate();
159 }
160
161 //------------------------------------------------------------------------------
162 // Entry point(s) for unmanaged internal NXOpen C/C++ programs
163 //------------------------------------------------------------------------------
164 // Explicit Execution
165 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
166 {
167 try
168 {
169 // Create NXOpen C++ class instance
170 MyClass *theMyClass;
171 theMyClass = new MyClass();
172 theMyClass->do_it();
173 delete theMyClass;
174 }
175 catch (const NXException& e1)
176 {
177 UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
178 }
179 catch (const exception& e2)
180 {
181 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
182 }
183 catch (...)
184 {
185 UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
186 }
187 }
188
189
190 //------------------------------------------------------------------------------
191 // Unload Handler
192 //------------------------------------------------------------------------------
193 extern "C" DllExport int ufusr_ask_unload()
194 {
195 return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
196 }
197
198
199 Caesar卢尚宇
200 2019年10月3日