PLM之家PLMHome-工业软件与AI结合践行者

【Aras二次开发】通过Item查询关系Item信息

[复制链接]

2018-8-1 13:41:14 1841 0

admin 发表于 2018-8-1 13:41:14 |阅读模式

admin 楼主

2018-8-1 13:41:14

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
Technique    P; l! _* s  I
To query for an Item and retrieve its structure you build the query as the structure + N( q! `, ]5 p% {" w) M
you want returned.  Use the IOM methods to add the relationships you want and / A, F5 C4 }5 y1 m/ a
build the structure in the Item.  The server will return the structure that follows the
) H- f. {& q3 A2 H' Mrequest structure. : C8 L3 W2 C0 f" v  e; C7 V: r# v
This recipe illustrates several related concepts together, which are how to get a set
* S: \* }& ^% Q8 E' ~+ d9 Lof Items from an Item and how to iterate over the set, plus how to get the related ( w3 G# V9 v- c
Item from the relationship Item. " c5 m7 n1 z2 s5 q( H
JavaScript  , \6 s7 c4 Z. v* f6 a2 E
var innovator = this.newInnovator(); / w0 [$ t1 |# Z& P/ n) c( C

" d% ]; s+ \: H2 S// Set up the query Item.
% c2 ^6 m0 }- Z9 d. dvar qryItem = this.newItem("Part","get");
, R+ G, G% S3 C9 B4 ~' R# VqryItem.setAttribute("select","item_number,description,cost"); ' H1 ~# ]" l! b
qryItem.setID(myId);
& }/ D4 ^$ ^/ c, b
9 ?$ u$ Q' i* I, I( p// Add the BOM structure.
0 `" a8 `$ u7 [var bomItem = this.newItem("Part BOM","get");
( |% f2 Z9 i; d) [4 UbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
8 G4 m; M- J- NqryItem.addRelationship(bomItem); 3 c4 _" j6 Q& J& ~4 q0 w/ B
1 l. }$ O# J3 N3 v
// Perform the query. / }( }' H3 [  \# ~
var results = qryItem.apply(); / t. J7 Z, \6 b7 ^8 S6 e5 E3 S
$ r3 M8 ], V9 A
// Test for an error.
8 B- t* M0 @) [) D% _' sif (results.isError()) { 7 l' v6 B/ C6 S! T9 R. ?
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); * \9 O& y; V2 X* H( Q
  return;
. ~  o7 P) v) ?& d9 }' D' ]} # I  b  d: `8 b3 I3 \: K0 a7 d

% B* B$ Y( g! l2 S$ U; q// Get a handle to the BOM Items. ( G+ R: ]( M: t$ j6 w( g; g
var bomItems = results.getRelationships();
+ c0 I) p! a. d- m. ivar count = bomItems.getItemCount(); & N+ J% z' _  l  ~( p$ x
: d, d" l6 {! G0 v
// Create the results content.
7 Z) c7 O2 e6 S$ f4 O/ [4 @var content = "<table border='1'>" + 4 u, Q5 h# \' I6 I6 Z
  "<tr>" +
, `% y; i# u, {3 f8 n1 }$ H, Q    "<td>Part Number</td>" +
" q+ Z( r  l3 u  t, x5 V+ F    "<td>Description</td>" + 8 K# B9 u- o# ~) \2 u& U
    "<td>Cost</td>" + / P0 P% D( Y9 |1 t# e! j
    "<td>Quantity</td>" + 1 Y% Q- B, u0 e" r, |8 G
  "</tr>";
  |7 _- O' h- c! H, F6 Q2 l 1 j$ C3 F5 K& V5 F  \, D. T
// Iterate over the BOM Items.
+ e% J9 g$ Q! b  Efor (var i=0; i<count; ++i) : W/ Z" z% [3 Q3 A3 E* x9 D0 q
{
) e1 l8 F( ~9 W+ f  y7 u4 k: P; g// Get a handle to the relationship Item by index. * i7 E+ w8 S0 E$ p
  var bom = bomItems.getItemByIndex(i); ; p8 E/ Q- y8 F& P% {/ c) z
// Get a handle to the related Item for this relationship Item. . K6 h4 R6 i, z% q' g( ^! B
  var bomPart = bom.getRelatedItem(); 1 C4 c0 I- H* q  o
* k6 I% d2 H: H; f
  content += "<tr>" + 6 M3 p1 P, p; M* f/ x  E
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ o# P1 O1 k( o  \* ~      "<td>" + bomPart.getProperty("description") + "</td>" + 0 l- e, t& x+ }* r
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) ]3 b2 L/ M6 k- I5 K6 w: A9 x1 O
      "<td>" + bom.getProperty("quantity") + "</td>" +
( J0 E4 U8 M1 l" J( U    "</tr>";
) H/ |" B. W2 l5 u}
4 v% ?4 k/ [  F. w5 ~( d& s; creturn content + "</table>";: a. X6 _$ t  H

8 a6 \. [  F$ K6 N% T

: R0 l5 R7 Q; Q2 ~3 j7 p* e* l( l( N# B* j7 z. A, \

; m$ ]4 U& i4 y0 dC#  " H. P- t0 E- {
Innovator innovator = this.newInnovator();
5 l' T0 s- f& P0 T0 K' a  @ 8 P2 z- U4 e( Q6 c" R
// Set up the query Item.
+ q9 n6 ?" B; d; X" j+ lItem qryItem = this.newItem("Part","get");
. I$ _4 J9 M$ H$ F1 f* \5 N( bqryItem.setAttribute("select","item_number,description,cost");
1 z0 P& a5 F$ J  U4 ]qryItem.setID(myId);
  {0 D6 q6 U7 M" @) D * ?' o2 B* S; m4 e
// Add the BOM structure.
' `0 T2 p* j. \, E' a6 W/ L4 a) f+ fItem bomItem = this.newItem("Part BOM","get"); # E' Q2 {; [" G9 B: ^4 O
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
+ F8 q7 R" u' R! j+ n+ GqryItem.addRelationship(bomItem); # A5 a: t: g+ l  K  T

3 G6 P- E% X7 y4 K// Perform the query.
9 O6 n/ @, D3 U. zItem results = qryItem.apply();
$ P7 H- f/ ]/ b" W* x
6 S5 X; T: M1 ]: |, r; R3 x// Test for an error. # X/ e) M  \8 M9 V% T8 i; |4 P
if (results.isError()) { + ~, ?- _  ^8 s
  return innovator.newError("Item not found: " + results.getErrorDetail());
9 o) C4 [, \# B5 B+ r* k} . d& L+ B" w& \+ ]5 i- M0 _9 I
( S6 |0 |( Y8 V/ M4 d
// Get a handle to the BOM Items.
# P. H" F$ B2 I& `Item bomItems = results.getRelationships(); % |5 t  P9 L0 w: h  U- x
int count = bomItems.getItemCount(); : X. Z$ r0 _- g3 n( i
int i;
+ W$ Y3 n1 w9 {9 `5 b" ?0 R " q4 b7 R; L9 d5 b
// Create the results content.
$ b( F2 {4 f+ ^' P- bstring content = "<table border='1'>" + 9 p1 O) z/ C5 A8 y5 _, ]- |' {
  "<tr>" +
2 b% E; p6 I1 O" t1 J    "<td>Part Number</td>" +
/ P. a% J- ?* c" g& K; u' |; G% h    "<td>Description</td>" + - }3 t; p, v8 x, l, U% ?# }
    "<td>Cost</td>" +
& m! j/ J, _: @4 S    "<td>Quantity</td>" +
3 O6 }. h5 Z5 A! T$ T% }  "</tr>";
: j2 B9 u+ D/ J" b, T ( z- z% i, ]0 S' `# O
// Iterate over the BOM Items.
' [7 e# y3 Z+ \7 P; G3 s4 j& y6 J) Lfor (i=0; i<count; ++i) & J9 g( H" j9 ^  K5 L! n
{
2 H9 L! |" w  h% }0 R$ c// Get a handle to the relationship Item by index. ; W( X' n3 X2 T( T# A4 s
  Item bom = bomItems.getItemByIndex(i);
# h" G- l8 K7 J9 e1 g9 V// Get a handle to the related Item for this relationship Item. . w/ c# z+ G# O
  Item bomPart = bom.getRelatedItem();
2 W2 R1 m! F  i' j0 |; u * a- D# h& V/ D9 Z
  content += "" +
+ o2 q1 _( W3 p8 z5 ~, @1 `; G    "<tr>" +
9 l" ]% ]/ K3 M4 C7 j      "<td>" + bomPart.getProperty("item_number") + "</td>" + 1 E  Z9 `# I0 w+ v2 g3 F& l
      "<td>" + bomPart.getProperty("description") + "</td>" + 7 ?. m2 z' R& `; y; |* W4 e
      "<td>" + bomPart.getProperty("cost") + "</td>" + ! b, L2 ]% F* x1 Z7 b; `' v! `
      "<td>" + bom.getProperty("quantity") + "</td>" +
( j8 u' F' Q0 J    "</tr>";
1 i$ g  c* X! Y} $ Y' p0 I* {+ Z/ o& A. ]! |
content += "</table>";
* q' \6 E* E4 v2 k# ^  H) j5 Y
' A5 B8 D3 [# m+ ~return innovator.newResult(content);
$ O- j5 Q" `; j% |
2 Z4 R# ?( I/ K
7 u, w: t9 N; j4 T
) C3 c# L( p% A* H" x
( L9 T( X8 f8 f% A$ q; a
( N, _0 m$ O5 W! z  d

- J' w: M/ m1 F, _( c8 C - j2 J& o2 V4 K6 P
    Page 46
. s5 v7 c' Z5 q6 [0 D6 c, E
' Z5 j; O. b2 y8 r5 aCopyright   2007 % Z0 L5 c3 d0 D. M# P! Q/ C
Aras Corporation.  
; t9 h9 j1 s3 u9 IAll Rights Reserved. 5 ~2 \6 C  @# Y1 \3 v2 N. k
VB.Net  ' j" l. L2 Z) N: p+ u% O3 L4 E
Dim innovator As Innovator = Me.newInnovator()
9 J' @+ R% [( v5 ?8 g& \, F
/ ~( \! N2 p& ?5 u' Set up the query Item.
' i/ L# [$ R' i2 oDim qryItem As Item = Me.newItem("Part","get") 0 T5 `) ~5 ~- a( X- L" X- b
qryItem.setAttribute("select","item_number,description,cost")
8 N0 k1 ]- i* h7 NqryItem.setID(myId) - ~+ S" {$ a! F. P) Q/ E

& ?& U0 W& B, d2 ]4 Y' Add the BOM structure. . A  k( y& j) [8 V
Dim bomItem As Item = Me.newItem("Part BOM","get")
6 {6 f2 k6 ], ObomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 8 X- @2 V% D) B/ B  B: _- O: G
qryItem.addRelationship(bomItem) ! o( b! n9 F- L" }
3 t6 W$ X- P2 @2 ]0 X( ^/ ?' H
' Perform the query. " S& u, K) H2 X  S0 v9 L
Dim results As Item = qryItem.apply() $ r$ U4 z' ^% e8 [  i! v

" d4 ?1 _% s2 ?0 w6 _' Test for an error.
  c$ S, Q' f' f% K& e$ jIf results.isError() Then
0 {# t3 r7 G* n/ z! ^  Return innovator.newError(results.getErrorDetail()) 0 r4 F9 L& L% d
End If 0 d& X; `6 [# I# k- A" C3 x

% _2 R3 S" k( z- h- z) ]' Get a handle to the BOM Items. 5 r0 p7 D: Q' _# R
Dim bomItems As Item = results.getRelationships() . L0 i4 ^9 T9 D0 ?
Dim count As Integer = bomItems.getItemCount() ) v8 T$ r2 H( n/ K
Dim i As Integer
: s! n. S5 w7 _! N# J+ e) g# [
' O( J  i4 |9 v8 m) K" E' Create the results content.
) W6 g$ @0 ]# v& Z3 z# KDim content As String = "<table border='1'>" + _
/ w* j5 Q/ p% w' J& t  h6 a  "<tr>" + _
) A+ O- M" g! h    "<td>Part Number</td>" + _
. z3 ^; ~% \% h& y) p0 q1 R    "<td>Description</td>" + _
- d0 i/ J% x. \2 v( q3 C    "<td>Cost</td>" + _
6 ^. @& A6 P: v. m7 M0 }% v    "<td>Quantity</td>" + _
# M: w' h3 y- B* t! z; j7 v8 }  "</tr>" . A9 g- O8 d) K! G: k' Q

! Z; U! b$ O& U* o; F' Iterate over the BOM Items
. K9 y9 W3 i: o) F7 R& bFor i = 0 To count - 1 # u* C4 _$ q9 x5 x
' Get a handle to the relationship Item by index. : g' R; p* W) @2 c6 t2 l
  Dim bom As Item = bomItems.getItemByIndex(i)
! b! D6 Q3 [# P
6 w  Y8 o2 V4 l7 L* z# s, u$ ]' Get a handle to the related Item for this relationship Item. + Y+ P5 @2 c5 |  t+ p
  Dim bomPart As Item = bom.getRelatedItem()
  i* q5 r* R4 u: V 8 O9 u: Y7 h. Y+ d/ j) Q
  content += _ 8 J& v8 ?( i( ], d) r2 O: Z$ A
    "<tr>" + _ & v* A* S2 G8 @6 }9 j: a
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ T" P4 V8 t  h; n& }! ~) p      "<td>" + bomPart.getProperty("description") + "</td>" + _ & h+ d! Q3 C7 s3 f7 `! u/ T
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
: Y& a. q' z. [2 m, ~      "<td>" + bom.getProperty("quantity") + "</td>" + _ 3 q7 k* R2 }0 z4 x+ q( r( S/ |
    "</tr>"
% c7 Y/ W  @  ~  nNext
  X: k# ]6 u9 q. @5 Gcontent += "</table>" - U5 Z0 A" U1 d; n

5 r( a' R6 h, Z; W7 BReturn innovator.newResult(content) 5 q# a& w/ h5 t4 d/ F- c1 \% O6 r4 [
* l' o4 R4 e. Y6 Q5 L0 A! Q
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了