|
Tag到NXObject的转换- D0 i( ]9 Y1 }& `3 s, s! A
$ k5 c/ D J' y! f4 n% {
3 Y; t1 o R3 v% y
ufun 里的Tag 转换成 NXOpen 里的实体对象
U) s3 l3 d7 k* r* |6 ]$ ?: K
: m S' O. A0 G! q/ vC++
: s8 W0 U9 m: h8 d- D( ]
; J" h/ h" T& h/ g
" Z' }; c3 }% N* j0 ttag_t obj=NULL_TAG;+ W' Z$ ^/ [3 q+ U. N0 @& N# S, ^
* H" C9 G- J7 Q; Q. ^& CBody *body1(dynamic_cast<Body *>(NXObjectManager::Get(obj)));. A+ X" u/ o. a3 I, r3 v8 \
" P2 _6 K. H2 O5 }
Assemblies::Component *component1=(Assemblies::Component *)NXObjectManager::Get(obj);% }* C& a6 j) j: N
& J2 f) @/ K7 F7 {! A! h) N+ K& }* t# B- C. |9 T2 y
) B( `5 c @! O. T3 z$ z c0 L/ W1 P8 O& F- W' @9 d( o6 l- ?$ e5 @- f
# P. w; b6 W5 m/ f! u% m2 K8 ?1 o=====================================================================
& n* ~/ Y' G$ j( s, t3 B3 ^2 N! z3 I; ]
C#6 S6 B) t. K5 B5 x
/// <summary>
) P3 y/ K' |9 } /// Tag到NXObject的转换7 G7 L2 q3 N/ [8 ^. x! `8 h3 E
/// </summary>9 {+ D' {0 Z6 C0 m7 [: M
/// <typeparam name="T">NXObject的类型</typeparam>
: @5 b7 ~, F6 F+ G2 G7 u3 | /// <param name="tag">tag号</param>7 Y- s. F; Q# _+ A
/// <returns>NXObject</returns>& Q* Y9 I+ k' i2 `6 q
public T Tag2NXObject<T>(Tag tag)2 Q z d8 b1 U8 G% ^; r
{) D7 e- L& r4 w+ |
try7 k* ^4 L. d C, o+ a+ o& z4 ]
{2 {5 B; I3 ]% ^5 Z8 a2 r9 X; W
object to = NXOpen.Utilities.NXObjectManager.Get(tag);" k) X* q) v' a5 l H% n
return (T)to;" u5 E+ f4 [( I) z( e8 B
}
! D7 X5 [ q# E9 ?0 G: g+ z catch (System.Exception ex), ~- _( C) x( q4 y! \+ I
{
+ k3 y: q) |# C) | b. k6 s UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
" N1 M! G5 m/ N* w* v& A return default(T);* J( q* M2 F1 d6 E. Z) \
}+ E }: _( e7 ^5 \# w
}
0 [- ~5 q0 I: R# `8 R$ Q
' p4 T" z u7 d' }4 m' d
: ^4 v& X* h1 I0 L6 w. s |
|