1 NX9+VS2012
2
3 #include <uf.h>
4 #include <uf_obj.h>
5 #include <uf_modl.h>
6 #include <uf_part.h>
7 #include <uf_std.h>
8 #include <NXOpen/Annotations.hxx>
9
10
11
12 UF_initialize();
13
14 std::vector<tag_t> SolidVector;
15 tag_t ObjectTag = NULL_TAG;
16 int Type, SubType, Body_Type;
17 char msg[256];
18 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
19 while (ObjectTag != NULL_TAG)
20 {
21 UF_OBJ_ask_type_and_subtype(ObjectTag, &Type, &SubType);
22 if (SubType == UF_solid_body_subtype)
23 {
24 UF_MODL_ask_body_type(ObjectTag, &Body_Type);
25 if (Body_Type == UF_MODL_SOLID_BODY)
26 {
27
28 //打开用于二进制输出的STL文件
29 void * file_handle = NULL;
30 UF_STD_open_binary_stl_file("D:\\abc.stl",true,"",&file_handle);
31
32 //将实体放入STL文件中
33 int num_errors;
34 UF_STD_stl_error_p_t error_info;
35 UF_STD_put_solid_in_stl_file(file_handle,NULL_TAG,ObjectTag,0,10000,0.0001,&num_errors,&error_info);
36
37 //关闭STL文件
38 UF_STD_close_stl_file(file_handle);
39
40
41 UF_OBJ_set_color(ObjectTag, 186);
42 SolidVector.push_back(ObjectTag);
43 }
44 }
45 UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_solid_type, &ObjectTag);
46 }
47
48 sprintf_s(msg, "当前有%d个实体", SolidVector.size());
49 UF_UI_open_listing_window();
50 UF_UI_write_listing_window(msg);
51
52
53 UF_terminate();

来源:oschina
链接:https://my.oschina.net/u/4389078/blog/4327408