NX二次开发-UFUN读取工程图注释UF_DRF_ask_text_data

  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日

原文地址:https://www.cnblogs.com/nxopen2018/p/11619880.html

时间: 2024-11-09 18:11:46

NX二次开发-UFUN读取工程图注释UF_DRF_ask_text_data的相关文章

NX二次开发-NXOpen读取工程图注释note1-&gt;GetText();

1 NX9+VS2012 2 3 #include <uf.h> 4 #include <uf_drf.h> 5 #include <NXOpen/Annotations_Note.hxx> 6 #include <NXOpen/NXObjectManager.hxx> 7 8 9 UF_initialize(); 10 11 //创建注释 12 char* TextString[] = {"Caesar卢尚宇"}; 13 double

NX二次开发-UFUN读取表格注释内容UF_TABNOT_ask_cell_text

1 NX11+VS2013 2 3 #include <uf.h> 4 #include <uf_ui.h> 5 #include <uf_tabnot.h> 6 #include <NXOpen/Part.hxx> 7 #include <NXOpen/PartCollection.hxx> 8 #include <NXOpen/Session.hxx> 9 #include <NXOpen/Annotations_Table

NX二次开发-UFUN添加工程图投影视图UF_DRAW_add_orthographic_view

1 NX9+VS2012 2 3 #include <uf.h> 4 #include <uf_draw.h> 5 #include <uf_obj.h> 6 #include <uf_part.h> 7 8 UF_initialize(); 9 10 //新建工程图(A4图纸) 11 char* DrawingName = "Sheet1";//设置图纸名字 12 UF_DRAW_info_t DrawingInfo;//设置图纸大小.

NX二次开发-UFUN将工程图中的点坐标映射到建模绝对坐标UF_VIEW_map_drawing_to_model

1 #include <uf.h> 2 #include <uf_ui.h> 3 #include <uf_draw.h> 4 #include <uf_view.h> 5 #include <uf_curve.h> 6 7 8 9 UF_initialize(); 10 11 //在工程图里创建点 12 double p1[3] = { 106.905267, 139.431151 }; 13 14 //获得图纸页tag 15 int num_

NX二次开发-UFUN移动工程图视图UF_DRAW_move_view

1 #include <uf.h> 2 #include <uf_draw.h> 3 #include <uf_drf.h> 4 #include <uf_obj.h> 5 6 7 8 UF_initialize(); 9 10 //获得当前图纸页的tag 11 tag_t drawing_tag = NULL_TAG; 12 UF_DRAW_ask_current_drawing(&drawing_tag); 13 14 //找名字获取视图tag

NX二次开发-UFUN设置工程图PNG图片高度UF_DRF_set_image_height

1 #include <uf.h> 2 #include <uf_drf.h> 3 4 5 UF_initialize(); 6 7 //插入PNG 8 char* file_name = "D:\\123.png"; 9 double origin[3] = { 50.0, 50.0, 0.0 }; 10 tag_t ImageTag = NULL_TAG; 11 UF_DRF_create_image_from_file(file_name, NULL_TA

NX二次开发-UFUN设置工程图PNG图片长度UF_DRF_set_image_width

1 #include <uf.h> 2 #include <uf_drf.h> 3 4 5 UF_initialize(); 6 7 //插入PNG 8 char* file_name = "D:\\123.png"; 9 double origin[3] = { 50.0, 50.0, 0.0 }; 10 tag_t ImageTag = NULL_TAG; 11 UF_DRF_create_image_from_file(file_name, NULL_TA

NX二次开发-UFUN获取工程图所有视图tag UF_DRAW_ask_views

1 #include <uf.h> 2 #include <uf_draw.h> 3 #include <uf_drf.h> 4 #include <uf_obj.h> 5 6 7 8 UF_initialize(); 9 10 //获得当前图纸页的tag 11 tag_t drawing_tag = NULL_TAG; 12 UF_DRAW_ask_current_drawing(&drawing_tag); 13 14 //找名字获取视图tag

NX二次开发-UFUN和NXOpen结合开发中Tag_t对象与TaggedObject对象转换方法

1 本文通过举四个例子来告诉大家在NX二次开发过程中会经常用到UFUN和NXOpen结合去开发,在UFUN中我们得到的是Tag_t对象,在NXOpen中得到的是TaggedObject对象,这两个是需要进行转换的.本文主要知识点为:TaggedObject->tag_t() , NXOpen::NXObjectManager::Get(BodyTag1) , feature1->JournalIdentifier()的用法. 2 3 NX11+VS2013 4 5 #include <u