|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数常见的使用方法如下,不外乎就是找文件,找文件夹,创建文件,查询等操作。) U8 @$ I3 b: d
$ ^( i1 d! Y( f, p( f[mw_shl_code=c,true]
; _5 {2 g, N' x+ m$ Z7 `' T#include <stdio.h>& P6 F6 g9 W+ D' }
#include <stdlib.h>
) M2 v4 [, Z1 p& ?#include <string.h>& a! @6 O2 f6 \* A
#include <uf.h>* r3 U' i0 A$ {) @9 x6 [- I0 h5 d
#include <uf_ugmgr.h>
0 B z6 @6 b: H4 Y0 g# Y* g#include <uf_part.h>
: k- m1 u9 i4 z4 t8 k" N, V#include <uf_assem.h>% j% _, v9 \5 w4 w7 W
#define CHECK( func_ ) \6 u, I0 d, q( V6 f4 u: t5 r
{ int ifail_ = 0; \
7 B+ U2 Q {2 ^/ T! E8 r* k char message[133]; \% [; |9 |6 q. L0 T P
ifail_ = (func_); 6 N% y2 R, J; t" h
if ( ifail_ != 0 ) { \
5 u" Q6 R5 ^% W; Y# g8 `( a G UF_get_fail_message( ifail_, message ); \; {! n) R6 `* N
printf("ERROR: %s returned from %s\n", message, # func_); \$ s; x; H; {( z9 r) ^/ \+ ?2 A2 c% Y
return ifail_; } }
$ C( J8 Z3 m5 t; j$ c" n/ @static int create_part( void );
6 X7 V8 P& \3 O) k' I: bstatic int print_work_part_info( void );. r0 r/ w9 ]' L! j
/*---------------------------------------------------------------*/0 w, K- S( B8 |7 a1 h& m. T
int main(int argc, char *argv[])
0 o6 a2 {1 o/ O! ]$ u{
7 I$ ~9 p4 E( ~6 o$ q int ifail = 0;
$ t( T/ Y2 Q1 w. S- l8 @" v ifail = UF_UGMGR_initialize(argc,(const char**)argv);6 h- W' F4 E; u& j. ~$ S% D9 C
if (ifail != 0)
" h( b) N1 [# s! t {/ m: P, D1 ~4 K
printf("ERROR: Failed to initialize with error code %d", ifail);) v ?! a V4 Y7 B3 `' z
exit(1);
% U6 g2 C9 w! g9 O3 o' W }* m$ N, l' g% {2 u, g, y
create_part();6 \( ?8 v% w5 w- q1 |
print_work_part_info();
, X: I( z# H( p; W1 x$ a UF_PART_close_all();
$ o. k4 u6 K2 ` V UF_UGMGR_terminate();
5 I! f8 U6 a* A" T0 j! W return 0;
9 W/ z6 l* |8 m# |0 c}
% n5 G' i7 X+ O& k/*---------------------------------------------------------------*/
) p" p h9 h; L- x) m0 b0 Cstatic int create_part( void )
# o8 k; e4 ~0 _9 n! z% o1 H{
; T/ L' H* }' y0 A- S7 g3 ] char* part_number = "600-A-wej-mk1-eng";1 ~, Z1 Z [% y" T& t
char* part_revision = "A";- F6 z' M' _0 g7 B5 \, M8 v
char* part_file_type = "master";( ^" u1 |6 L4 t7 K
char* part_file_name = "";6 {0 w# Q2 v* V1 l' p
char encoded_name[MAX_FSPEC_SIZE + 1];
& I- {( u ^" @7 ? tag_t part_tag;
/ J0 E( s! z0 l% i0 H2 _; H4 D& ^4 X UF_UGMGR_tag_t db_part_tag;
' R* ?8 x0 K0 n% P5 g UF_UGMGR_tag_t root_folder;
# @ H' s) I- j/ z, h# Y char root_folder_name[UF_UGMGR_NAME_SIZE];
$ ]% T; ^5 G( P8 B. N int i, count;
$ [+ N( I7 B. O; e4 E UF_UGMGR_tag_t *folder_contents;7 J. X a% d; k) I2 I% w1 ?
UF_UGMGR_object_type_t object_type;
l' Q2 M: ^8 E2 |+ u1 g char folder_name[UF_UGMGR_NAME_SIZE];
r! _+ \5 G* {# K2 v logical folder_exists = false;
9 i( V9 ]. J1 J7 J& f6 c" o5 f CHECK(UF_UGMGR_ask_root_folder(&root_folder));, e; `9 J3 L0 ?1 ~8 Z
CHECK(UF_UGMGR_ask_folder_name(root_folder, root_folder_name));
6 j x" k( m, d3 ~4 |2 Q printf("Root folder is %s\n", root_folder_name);
, v( a2 S& O7 }# _; w h" N6 ~: f; f /* Scan through the root folder, looking for a folder called
Y$ L' f6 G: J8 x0 L% I "Test Set Default Folder". If this folder exists, set it to be- e4 V0 X9 c1 z1 y" W q" G
the default folder into which newly created parts are3 i0 p' W. s. ?6 w; B; u0 @
placed.
( J9 \. p# M7 I& U */
( |& a+ ?& e3 x- R& }1 T, w CHECK(UF_UGMGR_list_folder_contents(root_folder, &count, &folder_contents));
9 X7 E0 m( U' X( n% q, ]& n' O( S for ( i=0; i<count; i++ )+ Q9 o. n: Z- ?' x4 w' |' d2 O
{
/ F( s. {, a) P. i# n CHECK(UF_UGMGR_ask_object_type(folder_contents,
4 \8 Q# i. [' F% n" f% Z& I+ z &object_type));# ^) ^$ `0 m j; V
if (object_type == UF_UGMGR_type_folder)% j" R. v* Z" c8 W& A% ~
{
; \3 B2 b& p2 W7 K1 u/ z; ? CHECK(UF_UGMGR_ask_folder_name(folder_contents, folder_name));6 w/ K, `; }0 @; }
if ( strcmp( folder_name, "Test Set Default Folder" ) == 0 )
) P; E' R6 D' K2 o0 @ {
% L$ J6 Q' g3 j4 m printf("Test Set Default Folder exists\n");
0 s) B3 z1 V% Q7 v' u: G CHECK(UF_UGMGR_set_default_folder(folder_contents));
" b2 u5 D) f/ g. p folder_exists = true;
0 H) c6 s' t- Z# K) V printf("Set default folder to %s\n", folder_name);/ Q1 M6 v* m7 B1 r
}
1 ~' u: _0 v3 d9 W* L }
1 P# t7 ?% }" M/ | }
- ?( V0 g3 i# E% n5 U /* If the folder "Test Set Default Folder" doesn't exist, set the
5 a! p) `0 @8 E! Y9 k! ` default folder to be the root folder.
$ G. x0 g3 n) q4 P */
" H" [2 s3 ^2 c/ j# W/ E& j if (!folder_exists)
) _) i9 s [+ d' g7 _1 ` {# k9 Z1 X0 r0 m6 W q* q
printf("Test Set Default Folder does not exist\n");9 r. k0 |( y/ _9 z0 ?
CHECK(UF_UGMGR_set_default_folder(root_folder));
/ {: O4 R- i# C( h* O2 a0 i printf("Set default folder to %s\n", root_folder_name);
6 D+ f' Z7 f4 t$ d% G2 B8 O1 R: j }
" L8 l& ]5 x( f9 w+ C printf("Encoding UG/Manager part filename...\n");7 d6 @$ ?4 S9 J" @! ]7 g
CHECK(UF_UGMGR_encode_part_filename( part_number, part_revision,9 ^& }1 I3 z) @+ ]5 u) k
part_file_type,
$ {/ ~, V3 \+ c7 r part_file_name,9 H3 H4 ^6 W" N2 U, ]1 z
encoded_name ));
* ]% I2 b& q2 h; U" K CHECK(UF_PART_new( encoded_name, 1, &part_tag ));
/ {3 ^( e- a& M5 @0 n printf("Created part...\n");
, G. J8 ]7 B8 x0 `: V# j% A CHECK(UF_PART_save());8 ]! l9 C O3 @; @
printf("Saved part...\n");" {' X! i; t7 `
CHECK(UF_UGMGR_ask_part_tag( part_number, &db_part_tag ));
Z* b: e: g' d K CHECK(UF_UGMGR_set_part_name_desc( db_part_tag, "engine",
; M! D. T5 D/ z4 B+ w"Mk3 Engine" ));+ ~9 m& M% Q+ h
printf("Set part name and description...\n"); t+ K* `: i" R+ A
return 0;8 |, K/ j5 j" p( z
}( s# \: R; U9 A. _
/*---------------------------------------------------------------*/) R# \4 |: k/ J. P @; N- C' f
static int print_work_part_info( void )
0 \2 U8 ]6 m& R* g% k6 I{( j! \3 ~2 R w/ s
char work_part_name[MAX_FSPEC_SIZE+1];
' Q% X/ J4 K( h" ~9 W$ k2 Z tag_t work_part_tag;2 ~# D/ \2 ^4 o
char part_number[UF_UGMGR_PARTNO_SIZE+1];
: j3 d1 ^# Y) t! q, b& c; k char part_revision[UF_UGMGR_PARTREV_SIZE+1];
! G4 _$ \1 F) @# m' u9 j# y char part_file_type[UF_UGMGR_FTYPE_SIZE+1];
9 @8 q# X/ e6 H9 K) a# D5 v char part_file_name[UF_UGMGR_FNAME_SIZE+1];
: `) r0 s( s6 Y5 \ UF_UGMGR_tag_t db_tag;. V0 N0 u* t7 r8 \+ q
char part_name[UF_UGMGR_NAME_SIZE+1];
3 ]0 c& n3 n2 V char part_desc[UF_UGMGR_DESC_SIZE+1];, L7 O# S5 B5 r3 |& l* l* @ `
work_part_tag = UF_ASSEM_ask_work_part();- K6 @8 O) S- S S7 H8 a, R
UF_PART_ask_part_name( work_part_tag, work_part_name );
8 ?6 {8 l3 J! B s$ [ CHECK(UF_UGMGR_decode_part_filename( work_part_name,$ W4 E0 Y) y! o1 a0 @, B, q+ o p
part_number,8 K& g% J( s- X- L$ s! Z5 _1 @
part_revision,& r# \: ]0 l( E+ v
part_file_type,
, X8 H; |0 m6 i4 T, e2 T part_file_name ));
% r) E4 C2 a% f$ r$ g9 {' X' R& A printf( "For the current Work Part\n\n" );5 v% t5 K9 Q% b
printf( " Part Number : %s\n", part_number );
% ~0 g) Z# I) D' y" H' D- \# p printf( " Part Revision : %s\n", part_revision );) B5 b, w0 S. F U2 D9 X8 @
printf( " Part File Type : %s\n", part_file_type );
+ @; C+ \% B& x5 v printf( " Part File Name : %s\n", part_file_name );$ J/ b, q- A2 J' [; k
CHECK(UF_UGMGR_ask_part_tag( part_number, &db_tag ));
6 ~4 t# `6 |6 r7 M% ` CHECK(UF_UGMGR_ask_part_name_desc( db_tag, part_name, part_desc ));
9 m5 J5 x' f9 B# g* P7 ?: e5 N4 {4 ] printf( " Part Name : %s\n", part_name );: E6 w, d7 n5 y5 x2 v2 w
printf( " Part Description : %s\n", part_desc );
9 |+ a% Z4 O7 k7 L8 O8 E return 0;0 J" M; [1 z* e4 P# _0 h
}[/mw_shl_code]
# v" g9 N0 {3 s |
|