Перебор компонентов и частей файла сборки (*.prt)


Добавил:DMT
Дата создания:5 апреля 2008, 20:39
Дата обновления:5 апреля 2008, 20:55
Просмотров:6048 последний сегодня, 1:48
Комментариев: 0

Исходники для Unigraphics NX перебор компонентов и частей сборки

Исходники для Unigraphics. В качестве параметра принимает имя файла сборки - *.prt, открывает этот файл и перебирает все части сборки и их компоненты. Результат перебора выводится на консоль, можете перенаправить в файл.
Код на C++
  1. /* Include files */
  2. #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
  3. # include <strstream>
  4. # include <iostream>
  5. using std::ostrstream;
  6. using std::endl;
  7. using std::ends;
  8. using std::cerr;
  9. #else
  10. # include <strstream.h>
  11. # include <iostream.h>
  12. #endif
  13. #include <uf_ui.h>
  14. #include <uf.h>
  15. #include <uf_part.h>
  16. #include <uf_assem.h>
  17. #include <stdio.h>
  18. #include <conio.h>
  19. #include <uf_assem.h>
  20. #include <uf_cfi.h>
  21. #include <uf_obj.h>
  22. #include <uf_object_types.h>
  23. #include <uf_view.h>
  24.  
  25. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
  26.  
  27. // VARS
  28. tag_t part_tag=NULL_TAG;
  29.  
  30. static int report_error( char *file, int line, char *call, int irc)
  31. {
  32. if (irc) {
  33. char err[133],
  34. msg[133];
  35. sprintf(msg, "*** ERROR code %d at line %d in %s:\n",
  36. irc, line, file);
  37. UF_get_fail_message(irc, err);
  38. printf(msg);
  39. UF_print_syslog(msg, FALSE);
  40. UF_print_syslog(err, FALSE);
  41. UF_print_syslog("\n", FALSE);
  42. UF_print_syslog(call, FALSE);
  43. UF_print_syslog(";\n", FALSE);
  44. }
  45.  
  46. return(irc);
  47. }
  48.  
  49. int cycle_obj_in_part(tag_t cur_part,char *rz=NULL){
  50. tag_t next_tag=NULL_TAG;
  51. tag_t *ch_components = NULL;
  52. tag_t parent;
  53. char p_name[MAX_FSPEC_SIZE+1];
  54. char rzl[MAX_FSPEC_SIZE+1];
  55. char r_name[MAX_ENTITY_NAME_SIZE+1];
  56. char c_name[UF_CFI_MAX_FILE_NAME_SIZE];
  57. char local_indentation[256];
  58. double origin[3];
  59. double csys_matrix[9];
  60. double transform[4][4];
  61. int ifail,c_count,cnt_obj=0,cnt_comps=0;
  62.  
  63. char view_name[UF_OBJ_NAME_LEN + 1];
  64. int view_dep,type,subtype;
  65.  
  66. if (cur_part == NULL_TAG) return 0;
  67.  
  68. ifail = UF_ASSEM_ask_component_data(cur_part,p_name,r_name,
  69. c_name,origin,csys_matrix,
  70. transform);
  71. UF_CALL(ifail);
  72. if (ifail != 0) return ifail;
  73. strcpy(rzl, rz);
  74. printf("%sPart: %s\tRefset: %s\tInstance: %s",rzl,p_name,r_name,c_name);
  75.  
  76. strcat(rzl,"\t");
  77. //UF_OBJ_cycle_objs_in_part(cur_part,UF_component_type,&next_tag);
  78.  
  79. c_count = UF_ASSEM_ask_part_occ_children(cur_part,&ch_components);
  80.  
  81. ifail = UF_ASSEM_cycle_objs_in_comp(cur_part, &next_tag);
  82. UF_CALL(ifail);
  83. if (ifail != 0) return ifail;
  84. while (next_tag != NULL_TAG)
  85. {
  86. ifail = UF_ASSEM_ask_parent_component(next_tag, &parent);
  87. UF_CALL(ifail);
  88. if ((parent != cur_part) || (ifail != 0))
  89. {
  90. printf("ERROR: Wrong parent %u for member %u\n",parent, next_tag);
  91. return 1;
  92. }
  93. UF_OBJ_ask_type_and_subtype(next_tag, &type, &subtype );
  94. if (type==UF_component_type) cnt_comps++;
  95. cnt_obj++;
  96. ifail = UF_ASSEM_cycle_objs_in_comp(cur_part, &next_tag);
  97. UF_CALL(ifail);
  98. if (ifail != 0) return ifail;
  99.  
  100. }
  101.  
  102. printf("\tComps: %d\tObjs: %d\n",cnt_comps,cnt_obj);
  103. b52
  104.  
  105.  
  106. ifail = UF_ASSEM_cycle_objs_in_comp(cur_part, &next_tag);
  107. UF_CALL(ifail);
  108. if (ifail != 0) return ifail;
  109. while (next_tag != NULL_TAG)
  110. {
  111. ifail = UF_ASSEM_ask_parent_component(next_tag, &parent);
  112. UF_CALL(ifail);
  113. if ((parent != cur_part) || (ifail != 0))
  114. {
  115. printf("ERROR: Wrong parent %u for member %u\n",parent, next_tag);
  116. return 1;
  117. }
  118. UF_OBJ_ask_type_and_subtype(next_tag, &type, &subtype );
  119.  
  120. ifail = uc6409( next_tag, &view_dep, view_name );
  121. printf("%s%u\t%u\t%u\t",rzl, next_tag, type, subtype);
  122. if ( view_dep == 0 )
  123. printf("Model Views");
  124. else
  125. printf(view_name);
  126.  
  127.  
  128. printf("\n");
  129. ifail = UF_ASSEM_cycle_objs_in_comp(cur_part, &next_tag);
  130. UF_CALL(ifail);
  131. if (ifail != 0) return ifail;
  132. cnt_obj++;
  133. }
  134.  
  135. for (int i=0; i<c_count; i++)
  136. {
  137. ifail = cycle_obj_in_part(ch_components[i], rzl);
  138. }
  139.  
  140. return 0;
  141. }
  142.  
  143. int open_part_file(char *part_name)
  144. {
  145. logical unused;
  146. int err;
  147. UF_PART_load_status_t load_status;
  148. UF_CALL(UF_PART_open( part_name, &part_tag, &load_status ));
  149. return(load_status.failed);
  150. }
  151.  
  152.  
  153. /* Main routine */
  154. extern void main( char argc, char *argv[] )
  155. {
  156. tag_t main_part;
  157. char rz[MAX_FSPEC_SIZE+1],part_fspec[MAX_FSPEC_SIZE+1];
  158. if( UF_CALL(UF_initialize()))
  159. {
  160. /* Failed to initialize */
  161. return;
  162. }
  163. if (argc>1){
  164. if (open_part_file(argv[1])){
  165. printf("Error open part");
  166. return;
  167. }
  168. rz[0]=0;
  169. main_part = UF_ASSEM_ask_root_part_occ(part_tag);
  170. if (main_part != NULL_TAG)
  171. {
  172. cycle_obj_in_part(main_part,rz);
  173. }
  174. } else printf("Count of param = 0");
  175. UF_CALL(UF_terminate());
  176. }
  177. /*****************************************************************************
  178. ** Utilities
  179. *****************************************************************************/
При использовании обязательна ссылка на http://DMTSoft.ru
Код на Text
  1. Part: E:\UG\den tests\practic 2\sborka.prt Refset: None Instance: Comps: 2 Objs: 2
  2. 9565 63 1
  3. 9578 63 1
  4. Part: E:\UG\den tests\practic 2\shaiba.prt Refset: MODEL Instance: SHAIBA1 Comps: 0 Objs: 9
  5. 10456 70 2 Model Views
  6. 10461 70 2 Model Views
  7. 10459 70 3 Model Views
  8. 10458 70 2 Model Views
  9. 10463 70 3 Model Views
  10. 10460 70 3 Model Views
  11. 10464 70 0 Model Views
  12. 10457 70 2 Model Views
  13. 10462 70 3 Model Views
  14. Part: E:\UG\den tests\practic 2\bolt.prt Refset: MODEL Instance: BOLT1 Comps: 0 Objs: 12
  15. 10466 70 3 Model Views
  16. 10468 70 2 Model Views
  17. 10473 70 2 Model Views
  18. 9597 70 0 Model Views
  19. 10475 70 3 Model Views
  20. 10470 70 3 Model Views
  21. 10467 70 2 Model Views
  22. 10471 70 0 Model Views
  23. 10469 70 2 Model Views
  24. 10474 70 2 Model Views
  25. 9596 70 2 Model Views
  26. 10472 70 3 Model Views
При использовании обязательна ссылка на http://DMTSoft.ru
up