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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
1 l0 Y, U0 C1 }& e4 \To query for an Item and retrieve its structure you build the query as the structure 9 }/ G; ?! }" d) u4 A& ^* ]& ]9 \
you want returned.  Use the IOM methods to add the relationships you want and
. n; e2 @- J9 jbuild the structure in the Item.  The server will return the structure that follows the
  }+ T. O$ l" rrequest structure.
2 w) u1 U7 W1 k) i, `7 S1 Y. [This recipe illustrates several related concepts together, which are how to get a set 1 m* H9 K- W5 K. ~. s7 w2 p) D  p
of Items from an Item and how to iterate over the set, plus how to get the related ' O- G8 e* H: Z! h
Item from the relationship Item. ; d4 `; I0 W8 l% a$ y
JavaScript  ; o5 r* q  ?  k. Q; K6 U; c
var innovator = this.newInnovator(); # J- l  J5 j, H. h2 V! x

0 e+ ]2 ~0 x3 j1 Y! n6 y/ O// Set up the query Item. & {* u: j6 @4 z( k3 V7 _# }/ L; S
var qryItem = this.newItem("Part","get"); 8 F6 l& t5 X9 L; K. G
qryItem.setAttribute("select","item_number,description,cost");
/ b. g8 e6 \- M% x0 MqryItem.setID(myId);
4 L" s7 \8 j+ b2 Z8 N. J  X. Q
' t" ?( t& D# h' w, e// Add the BOM structure.
$ q$ S/ ]& v( I! D8 f- bvar bomItem = this.newItem("Part BOM","get");
, s+ i7 w# d( t* [  |; c, C9 ]$ JbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 4 D( k8 O6 A% L/ C
qryItem.addRelationship(bomItem); % v4 N' k. Q8 M- z6 \. b9 l

# Q0 A8 j3 s& ~! F/ d// Perform the query.
" m, Y+ H. z. Y5 bvar results = qryItem.apply(); ( F5 t+ X- m; l3 [, X/ U

) ]. m. p! O, T2 m7 B2 J0 c7 G7 a// Test for an error.
5 F  w# \% J  ]6 e) @$ bif (results.isError()) {
+ g- O! M) Z: U, Y. r  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! A, \  g4 `3 W' ~" {# h
  return; 6 z, ~: Y, N5 _7 ]8 w; Z/ R) k
} : a# X$ t6 @( n+ ~0 r, _" ~

  B9 r7 D% r+ O// Get a handle to the BOM Items.
4 B6 P. \* Q+ G. a) F' X1 Pvar bomItems = results.getRelationships(); 5 ]& M$ A" L. R. ?9 \2 P( y
var count = bomItems.getItemCount(); ; ?$ e8 J3 f# u# t- X

. t5 l5 w7 }$ g1 X3 k$ k// Create the results content. . u' J# J# w/ ]9 t8 U0 o% Z& O; }( U
var content = "<table border='1'>" +
/ g+ G, q1 P+ I( o/ z" c4 M  "<tr>" +
' x, U1 {. E1 o5 U2 J0 P: l    "<td>Part Number</td>" +
4 i; P; F5 V- G) b$ P' @) x2 C3 w  V    "<td>Description</td>" + * z  |/ v4 n6 B
    "<td>Cost</td>" +
! q2 n" N" o& h. F    "<td>Quantity</td>" + , H# x# u% f, {2 v) p
  "</tr>";
, u2 x1 ]- v; h9 G2 q & I. W4 g1 |9 q/ t
// Iterate over the BOM Items. " G, s$ M2 q% D) }' |  k
for (var i=0; i<count; ++i)
3 k6 d  w# o1 ~7 @  L4 H4 n{
% n, S- o* K" C& _! A3 G// Get a handle to the relationship Item by index. 2 P& Z4 Q* S6 J$ f7 R
  var bom = bomItems.getItemByIndex(i);
: A2 t6 X5 ^" X" n// Get a handle to the related Item for this relationship Item.
! k$ m+ ^3 S) z0 C/ f6 o  var bomPart = bom.getRelatedItem();
" [5 i; Y# [% b5 P$ r
0 h0 Z; H0 J  a; q4 O7 a/ n  content += "<tr>" + ) y6 g& G4 ]. C' D5 ?" w
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 7 V7 ^" Z( m) F; f0 ]/ V
      "<td>" + bomPart.getProperty("description") + "</td>" +
, W! [  m" R8 o" l" j, G      "<td>" + bomPart.getProperty("cost") + "</td>" + ! c7 W! k, x7 I# y7 [
      "<td>" + bom.getProperty("quantity") + "</td>" +
0 b  _. n9 x% T  }0 N' J    "</tr>"; ' j$ F( V- @; G2 d9 i2 v
} % ?  ]$ y3 t% W6 S
return content + "</table>";: p4 m2 q9 a) N8 r4 n2 }

0 I" Z2 y/ J% E6 C

& q- v* [4 ?: d8 n: E% A4 r5 j! I: }7 G  }$ L

1 S: T" z4 }5 `* M" J6 T9 v3 Q! NC#  ' n* x, I6 O+ k3 }, |) W
Innovator innovator = this.newInnovator(); ' G! P- Z8 Y8 U# O: I7 l5 R9 v( u# n8 h
0 o# R" X' \2 V, y$ H
// Set up the query Item. 9 u( T9 W0 A$ ?
Item qryItem = this.newItem("Part","get"); 2 l2 t9 C+ \+ b0 d. M
qryItem.setAttribute("select","item_number,description,cost");
- c# d  x& G$ q; t" y4 v4 QqryItem.setID(myId); 2 k# N0 V6 U( P+ \8 V
0 o& T8 |  u% I6 |" Z
// Add the BOM structure.
8 y7 p0 O/ z7 M2 E1 tItem bomItem = this.newItem("Part BOM","get");
* Z8 f2 X+ {# u; v. u- |  xbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
4 I3 U& z  a' u) v# b) \qryItem.addRelationship(bomItem);
7 a- |, m- q1 e . D3 x1 O6 F; l5 m# u) q
// Perform the query. # m3 e7 O4 V: X( B8 B. t! p
Item results = qryItem.apply(); + o. F4 k; Q2 _( g. o9 B( E! ~4 O
# N8 c4 O6 H8 q( q& b
// Test for an error.
* d# f3 C  g, x( F9 zif (results.isError()) { 2 X8 d6 }9 x4 ~- y+ U
  return innovator.newError("Item not found: " + results.getErrorDetail()); / Q: b8 k# d1 I2 M
} 9 i9 `* Z& w, w1 e$ n7 v( K: b# H/ \

# ]+ c, j, Y* D6 ^1 W5 f- v4 a// Get a handle to the BOM Items. . I" D6 Y0 r- x7 m4 v9 P
Item bomItems = results.getRelationships(); # X9 l% `4 S# R) D: K
int count = bomItems.getItemCount();
. I( j& H- H5 f7 iint i;
4 z( n& r0 m: a, }; P1 S; Z! Y ) K0 \7 n1 d" a2 x9 W. O) h
// Create the results content.
# e% e& B# h8 O: E( mstring content = "<table border='1'>" + ' ^- q$ S& O! c; i7 J% O; k8 D- V
  "<tr>" +
0 P# }* |8 {/ S2 P9 e% |    "<td>Part Number</td>" +
( J4 w; f- K; l# o2 a% Q3 |- b% E    "<td>Description</td>" +
: l/ f" r0 J- G    "<td>Cost</td>" + 0 ]' C! o5 y$ V. z) b! r9 ]8 ~
    "<td>Quantity</td>" +
1 m- J' @  T# L$ q0 s  "</tr>"; " H* n* {  o, j; N! |

5 b: e8 e. ~7 T1 B// Iterate over the BOM Items. 4 D/ h2 z, F( }0 T
for (i=0; i<count; ++i) / h/ J6 F, z% ?  ]
{
; v5 o) ?* y' e% @0 l! x2 E! {// Get a handle to the relationship Item by index.
# C) |; `- o- ?  Item bom = bomItems.getItemByIndex(i); + ~7 Q$ P2 h/ G: u# W' ^
// Get a handle to the related Item for this relationship Item.
+ I* e4 r3 c$ g0 \, K  Item bomPart = bom.getRelatedItem();
% O* ~$ q6 I; j( ]6 B # {; p" L7 K: V0 k6 ^+ m
  content += "" + & {! h6 Z# i9 q) T
    "<tr>" + & Z7 h5 y4 e9 u" E0 _& V
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ K/ }0 U* d) R7 R      "<td>" + bomPart.getProperty("description") + "</td>" +   ~; ^/ t4 I3 ~
      "<td>" + bomPart.getProperty("cost") + "</td>" +
8 d: ~& V8 Q( s" t3 w( |      "<td>" + bom.getProperty("quantity") + "</td>" +
' ?! ~; Y  d  e% t    "</tr>"; : P" B0 ^" P: ^+ t* N5 H" \6 ]
} / J+ X' B. L$ R0 d: p5 G* H
content += "</table>"; # \0 H$ d! d6 o* o: l1 O+ D

* Z" O" K5 f! D( y7 jreturn innovator.newResult(content); 7 k0 S; _( `: X7 B

5 ?$ ]3 d% |6 E1 A6 ^1 v
0 E. T4 S, p1 N2 W4 a& e, A# }

6 E1 B2 \6 R; M7 H3 A
! ~) I8 g# U& ?2 ~- e
; M' C  r* k0 ?
9 h/ Q! v+ p/ m6 s+ C- J9 D

; G) ^: M/ V* \: F! c3 C    Page 46 - i( Q' D5 G8 @
& {8 y$ Q4 Z( N/ D% c5 ?$ E
Copyright   2007
' j2 Z, A1 @% t2 [2 wAras Corporation.  
% _4 B9 B3 n3 n/ ~All Rights Reserved. 6 e  M- y. W* n4 S/ h, r
VB.Net  * k9 G% }4 N$ `; f
Dim innovator As Innovator = Me.newInnovator()
+ [# W1 z- u! |* G- H& K, ?
- _. Q  C# ?2 t  n" r" {' Set up the query Item.
( d( n  G$ |" l! N& j9 i8 ^2 pDim qryItem As Item = Me.newItem("Part","get")
  N7 n% j/ Y9 q, s& T  x4 oqryItem.setAttribute("select","item_number,description,cost") $ N4 ?( w0 z# H  c2 L7 T. m3 U
qryItem.setID(myId) & D, ^# Y% ]/ a4 i

( ~, z( W: L) l5 \; h1 {: s' Add the BOM structure. - a9 [% Z- c( B! u6 C- B
Dim bomItem As Item = Me.newItem("Part BOM","get")
. y! i3 V! W+ U) bbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
3 N; `: _+ X' o& e- \; O- ^0 kqryItem.addRelationship(bomItem) 6 n4 @6 w+ H% ]9 G- c$ E% I
# ]2 w( b' K6 y# c
' Perform the query. 7 ^, j/ J5 ?3 ?3 K
Dim results As Item = qryItem.apply()
2 c* t2 k6 P* `- ?  i! v! B
% @5 k$ |! z; b9 F% z" s' Test for an error. % k, k, H0 E, p  }( x" n6 Q9 j
If results.isError() Then 0 P2 q" l7 b& Z7 \; i" [+ \. r
  Return innovator.newError(results.getErrorDetail()) $ P( E+ N% M. W- s
End If
% D8 W% o9 H3 }9 U* c ( s3 w% |1 ^& F! g1 P
' Get a handle to the BOM Items. 8 D6 t1 D0 ?. n" _
Dim bomItems As Item = results.getRelationships() # `$ m0 o* f+ q& A6 L/ C' l
Dim count As Integer = bomItems.getItemCount()
" e: D  a  |& Z, _2 ]$ j/ b4 DDim i As Integer
' \: V4 t7 i% x5 m1 C , E* w$ {5 I8 G) g( S
' Create the results content. 2 @! T: {& e" y2 F; `# q
Dim content As String = "<table border='1'>" + _ / X) M+ X/ v8 ^$ w  t* ?
  "<tr>" + _
5 D' J2 o# G7 x# W" ~% K% d    "<td>Part Number</td>" + _
# S5 \$ Y' j1 |0 K4 p3 ~    "<td>Description</td>" + _
5 A7 F) N2 J6 [* r    "<td>Cost</td>" + _ 0 n. [  f0 [) m# o$ v. U
    "<td>Quantity</td>" + _
. R" n' z! w" |  "</tr>" ) p5 A$ V9 @, t! [7 p4 z6 u
: H5 B1 c) Q3 b; Y
' Iterate over the BOM Items + G% }. G- f8 S5 _
For i = 0 To count - 1
* P. ]' l) Y/ x; z' Get a handle to the relationship Item by index.
* Z5 C( G9 j  x6 c- f  Dim bom As Item = bomItems.getItemByIndex(i) 4 \) C8 B9 c# K& Z

: Q5 x8 ~3 U# ~8 A8 v1 b1 R7 Y' Get a handle to the related Item for this relationship Item.
% y2 N* _0 N# H$ o8 N* w  Dim bomPart As Item = bom.getRelatedItem() " x. b9 d9 E# G. ^; J8 \' \4 x$ P
# s1 ]  w0 |/ |, g' U
  content += _
8 n5 F2 C. |5 J; o    "<tr>" + _
  e1 o! f% B% l% A. m# T& U8 |      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 0 Q& R; x& L2 }, x, h
      "<td>" + bomPart.getProperty("description") + "</td>" + _ . w9 n; T. B6 l% O' K& @- k. k
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
! Y! u% z2 ?, a6 d      "<td>" + bom.getProperty("quantity") + "</td>" + _ 9 Y" z$ M% ?/ p5 I2 G
    "</tr>"
+ |0 ]# t3 m& k+ w! l; `Next
) I/ ?$ `. |$ A& [content += "</table>"
0 q' I9 H/ z( n0 `, b  f 7 k) l5 B) p% m. X3 W% c
Return innovator.newResult(content)
3 I. Z  a: |, d( x, g1 m- O# [( c$ x; G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了