|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
UG NX二次开发源码分享: Teamcenter集成NX Manager开发函数常见的使用方法如下,不外乎就是找文件,找文件夹,创建文件,查询等操作。& @: N; V; m4 _0 W# u" A
4 }' d! M9 l" [" b9 n. p4 G+ ^
[mw_shl_code=c,true]
5 T- X6 x- m" e1 T( J( O6 g#include <stdio.h>
- g+ s) E/ U! K) b/ }9 E#include <stdlib.h>4 @/ T& Z9 W6 Y* w. H
#include <string.h>2 s, K: U& F5 A3 I
#include <uf.h>
: w) t6 L J" Q6 _( Y#include <uf_ugmgr.h>
1 ~: ?/ v7 c: o `#include <uf_part.h>. ^/ N2 I% h7 J7 c. @: `1 m# X
#include <uf_assem.h>0 _: H# A" z) }) N1 J) J- X
#define CHECK( func_ ) \6 S" a' p) p6 {/ @. W* P
{ int ifail_ = 0; \; @" [4 D: _, x) m
char message[133]; \
0 j) F. W9 M( ] O ifail_ = (func_); , e# ]+ X. j2 H/ X( J. w6 _
if ( ifail_ != 0 ) { \
1 ?' [, L. U! ^5 l4 M UF_get_fail_message( ifail_, message ); \
/ b0 c+ E. n/ c; z/ \$ P printf("ERROR: %s returned from %s\n", message, # func_); \7 A1 `% u# J2 M
return ifail_; } }
/ D$ z1 M$ |! ~5 Astatic int create_part( void );
/ M- C. G" j4 y1 Z) k' g) Fstatic int print_work_part_info( void );) G4 K; @) O$ t4 m m6 o; V
/*---------------------------------------------------------------*/0 J6 {" r+ `, `4 V% E( H. c* \
int main(int argc, char *argv[])) l% S) z& ]0 G
{
2 {9 r* D+ Q+ m, v5 }2 V int ifail = 0;
" D9 J; S* b5 T7 Z. ?# l1 d5 K2 V ifail = UF_UGMGR_initialize(argc,(const char**)argv);
; |1 [$ y% ^) G/ V' p \ if (ifail != 0)
7 H- B0 k8 a' b2 ?4 c# H% W" o {
) }# t: Y3 m- I printf("ERROR: Failed to initialize with error code %d", ifail);" |" p4 ]2 V) s; A2 c+ F
exit(1);
7 \. Y# U7 r9 I }2 ~" Q- g+ O0 ^ F3 }9 F1 [1 [
create_part();, z1 ^2 r7 K# A$ x! o7 X. G6 ]
print_work_part_info();4 h6 y8 s" R# C0 x, Z& S4 a* k
UF_PART_close_all();/ O# I7 u! i1 H( O8 Q* P
UF_UGMGR_terminate();
& m1 N- g. C8 F; d8 W) p* [' W6 Y4 C return 0;
0 _( x' H6 Z1 h# Q" m5 i9 r; {}
" r% @! e, J8 [0 r! X+ R/*---------------------------------------------------------------*/
- P# ^* ^, c: R; a- `7 v4 \static int create_part( void )
7 l0 n4 u7 i3 c# B( w{1 P3 v& b! Y1 P0 r2 }
char* part_number = "600-A-wej-mk1-eng";
$ C; x# a+ ~/ X3 A( n' X char* part_revision = "A";/ [9 C: T7 Q' V4 {8 `+ j+ f
char* part_file_type = "master";) |% k5 P7 y/ R7 p, R
char* part_file_name = "";
' j0 b( v7 H; a' u char encoded_name[MAX_FSPEC_SIZE + 1];
: P- Q. I$ E# D2 ?* |5 n tag_t part_tag;% g3 m. r8 d* ?# E0 Z. P9 A6 j
UF_UGMGR_tag_t db_part_tag;. o. U/ e U2 W M' \
UF_UGMGR_tag_t root_folder;
( p9 v' F9 O6 ]. j) t9 i! _ char root_folder_name[UF_UGMGR_NAME_SIZE];- [# z0 j) J0 f5 M) B
int i, count;
: R4 K8 _3 s% p! Z. m UF_UGMGR_tag_t *folder_contents;
. r# ^& o; ~9 t4 F2 Z r/ H2 ? UF_UGMGR_object_type_t object_type;& }2 T& A7 f0 {
char folder_name[UF_UGMGR_NAME_SIZE];( I/ T, z% y; u9 w
logical folder_exists = false;' n" X# c8 R4 [. T# D; E( ]
CHECK(UF_UGMGR_ask_root_folder(&root_folder));. t" K+ K$ W' P1 G8 h" V
CHECK(UF_UGMGR_ask_folder_name(root_folder, root_folder_name));
5 }& u+ y0 X! p printf("Root folder is %s\n", root_folder_name);* `1 f- p h9 I* I2 }1 b J7 [( r ]
/* Scan through the root folder, looking for a folder called/ f+ L" k/ J/ G; ~$ n4 ]
"Test Set Default Folder". If this folder exists, set it to be
/ z8 j! R' b# \( R. z7 H3 d the default folder into which newly created parts are* [! Y. {1 b( E/ l0 @( r; u; U
placed.# o: o6 |6 V: w: [9 }
*/! F/ i- \0 Z0 ~5 g+ [0 u! a
CHECK(UF_UGMGR_list_folder_contents(root_folder, &count, &folder_contents));7 S$ |3 W! a* Q W
for ( i=0; i<count; i++ ): r. @* y8 s; P, f6 j
{
) d E9 J( q# x5 J! J% ] CHECK(UF_UGMGR_ask_object_type(folder_contents,& d4 Y# R6 A0 q0 a' f# r, |
&object_type));! z4 g1 i$ e. W \" x5 Q
if (object_type == UF_UGMGR_type_folder)
! v& i6 ^) j- U4 W% f6 o {
1 G+ M4 S& C' u/ l; _& J CHECK(UF_UGMGR_ask_folder_name(folder_contents, folder_name));" p. Z4 f" n! j" w- W4 W
if ( strcmp( folder_name, "Test Set Default Folder" ) == 0 )
1 v" s2 A5 E7 }& v# Q4 T2 G {
( Q! a& l3 j8 T1 d4 s# ^) c1 \% ~/ y! b printf("Test Set Default Folder exists\n");& X( n& v+ a' N: n9 q1 l
CHECK(UF_UGMGR_set_default_folder(folder_contents));
7 u ]- ^" A* {: K6 E folder_exists = true;
0 \$ s! ]4 m3 c" [( f6 g) x: K+ @ printf("Set default folder to %s\n", folder_name);0 w- X* r5 b" i. ^% V3 `) |
}4 g: e+ F3 ~, i: g( Q
}
: G& ?9 H2 d2 R. w4 B. X }
' m0 G) T/ Z! K0 ^. k* y /* If the folder "Test Set Default Folder" doesn't exist, set the
9 Y" \: x* q3 P7 t8 z default folder to be the root folder.% D+ N& p# ?% E8 U/ L4 c
*/
8 o2 Q" N- |0 i- S# [% M( y if (!folder_exists)" x( j* M9 }+ P+ Q/ B# b
{: f; ^. W S4 q% V* `0 g
printf("Test Set Default Folder does not exist\n");
3 E3 F8 W; I6 ? CHECK(UF_UGMGR_set_default_folder(root_folder));+ V, }, B" X1 X) h1 \$ {& K0 o
printf("Set default folder to %s\n", root_folder_name);* C' C" `, Y) t3 W/ G6 L
}
- L8 @9 y7 i! ]/ e$ I" u printf("Encoding UG/Manager part filename...\n");5 g! b* ?& ^. ~, z1 o/ G
CHECK(UF_UGMGR_encode_part_filename( part_number, part_revision,5 w2 e, h8 o! r0 D, ?! `- Z
part_file_type,
$ Y* `/ r, S* d% ~. D. s part_file_name,
% c( o5 h* r9 U" |4 c4 ] encoded_name ));
8 s2 b+ Y, B+ `) C1 ^ CHECK(UF_PART_new( encoded_name, 1, &part_tag ));
, i% h2 W) s9 b& E8 \ printf("Created part...\n");
. t1 L* F/ C, C$ u9 }6 ` CHECK(UF_PART_save());
/ V- e% n& x. {5 K& [ printf("Saved part...\n");
0 t/ A; u8 H- s* J* e CHECK(UF_UGMGR_ask_part_tag( part_number, &db_part_tag ));
1 M* h( V8 g& l. e. ^3 A CHECK(UF_UGMGR_set_part_name_desc( db_part_tag, "engine"," c7 g. { \2 L* K' J5 R8 g
"Mk3 Engine" ));, ?6 s8 y: j# ^$ a7 h& @
printf("Set part name and description...\n");9 V: s! ]6 v4 J* Z! I3 f
return 0;# D8 X* q9 \/ z
}# F( B4 C* ?- h9 o" L% R
/*---------------------------------------------------------------*/& E7 m# c- n ~- P, y
static int print_work_part_info( void )" y: V& i$ {6 N
{5 A" M2 N* T* N5 }5 }5 [* {2 L
char work_part_name[MAX_FSPEC_SIZE+1];4 T, ~2 f' X& b$ t% z* b# ^
tag_t work_part_tag;! N( K* g: m* w, `
char part_number[UF_UGMGR_PARTNO_SIZE+1];
3 @ x! j) G% z, E char part_revision[UF_UGMGR_PARTREV_SIZE+1]; o; }! [* a5 ^3 |7 S$ ?
char part_file_type[UF_UGMGR_FTYPE_SIZE+1];( @# F5 E( l' [6 s! ^: ~1 g
char part_file_name[UF_UGMGR_FNAME_SIZE+1];
9 f' f, N% ?6 Y- d- S: S* Q h UF_UGMGR_tag_t db_tag;
' X, z0 ?4 k4 r; k- O char part_name[UF_UGMGR_NAME_SIZE+1];& F0 P M' E6 C' p4 Z4 ~" H9 ]
char part_desc[UF_UGMGR_DESC_SIZE+1];
" ]5 L3 o8 ?7 m/ i) [4 g9 U work_part_tag = UF_ASSEM_ask_work_part(); t; }8 Y2 { C7 g- I2 g
UF_PART_ask_part_name( work_part_tag, work_part_name );9 h1 s& Z; J! p
CHECK(UF_UGMGR_decode_part_filename( work_part_name,
( t6 z$ q: n# ~+ f+ x% P% ~ part_number,2 V8 t4 E% v. ~" w0 G7 M f
part_revision,
% I7 n1 C* G1 E! \+ { part_file_type,
. ^% a; n! i+ K, L4 T part_file_name ));9 Y! j! S- c' p4 S. h
printf( "For the current Work Part\n\n" );
5 v5 \' m2 M. j, ~ printf( " Part Number : %s\n", part_number );
/ V5 S+ J8 V8 s! @ printf( " Part Revision : %s\n", part_revision );
# l$ M+ G6 P; U8 s' h printf( " Part File Type : %s\n", part_file_type );
) S) k, J6 ?- p/ l, b2 _ printf( " Part File Name : %s\n", part_file_name );% |, t4 n3 k1 P- X
CHECK(UF_UGMGR_ask_part_tag( part_number, &db_tag ));( B, v- I; N: Y. f& X8 ^
CHECK(UF_UGMGR_ask_part_name_desc( db_tag, part_name, part_desc ));/ E+ f7 c2 N7 I0 g' _3 i7 w; T
printf( " Part Name : %s\n", part_name );
$ F) e5 \" l9 G+ r7 J printf( " Part Description : %s\n", part_desc );1 c2 I- z8 P t+ m
return 0;6 C$ d; l ]) E2 I1 a
}[/mw_shl_code]% d. F2 l8 `1 q" j7 g
|
|