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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
3 E: f  [) L, f8 U- J2 P" wTo query for an Item and retrieve its structure you build the query as the structure , X; N7 r6 ?9 G6 d" q
you want returned.  Use the IOM methods to add the relationships you want and
# v: N' W, D: Fbuild the structure in the Item.  The server will return the structure that follows the 7 n/ C3 m. [  L! O( m* _! e
request structure. " n: T" @" z. t: I7 S
This recipe illustrates several related concepts together, which are how to get a set # G: m. @) X- K; c  e
of Items from an Item and how to iterate over the set, plus how to get the related 0 n* G% b1 S. [* n& N3 w7 W9 S
Item from the relationship Item.
- a. X3 k. L* l; K( YJavaScript  9 }) W- Q* o" Y1 p
var innovator = this.newInnovator(); $ S- |8 d/ I# D* m: d
9 _6 N+ U- u. x" A9 f1 ]5 Q8 C
// Set up the query Item. $ Y! W& q4 k$ {- w" U3 [
var qryItem = this.newItem("Part","get");
3 M, y1 G( T  P" UqryItem.setAttribute("select","item_number,description,cost");
; V8 C2 A, F) Y6 L5 PqryItem.setID(myId);
5 D8 b/ ~* _. r4 b
- m$ x2 v. N( E/ D* Q// Add the BOM structure.   M# Q  i% ?$ _7 E6 b
var bomItem = this.newItem("Part BOM","get"); $ V4 T9 L: N! m' K  O3 d9 u& e+ K/ C
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
7 q; [- ^, t4 t- _qryItem.addRelationship(bomItem);
9 R7 z9 ^5 o8 ^7 |+ @6 L# C 2 m* A+ P  [3 K# m( A
// Perform the query. - g  I( B! Y& q/ O
var results = qryItem.apply();
6 v( S8 H! g6 Y+ {  {# Y! Y# @
8 Z6 Z) y+ m' w// Test for an error.
- [# @  z+ J# S7 Oif (results.isError()) { & ?7 O* C6 e# u4 [3 k
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 3 Z& T0 g) n- o4 j, s+ U
  return;
' l7 O  T8 X9 T. i- m( n7 j} , t  L4 }# T/ P* J

7 F3 c: \; d) l2 {* o; D- X+ P6 F// Get a handle to the BOM Items. - ^, P' R. |" j- V& m( g4 ?/ d/ Y
var bomItems = results.getRelationships();
: j; }! M/ B; I8 ]* l' b8 @! P( t- S, Avar count = bomItems.getItemCount(); ) N2 Z2 E$ N' f- o
( H) e! ~$ r( b2 f7 J) J) o
// Create the results content.
" e  n' Q, c& h7 F' Y# kvar content = "<table border='1'>" + 5 g( J; q) f; [3 z6 f2 D
  "<tr>" + 8 T* y9 w$ h3 A* \
    "<td>Part Number</td>" + 7 @3 k. R9 N% _! w1 N
    "<td>Description</td>" +
3 }% Q8 Z- H' S) H, V    "<td>Cost</td>" +
# p  i8 j& y" b# H" D) ~' ?    "<td>Quantity</td>" + 7 X! d* z) ?( L
  "</tr>"; - N% h' z. N  z

  D6 v- P7 V: M0 X- ~// Iterate over the BOM Items. 1 o. J: h4 L% U+ Y, G8 \) P
for (var i=0; i<count; ++i) / r1 d! S% f2 A" i% b5 }$ A: E
{
! A9 s1 d7 f* R+ B; d7 K3 Y# v// Get a handle to the relationship Item by index. 4 h+ n* \" y+ k5 e  j( [! G9 E
  var bom = bomItems.getItemByIndex(i);
; q; {/ c' y! N- N// Get a handle to the related Item for this relationship Item.
) @+ w- e; M2 J0 s$ Z  var bomPart = bom.getRelatedItem(); 6 \3 k2 p: ^5 ]1 M% k
& x* a" W* E9 X" T- E1 `2 a$ H
  content += "<tr>" + 5 M2 A& R9 m! v4 ~
      "<td>" + bomPart.getProperty("item_number") + "</td>" + ' E( O% k- F" d' a; e, V5 G
      "<td>" + bomPart.getProperty("description") + "</td>" +
4 ~: f* h) f: W, ?      "<td>" + bomPart.getProperty("cost") + "</td>" + ( m! z9 A# g1 v& [0 \
      "<td>" + bom.getProperty("quantity") + "</td>" + & r4 q+ c' ]2 V. @% b; f
    "</tr>";
# b; `; P1 b+ Z5 j* m! J! T  S+ l}
2 i  h. B0 o" U1 Z0 N; P! L8 o/ xreturn content + "</table>";: {" R& A, d& i' @6 Z! h3 `" }% E

! r6 o7 ~" i  j; \! V1 X& ]) H

: ]- N1 Z- g& r9 Z
) X% e" e2 f0 m6 L9 ]
: ^6 r4 e/ t5 ~+ r. y7 c# T) X8 J
C#  % L; l; n$ w5 F$ ^  M) ?- B
Innovator innovator = this.newInnovator();
( n" ]  `$ P0 {* v+ W9 F
. l  h* @+ g2 Z6 e  C+ P// Set up the query Item.
6 b+ J4 r, H. o6 s! V- E( G1 z0 \Item qryItem = this.newItem("Part","get"); 0 V) ~& a& A* G0 G  O$ B
qryItem.setAttribute("select","item_number,description,cost");
+ ~  f2 b# J3 V" D* H4 c( }qryItem.setID(myId); , p. z8 ~8 M- Q" e, w3 C/ r
( D( O# l! s  P7 I3 H( b& Q$ n
// Add the BOM structure.
- A. u+ Z8 d- F$ |+ }Item bomItem = this.newItem("Part BOM","get");
- S& v& H; K0 J0 H+ q8 lbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 3 e* @2 i9 ?( b% ?" f) Y
qryItem.addRelationship(bomItem);
" ~0 M/ q/ D; Z4 O; ^& r8 L, P
* ]* d. B! E8 l2 d// Perform the query.
. p4 [  c' m% ^& t, A$ q; |, iItem results = qryItem.apply(); ) c; j7 X  t2 h# _5 u
8 {! e8 q; u  E: d; v1 I9 _
// Test for an error. ! v5 E2 R# y$ l5 G; F" \
if (results.isError()) { ! v4 h9 E- i5 d5 t- S/ {$ o
  return innovator.newError("Item not found: " + results.getErrorDetail()); 0 k) k$ m  [; Q) R3 V9 i
}   Y9 @: Q3 H& c5 @/ U1 Z0 C

2 |0 N! p( M9 z7 S// Get a handle to the BOM Items.
! ^! G0 K* V5 u% Z' sItem bomItems = results.getRelationships();
. M* C' v0 }; y" p: X: O8 pint count = bomItems.getItemCount();
- \3 Q8 Q$ @& U2 j/ n$ jint i;
6 F; p" }4 E+ ]6 g( `, T1 N0 s
$ e8 h0 n4 N: ^& o! H2 D! a// Create the results content.
  A* X; Z, U8 _string content = "<table border='1'>" +
, k" w% ^9 \! [1 k  m/ o1 o. N  "<tr>" +
# j+ R( n( ~9 u1 Q' C$ ^    "<td>Part Number</td>" + $ {, Q8 `# m9 S# L$ A1 k8 X
    "<td>Description</td>" + 5 T6 _0 v. Z/ o. K; n4 _
    "<td>Cost</td>" + & i( M. }2 V1 j8 T7 _. Q& A; ~
    "<td>Quantity</td>" +
2 X' S% D7 y2 Z) W0 z( w  }  "</tr>"; ) W& A) G9 [2 _% _# ^1 _
3 X9 v' U  `" _4 g8 V+ ^
// Iterate over the BOM Items. 9 `; J5 t  \4 a5 e
for (i=0; i<count; ++i) & U3 ?4 k9 p- {+ [& k$ {- j9 _
{
9 n" G" z5 ^9 }! M% h! I// Get a handle to the relationship Item by index.
) Q8 O# o% Y8 X. t9 z2 ^  Item bom = bomItems.getItemByIndex(i);
, I1 K9 V4 n8 Y- O// Get a handle to the related Item for this relationship Item.
0 S' {$ v  U2 \/ k& r! x$ _* c' P  Item bomPart = bom.getRelatedItem(); 8 u+ _+ e% m2 H3 O5 A

+ ^% G( D0 R) [! O" t  content += "" +
% k4 U5 R6 \# s" J    "<tr>" +
: ]) Q0 I# H$ b6 T1 K/ ]1 Y' w      "<td>" + bomPart.getProperty("item_number") + "</td>" + ( r6 Q" A; J/ Y3 Y5 t" [
      "<td>" + bomPart.getProperty("description") + "</td>" +
9 n2 Y5 f! T' f  T- k1 [      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 L3 z( F; T4 l) g
      "<td>" + bom.getProperty("quantity") + "</td>" + / ^: v- U: d" z9 k& C
    "</tr>"; , X$ ]5 N8 N8 P& O" c6 G% e
}
! \" p. G& o" j8 R: j9 V1 Z/ tcontent += "</table>";
: @9 {) w# y9 q9 @  X. u
' e  O  Y* c9 zreturn innovator.newResult(content); / P4 B$ z, Z5 z9 f1 L! Q2 q" g

$ N* v/ K3 M3 m% l5 _& m
7 @) v9 [+ k0 Y/ L: J
7 [! A. S% W( s) e
4 f3 f# f7 t) e5 P4 g; D& E7 C: U
# @+ ^6 ]+ d  _9 {
8 g: }% J+ ^; x0 _: C5 _7 K
# ^: E$ I+ [7 \2 |
    Page 46   ^, P  W7 B9 T! z  ?

) I% W7 }& f" N- V$ j# T; VCopyright   2007
* r# k; y8 Z( L% _Aras Corporation.  
/ o1 }2 m" P0 m! {% i' p0 H- S0 cAll Rights Reserved. ; T0 {1 E9 V! Y4 S8 v
VB.Net  
" k6 l6 ~# _2 RDim innovator As Innovator = Me.newInnovator()
* g+ _' Q/ J- [( D5 Q5 S 3 b7 E* y- Z- Q
' Set up the query Item.
* w3 U$ _- r4 U/ o" g( |4 H1 m( gDim qryItem As Item = Me.newItem("Part","get") ' w9 G# f! P; `3 P/ Q$ k9 A
qryItem.setAttribute("select","item_number,description,cost") % E" }/ M  f1 r
qryItem.setID(myId)
1 c9 ^$ d$ @  t" h
& Z! K( ~: ^  R5 v- Y' Add the BOM structure.
4 H+ Z6 X5 `  W- IDim bomItem As Item = Me.newItem("Part BOM","get")
; P7 M6 @% C) M# o! m3 ~( X) ?bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ' ]2 K2 ]) R5 r! Y5 K
qryItem.addRelationship(bomItem) / j3 s& i: x* R0 v9 m
3 R$ n( B4 c, V3 m/ v/ w
' Perform the query.
! f; }8 _& ?. u1 i5 B/ p! UDim results As Item = qryItem.apply()
! S0 M7 H5 {6 h/ L+ r 0 r2 i6 ]& j! @3 H* @0 ~
' Test for an error. 0 |. H0 M, A1 t$ k# |+ o
If results.isError() Then
' F( V' m3 F6 R( w; A8 ^* F+ ]  Return innovator.newError(results.getErrorDetail())
7 }/ l2 Y& m# u0 h% \9 s8 Q, lEnd If
' j$ d/ [+ K+ n3 K/ [0 n ) k1 a# o) I. j4 M% ^- _
' Get a handle to the BOM Items. 8 j6 s: e# a) l3 w( b% [
Dim bomItems As Item = results.getRelationships()
0 `# h. H! e, p( I2 Y9 p! TDim count As Integer = bomItems.getItemCount() 3 R% n& R: o$ h; Y& _7 ~
Dim i As Integer 2 A! h  I, \/ B# ~3 y
! t' b3 c5 c5 ~
' Create the results content.
& Y- h6 l5 c, d& ~4 zDim content As String = "<table border='1'>" + _ 3 x, i% s8 S% \
  "<tr>" + _ 4 X9 X6 p! j; K0 h4 x4 C
    "<td>Part Number</td>" + _ % e9 v) r8 _5 i! O# x
    "<td>Description</td>" + _ / K0 @1 j/ W* f! g& s$ k! {  w% m+ Y
    "<td>Cost</td>" + _ - {% I+ K/ W9 i. L$ B( J7 _
    "<td>Quantity</td>" + _
& x' F4 N" X& U& E& U: J" g' D  "</tr>" + t. l8 w6 y3 ?+ d5 m
8 }/ c; _4 ]/ z1 e& C8 N
' Iterate over the BOM Items
' P$ G* t- _2 cFor i = 0 To count - 1
1 M* ^7 b, Z; A. i) A$ w! A' Get a handle to the relationship Item by index. 8 p0 U  x( j3 S% A; d% W7 @" D) R
  Dim bom As Item = bomItems.getItemByIndex(i) 7 {# R7 ~+ V0 c; B8 m( b
* h! c7 `# P1 m& \. C% a* i
' Get a handle to the related Item for this relationship Item.
- R8 a  u" w# T5 R5 q  Dim bomPart As Item = bom.getRelatedItem() & _3 _1 L3 g; W
6 ~3 ~* ^7 ~# j
  content += _ 2 O) i9 k" ^3 Y: W7 V6 c, I
    "<tr>" + _ 5 I6 x) y; b7 m  L8 b
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ % R9 g" @; W3 F; k3 y7 X
      "<td>" + bomPart.getProperty("description") + "</td>" + _
9 ]4 K2 v) m7 `+ C* f1 E      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ; S/ x' t) n# y6 e5 C. x
      "<td>" + bom.getProperty("quantity") + "</td>" + _
' D; ]' e. v6 z5 s1 W4 l: p; }    "</tr>"
/ k' ], ?9 v) q- s3 E) o6 dNext 0 ~! O. w6 E9 D" W4 u( }6 h
content += "</table>"
# v" O3 p2 S9 W+ c; ]
% y/ N8 s. p- S. l& cReturn innovator.newResult(content)
7 w* X/ D+ m4 S
  E& c2 A8 {* }/ t# I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了