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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% ?8 j$ a7 ]. o! [" c7 [( WTo query for an Item and retrieve its structure you build the query as the structure : a% |( u( d, q4 ]+ Q
you want returned.  Use the IOM methods to add the relationships you want and " R3 v: k; b% G1 d
build the structure in the Item.  The server will return the structure that follows the
# U. D) a$ G' P( D, e9 X$ Nrequest structure.
! j& t: N; m2 \! KThis recipe illustrates several related concepts together, which are how to get a set
( e1 o5 h  Y) R! w1 W4 Y) J. ~* Fof Items from an Item and how to iterate over the set, plus how to get the related
7 X; v4 J  q" K( GItem from the relationship Item. 7 \& F# j/ f/ B7 M0 d; d
JavaScript  / p6 n! _+ F# }' H1 X. c
var innovator = this.newInnovator();
' z( t+ Q4 G3 m* s+ ]& H / a. ?  h& M* A* ~2 i9 R+ y
// Set up the query Item. # S/ o7 i- v3 y- R& E) T
var qryItem = this.newItem("Part","get");
% [4 t4 K+ h2 _qryItem.setAttribute("select","item_number,description,cost"); 0 X- a! l2 c% b4 r
qryItem.setID(myId);   ^/ B# W% f: ?' d9 `! G8 H

6 x! Z& T& }+ ^// Add the BOM structure. ' |+ I) l- m& |
var bomItem = this.newItem("Part BOM","get");
2 P, M, R+ e6 ~$ xbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); ; z1 w  e8 j. b) {) Y
qryItem.addRelationship(bomItem); $ D! l5 Y! W+ D7 m7 p" ~6 h, R

1 q- h8 G- s( w$ n+ i6 E// Perform the query. ! K6 j/ [) g& D% C+ r
var results = qryItem.apply();
: B) w* _9 V/ W
4 f+ N! n, r! @. r0 E2 l1 U// Test for an error.
( x. ?) ^- |9 E6 U) `0 C2 Sif (results.isError()) {
. T7 [9 w( M& L9 R$ o  top.aras.AlertError("Item not found: " + results.getErrorDetail()); - h/ ^$ Q& K+ Q1 f& K& d
  return; - e7 S! a, ^- D' c: d3 {/ d
}
8 X  ]7 |0 h9 V( \* @ 8 i5 g4 s$ d0 Y- N$ f& ]7 q
// Get a handle to the BOM Items.
# ?$ p+ X: Y* I5 E# |1 f: n6 Rvar bomItems = results.getRelationships();
% k) o% b* y) zvar count = bomItems.getItemCount();
9 H; J6 t  D  W) r2 f$ ` , b( s  s$ j$ H" P, f7 N: Q
// Create the results content. 8 I/ L1 ]5 W7 t2 `, h7 |8 O
var content = "<table border='1'>" +
* j8 n8 e# b7 }/ X. @7 B  "<tr>" +
/ K- }" l: N4 Y- I- {) v/ g7 b. n    "<td>Part Number</td>" +
' ^2 S! @# z9 w; Q; i9 N* i    "<td>Description</td>" + ; d0 A1 s# a. Y
    "<td>Cost</td>" +
. ^! f# A; ^, [! N    "<td>Quantity</td>" + . x& b3 g( R4 X* Q; K) O
  "</tr>";   b  \: p) {# p% Y8 p( q9 T

* n  Z8 h  \' x6 B// Iterate over the BOM Items.
. O3 L# W1 S9 ^  ?1 ^- j3 tfor (var i=0; i<count; ++i) $ q: {: ]5 I- O( V* _# {
{ 1 b( F' A4 `/ U5 c4 A. X* }! z1 A& d
// Get a handle to the relationship Item by index.
9 j. @- w) j( n5 t6 T  var bom = bomItems.getItemByIndex(i);
" I3 ^/ a. C0 l9 e- w% ]- q// Get a handle to the related Item for this relationship Item. ' g+ d+ x. L3 e' |9 k
  var bomPart = bom.getRelatedItem();
) N7 x6 e& |; s. {. L) i
7 c- P* N; L9 [- ^. k& I  content += "<tr>" +
; Y* x; T# i9 i0 Y1 N& T) }  @2 b      "<td>" + bomPart.getProperty("item_number") + "</td>" + ( [! m# w2 j+ X/ H. C0 l( ?8 d; w
      "<td>" + bomPart.getProperty("description") + "</td>" + # v) g/ X2 M' L+ \3 Z  O
      "<td>" + bomPart.getProperty("cost") + "</td>" + / ]4 m5 k6 K: F4 N' ]9 t4 z
      "<td>" + bom.getProperty("quantity") + "</td>" + 2 X8 u% C8 P) m9 F) J2 Z3 e
    "</tr>";
2 }; B1 }" j9 K$ l7 w! s3 l! K  t} # |3 }, p8 K+ Y: o8 S9 [9 s6 {
return content + "</table>";  t* ?1 y. Q. N4 \6 G) E( R9 r

, u6 ~- j+ \4 J6 W

) O" @& H) D+ {6 }* A& p0 ?
4 z8 X1 V+ m. f  b6 O) Q2 Q+ ]- h
; q& T; ]! g8 _" y
C#  6 d, _' y6 C# Q7 m2 n* G* p- Q
Innovator innovator = this.newInnovator(); 9 M+ N& i/ t1 K* _- B% S, u% n) s

$ `# L* ]2 T" s' t, m! F0 N// Set up the query Item.
( j5 p! n# Y" ^* a9 AItem qryItem = this.newItem("Part","get");
4 W; r! \' r+ o5 i3 H5 ~% UqryItem.setAttribute("select","item_number,description,cost");
8 o1 [& x+ P, E+ c. K  n: x. N0 v- s, K6 fqryItem.setID(myId);
$ ~% |9 Y! ?* _* S5 \ * m5 `3 H% G, S: n0 t. e
// Add the BOM structure. / n2 f. t. [: j5 V: \% J1 Y$ s( ?9 N
Item bomItem = this.newItem("Part BOM","get"); 8 J3 D- ~* Z& ~/ {+ n6 V( S. i
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 7 v( ?9 ]: U& K' r# A7 u8 `$ n$ U4 l
qryItem.addRelationship(bomItem); & f! A+ {9 n% [- J( b, g' S
" J& j7 v; S6 R6 r6 `) S) [! u
// Perform the query.
: d& ]/ q- c$ v5 mItem results = qryItem.apply();
7 ]" H+ F( E# p4 w0 Y7 {! t ; W4 t& s+ ?+ s. c, \
// Test for an error.
. q5 c! V7 j3 y. j/ uif (results.isError()) {
" c7 d) P9 p2 `# a  return innovator.newError("Item not found: " + results.getErrorDetail());
1 ~  @: d. b' M, W7 h9 O} / T! G' F/ {* X2 [3 ?1 O) a
/ L) ~3 m/ P6 M. D+ \# s
// Get a handle to the BOM Items.
& }( r) j: d' y8 u& X9 g5 GItem bomItems = results.getRelationships(); 8 |$ ^: J9 v& k4 r$ `( e
int count = bomItems.getItemCount(); ; Z1 O, s. f2 G2 j! q) d  a& O1 y
int i; " q! g  K9 p& u: k/ q/ O$ W% a
& |8 G# U! ?+ X# h/ \  [9 B( ?
// Create the results content. 1 g9 g! A; i! ]0 V8 [2 J
string content = "<table border='1'>" + & r1 N' @/ r) M# F6 T; C$ N3 g
  "<tr>" +
% P" V, x' ?; _    "<td>Part Number</td>" +
# z( ?% K, t3 T; M$ Q% A    "<td>Description</td>" + 6 |+ L3 ?7 ?7 t5 P1 x% M
    "<td>Cost</td>" + # `. D8 }# [( U* h6 t: s) \
    "<td>Quantity</td>" + ' E: h  F7 B- ^0 |1 y0 C
  "</tr>"; . [* S; O7 _7 }. L/ z+ O( H' ?

, k0 a8 c' e( ]) L$ s. V( X% o* T// Iterate over the BOM Items. 4 P2 ]! x5 q/ s! ~% t2 _1 O! I8 B) J
for (i=0; i<count; ++i) 7 }' \$ b" s1 |1 ]5 G+ H2 g
{
+ G' `( M8 s, f! j; W, z7 v: J// Get a handle to the relationship Item by index.
( L/ t4 U4 ]& a" I2 {6 F5 }+ ]  Item bom = bomItems.getItemByIndex(i); + Q# ?. |( n/ ]0 s
// Get a handle to the related Item for this relationship Item.
. ~3 y( O/ g. j  q  Item bomPart = bom.getRelatedItem(); * Q3 [! {! @) E/ N  u; M, F

2 R" _2 l4 v5 J5 m  content += "" + / U; A  n  ~# h( w
    "<tr>" +
3 ]: ^5 H' i- Q* A( J' v      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 y8 d5 Q) s" l$ ]; V6 k0 G: t
      "<td>" + bomPart.getProperty("description") + "</td>" + ; ]2 F  c8 X) e, R2 O3 e& S
      "<td>" + bomPart.getProperty("cost") + "</td>" + " I; v' W6 o. L+ F! X
      "<td>" + bom.getProperty("quantity") + "</td>" +
2 ?7 H. h6 O: y; G    "</tr>"; * r; w& k9 w1 m2 G
} 6 ^3 Z  b$ t3 D  e
content += "</table>"; ) _  R0 r# q& o/ |! l5 P
' u- F9 H- S! i! x
return innovator.newResult(content); + L, ?: Z+ i! D$ x

/ O" b; V& I/ G; ?6 |

! k7 Z6 q: Y- m2 ~( ?) \
, U0 {  _& Y6 t1 B) ^
8 |. W  e( k, i$ ~

7 q1 k: {& ?% Q% V' Y' ]2 ~* k
7 B( m( r; X3 n, P

9 ~, N8 K8 F  ^9 F& {    Page 46 , U$ m3 A3 {; d8 y
: ?" A; {; m. u4 b
Copyright   2007 , R6 N, k" u) h6 i% i
Aras Corporation.  
  v/ B1 g. l+ gAll Rights Reserved. 7 H  U; V8 M  T0 c, S: a
VB.Net  
7 V) \% l1 I! R- S& `Dim innovator As Innovator = Me.newInnovator() % m- C  k7 `5 H7 U
! [' c' \6 k, i  r9 d& ]' I9 d
' Set up the query Item.
8 S8 Z1 x# ?/ U9 S; r: R  ^: M/ eDim qryItem As Item = Me.newItem("Part","get")
5 w5 n, R0 S6 g! ~& VqryItem.setAttribute("select","item_number,description,cost")
7 O+ ]3 J( E4 MqryItem.setID(myId) 3 B, e, Y% \4 M3 ^* v' _3 E# @
* Z# \- D$ D4 e! k
' Add the BOM structure. % b8 D9 U  `+ ]- R. d' u: u$ d* A
Dim bomItem As Item = Me.newItem("Part BOM","get") 6 l1 {1 I% R! u* k3 U
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
5 r, H, R2 V% g! N- R; fqryItem.addRelationship(bomItem)
/ l5 l8 c  [. a: O1 [' q3 Z
' u* |  g7 P* Z8 k- Q) e' Perform the query. 2 p: k$ x+ l7 W. Z6 v
Dim results As Item = qryItem.apply()
& l5 W# B/ D3 Y8 H/ l4 ]9 z5 ?& c3 a 3 f% a  t. T$ q  f* u
' Test for an error.
( u( o3 [- Z& Q0 [5 q! k3 B9 TIf results.isError() Then ) M' y9 U( I6 {) F. v$ b* ]
  Return innovator.newError(results.getErrorDetail()) # O  a8 |  s" \& f; r
End If 6 l6 A1 J/ B! s  V* S
9 Y5 H; X& D9 K
' Get a handle to the BOM Items.
6 n$ R3 M1 J9 t4 y$ TDim bomItems As Item = results.getRelationships() 8 h; j- x" r7 |# Y8 G, H) z6 D
Dim count As Integer = bomItems.getItemCount()
6 D- g) k: d, U6 N" u- KDim i As Integer / U1 {7 g3 B$ }- |1 Z) J! ~
4 _5 s1 A2 Q, V+ e  l! x
' Create the results content. ) q( B0 d8 Q. C! E7 {
Dim content As String = "<table border='1'>" + _ 4 m* g; `; T. ?9 z
  "<tr>" + _
' |4 l1 [7 Q/ `7 O( C+ C1 F9 D8 g    "<td>Part Number</td>" + _ 9 z% m- S2 \8 ^* j
    "<td>Description</td>" + _ 9 h1 A4 K5 Z  c3 p& H6 Q4 i
    "<td>Cost</td>" + _ * [, @2 {# _2 B2 f$ Z
    "<td>Quantity</td>" + _
5 _" A/ u+ O. s2 k' P0 ?; z  "</tr>"
7 }/ k5 j6 V$ D. I
1 @7 \* @6 H/ e; O7 l/ G) y$ i' Iterate over the BOM Items
, H2 M% c  k& a% o# d3 sFor i = 0 To count - 1
5 ^& q- n+ e7 s* @5 x: z+ S8 a+ n7 v' Get a handle to the relationship Item by index.
9 [1 \7 h. W& b3 r; {7 k  Dim bom As Item = bomItems.getItemByIndex(i)
1 }- W# h) J" H7 B' ] 3 Z1 _3 J- |0 {: S' Y7 C
' Get a handle to the related Item for this relationship Item.
; s3 p; f' o% t  Dim bomPart As Item = bom.getRelatedItem() ) Q9 j1 b9 i+ |, G/ F$ T- {# K  v
) M& b) e+ o9 i$ C0 V4 H$ J2 _
  content += _ 5 s) d3 `7 z+ `  J! D
    "<tr>" + _
4 h' _+ C. `0 D      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 5 C# \) F, Q5 \! j( ?, B+ g7 o7 O2 B
      "<td>" + bomPart.getProperty("description") + "</td>" + _ : ]: H; Q. }. W& ^
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ - o) ^$ w4 p' v7 P
      "<td>" + bom.getProperty("quantity") + "</td>" + _ , e. \+ G5 Z2 z8 C( h
    "</tr>" 9 P6 i; X" I0 x: M& x
Next 5 B: Y: r4 n  F' c
content += "</table>" * B0 N! g* m8 s* |

( w" E( }5 y- O2 N: G. _Return innovator.newResult(content) ! G' s, f% h5 H8 v. @+ B6 T

0 n1 A0 p* Z! \4 h; m
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了