|
Tag到NXObject的转换+ _3 K& X0 g& e" t K
# W F# T9 P6 R1 _% \5 f8 j
6 t$ x6 m9 @* T( E- w# n0 ^ufun 里的Tag 转换成 NXOpen 里的实体对象
M5 m4 G& K( L m5 r
7 T0 f) r9 ?8 H! ^# a9 R# k0 J0 GC+++ k; c. S5 T% c3 M) k
+ p8 Q. F" W2 |4 H& v- C. m
8 A2 i! D2 \- ]5 G7 D
tag_t obj=NULL_TAG;2 M' \, \9 ^& I: A0 B
" u: s) L- m: h
Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(obj)));
) H, Q9 c, p# b% |, e2 J. w5 B" Z/ i
Assemblies::Component *component1=(Assemblies::Component *)NXObjectManager::Get(obj);
R$ r& z5 B0 A8 R& J/ w" q. u; v& F
0 a7 ]. d5 F* f- ^/ G) ?2 q1 v3 j' O* n' P, Q- Y6 z
6 x! W% ^* m, t1 |' j: |0 O- c Y
F, b* Y: |; ]
=====================================================================' n( `& U \" p! K( |
3 ^% U7 c2 `( r- F/ o& B
C#
: W5 R$ u/ v+ m8 v# a" g /// <summary>
- ?! n; t" N4 z8 W# ?* S /// Tag到NXObject的转换
2 R0 l5 T; x/ j /// </summary>3 R! M8 S0 c9 q/ R4 f) u, n9 E) N+ b
/// <typeparam name="T">NXObject的类型</typeparam>; B. C" H T# z+ F
/// <param name="tag">tag号</param>
- D% N& M3 U1 M4 z/ w+ l /// <returns>NXObject</returns>
) a$ J3 c( e0 N! d public T Tag2NXObject<T>(Tag tag)/ {2 s5 Y% b9 F
{
* l$ a8 i7 m$ O% x6 x! U! \# X try
& h( P( F% {- Q/ r4 F1 U {) m1 j4 _. B" k- a- e3 P. Q
object to = NXOpen.Utilities.NXObjectManager.Get(tag);
* ^& i$ I( X+ C( p4 l return (T)to;
$ N+ R3 |( c, P7 [* X }! P- m, Q3 k5 m; A) T0 }. I
catch (System.Exception ex)
* Q+ d8 v- Q9 E- R {7 C3 z. k% b l0 P
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);" i+ O2 q3 v: `8 A5 W4 p
return default(T);' B& E o; l& I% E6 j
}
" z- y) Q# Q( ^8 b9 L }
$ q1 n- @. _! Q2 Q; B8 C t5 h; |9 ~! D i7 l
( O1 j2 \. C( O$ Y% N4 ]
|
|