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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
5 z7 ]: ^  {" I. E- qTo query for an Item and retrieve its structure you build the query as the structure
1 ]7 D! G& |- t3 Vyou want returned.  Use the IOM methods to add the relationships you want and - P% [9 N( s; u3 }( A
build the structure in the Item.  The server will return the structure that follows the . y6 ^" s" t2 j& r  u: @; T$ B
request structure.
) p( o% r9 h2 r7 r; U5 NThis recipe illustrates several related concepts together, which are how to get a set
- }3 O  a% w5 c2 v% Xof Items from an Item and how to iterate over the set, plus how to get the related * z! P5 o1 R: U) d+ E1 d4 Y
Item from the relationship Item.
; ~" v/ ?9 d# ?$ m  xJavaScript  1 q4 m, S3 r/ Z) {
var innovator = this.newInnovator(); . F. A- N6 J: @- p

. I& y" D& R+ P! s; ]: ~. N% k// Set up the query Item.
* ~$ M7 b& I$ Qvar qryItem = this.newItem("Part","get");
' u' H. {6 J6 J* fqryItem.setAttribute("select","item_number,description,cost");
  t( \* Y" o( u, FqryItem.setID(myId);
6 {& W3 M  \  H1 G9 D& U 8 g3 b( H" n: `6 Y3 s' H5 g
// Add the BOM structure.
% `0 ]7 @2 ]; X; b0 @+ D; Hvar bomItem = this.newItem("Part BOM","get"); ! i5 E; F0 z3 H! V' Z& p
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); 1 e) a$ u# m9 K" h1 r# _
qryItem.addRelationship(bomItem);
: I0 x4 S, w) M% R
3 e6 U7 s& K8 V. a& R// Perform the query.
& u; Z" `7 M2 Zvar results = qryItem.apply(); ' k! Y1 T; V; {- H0 \5 G( f

5 y. x! G( r4 v& Q1 {# B9 t// Test for an error.
% j0 Z. H$ h& ^# x! U+ p- Gif (results.isError()) {
+ X7 [* h" ^! Z- Y) x7 @, {  top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ |* g! t6 q2 N8 M6 ^/ u5 l  return;
: T/ y+ ^2 [1 Y. W' [& V+ d* S* t2 }  O} ) o! B+ d0 \% o5 T4 C
6 k; `) }! h& Q' y
// Get a handle to the BOM Items.
. c, N% P& C/ [. P$ m" Y* o+ N) svar bomItems = results.getRelationships();
1 P  G: g2 d2 u- B! k. Tvar count = bomItems.getItemCount();
3 a4 o8 V  p6 T# h
$ a' |5 s2 J& \3 m, r2 l// Create the results content.
& f6 @; S, w- G1 R1 r$ M( hvar content = "<table border='1'>" + ! W0 p7 l2 ^6 v0 H6 t) m
  "<tr>" +
2 F& T( o) D( g0 q    "<td>Part Number</td>" + * j, h( k, M- U" C( ]2 k
    "<td>Description</td>" +
  V3 s  F* ]: t- I    "<td>Cost</td>" + 1 o* I/ S% u; _
    "<td>Quantity</td>" + : G* M8 x! s9 L0 [
  "</tr>";
; f% w2 T: {' C4 k% n3 K5 W; L2 d
) R8 D' \) l! s// Iterate over the BOM Items. ) h, t5 l0 p7 S
for (var i=0; i<count; ++i) + e6 [; N0 l) W. C
{ 1 S* f" |" Y( S$ i
// Get a handle to the relationship Item by index.
4 g4 F1 P) k' g1 C; S  var bom = bomItems.getItemByIndex(i);
% D. ^9 [% |* k8 P: e& {& g; G- Z// Get a handle to the related Item for this relationship Item.
+ f0 k9 \* v  o! O5 u  var bomPart = bom.getRelatedItem();
/ O1 o( r, [+ M% H( e' W( K 9 s2 J  f7 s5 G/ n4 I! f: k: t
  content += "<tr>" +
) T6 `9 @1 T1 S- P- G+ H4 W# H1 d% u      "<td>" + bomPart.getProperty("item_number") + "</td>" + * h- c; x2 Z0 k+ \
      "<td>" + bomPart.getProperty("description") + "</td>" +
) L8 e6 `6 R0 B; ]      "<td>" + bomPart.getProperty("cost") + "</td>" + . S% U* T, J" {
      "<td>" + bom.getProperty("quantity") + "</td>" +
! Y: u( C5 T3 W' j# x6 h    "</tr>";
% X4 G( h- b$ ?" I# X# [, _) P1 ?} / g/ f8 w: E5 g& `0 B
return content + "</table>";0 N4 V9 J/ X+ O

7 b$ x1 Z$ i; {- v
# ~2 Q) s* w/ C8 @3 H) U) k

* \' |) K6 a; ?1 J0 Y2 q

  e% k5 N6 S- H# c$ \C#  
0 W# z, h; Z# L5 yInnovator innovator = this.newInnovator();
5 Z# i5 ?# j% Z! }5 x7 n2 @ " y$ H& [" d0 v( S4 ]! f' ^
// Set up the query Item.
( g/ l4 c* }+ P0 RItem qryItem = this.newItem("Part","get");
' _$ s1 \0 u; H4 h6 f, i' bqryItem.setAttribute("select","item_number,description,cost");
% I3 e1 w% l# f1 S1 C( N9 kqryItem.setID(myId); 4 O/ H, E0 D& E* b# B2 P7 ?
& R5 m- V6 C* O7 G7 T
// Add the BOM structure. $ d- ], O% u' c2 k
Item bomItem = this.newItem("Part BOM","get");
: V, O6 x$ v4 a2 H7 MbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 3 W% p6 p0 Y' T+ p' P
qryItem.addRelationship(bomItem);
  Q* j( Y3 V/ X1 V
9 _* o. F+ R  k& y! m// Perform the query.
' o7 p: |# C& [8 V* `Item results = qryItem.apply(); 7 [, i3 Z; Z  i: b: w
& L* \* e7 O+ e  t  r+ Z) B2 j
// Test for an error.
; ]3 l6 I0 e; U' D3 Cif (results.isError()) {
" ]/ L5 H9 h3 g2 M  return innovator.newError("Item not found: " + results.getErrorDetail());
2 l! w$ S# y) |6 A, o/ X( X: o} : r* f: L" e" q" ~6 k% p: h

6 U& T% V6 e7 @& C5 z' E// Get a handle to the BOM Items.
. q$ w6 Z1 H" ^' {+ hItem bomItems = results.getRelationships(); - j6 U1 e# c$ [
int count = bomItems.getItemCount(); 5 b' ^4 w* Z" S9 b, t& Y9 m6 g: V
int i;
) L. i) j" r  e
2 ^5 C$ q/ V' C5 ]8 r4 `// Create the results content.
. T6 c/ T. k" u- Sstring content = "<table border='1'>" +
! o( g; E5 f6 h( k, N# o) m' k  "<tr>" + * q9 r3 g3 c  J
    "<td>Part Number</td>" +
2 f6 ?) P2 N5 b5 {3 ]$ C1 X* T    "<td>Description</td>" + 4 c1 ~1 R. _" r: }$ P5 q: G  y
    "<td>Cost</td>" + 0 m0 M- t  t7 e  S0 W) T8 N# c2 B
    "<td>Quantity</td>" + 0 T: p3 c) a* i  f7 k
  "</tr>";
( h# {! V2 F5 D) k  I 2 c9 U! M" `; _: E- H8 e" ?9 f% q
// Iterate over the BOM Items. - \( |5 d. P" p/ j  F% j; T5 r
for (i=0; i<count; ++i)
3 o) h- z$ d; Z, k) t, }$ |; |{ 5 p7 F6 Q# V) h% E
// Get a handle to the relationship Item by index.
3 q- T/ z/ ~' h! {# |  Item bom = bomItems.getItemByIndex(i);
) j; p* q4 p. q8 i// Get a handle to the related Item for this relationship Item.
6 e' N  `* j( B& F2 q+ j4 `8 U. D  Item bomPart = bom.getRelatedItem(); ! F2 u- [8 i4 B3 K

' _; x) \) j( M# }5 c  content += "" + + w5 p- z. E  k( c: L' }1 c2 s
    "<tr>" +
1 j2 R' ~1 N0 T8 _/ x      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" n# y2 A9 P3 G$ L      "<td>" + bomPart.getProperty("description") + "</td>" +
& [' g5 o! w' A: W1 D  h# a      "<td>" + bomPart.getProperty("cost") + "</td>" +
1 u7 b! i7 m3 w9 }      "<td>" + bom.getProperty("quantity") + "</td>" + . p/ j7 |5 p# c- ^
    "</tr>"; # i& e5 x! O' l& x  ~1 e! i: t
}
; l, t. s! r8 D: M- t6 Hcontent += "</table>"; / r* O4 l# O; U! I; h8 _* b

2 @) M# D2 `: F. b1 o% treturn innovator.newResult(content);
4 t. ^' Y$ i; F- \* j
& L7 t% F% c& R; b* f/ \

" {; s# ]0 u. M* b: z+ i* {
. w# u0 E' y0 K

( f& w( e6 B1 l7 T+ u# T
9 s$ l( c" o; V" z, S
2 b5 M8 {2 o+ u

( K% l- \' \7 t# x    Page 46
, I5 w6 e$ D1 J% U. p% R" Z; e$ v5 N/ | 8 H$ h- A+ G/ [$ a* b3 f+ k
Copyright   2007 0 p7 x6 _8 H2 x4 S- T; @' m
Aras Corporation.    V0 d1 ^% O) ^$ s7 j" Q' Q1 Y
All Rights Reserved. 3 D- b+ g! `1 d' C, G4 h
VB.Net  
! \$ Z; T. Z. }' x, }Dim innovator As Innovator = Me.newInnovator() & O  y+ }2 O* h6 O5 q: X+ w
( L/ Q! Y% T3 t' b
' Set up the query Item. 0 B8 D, J$ p, J' Y# E  {7 C
Dim qryItem As Item = Me.newItem("Part","get")
+ @* v9 I7 {2 U3 N: C. lqryItem.setAttribute("select","item_number,description,cost")
2 {2 Z: J6 _* F7 x! rqryItem.setID(myId) ' D% s: y* X; t( a; b

7 T  s, C& @7 x" W, d5 @' Add the BOM structure. 2 x8 `4 E2 l2 f+ |$ T: K2 @+ C
Dim bomItem As Item = Me.newItem("Part BOM","get") " P5 r* ^& J; D. G8 ]7 p4 q
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
1 b+ n( U3 ]* FqryItem.addRelationship(bomItem)
1 ]1 g' X$ W( a
, {  {# X' c$ F- `' ?, d" ^' Perform the query.
$ @, H8 p0 R% y. N% S5 D& Q/ eDim results As Item = qryItem.apply()
/ l$ S9 R' g+ m5 B! I # t+ Q1 X# {$ {  P$ V! E" D% t
' Test for an error.
' U9 |. L: ^. r( ~9 YIf results.isError() Then
4 j/ {8 m& Q& R  Return innovator.newError(results.getErrorDetail()) : v' j( s  F; [
End If
2 i; s; |$ p3 L# T% `# n/ u; H , R1 M0 I0 A( L# K0 v- G
' Get a handle to the BOM Items.
0 `  ~5 L, O1 M* u3 \6 b3 RDim bomItems As Item = results.getRelationships()
- v1 k$ s3 I( ?. k0 oDim count As Integer = bomItems.getItemCount() 4 P# l% w0 Z) W* z+ y  `6 p: x) N
Dim i As Integer $ x! l3 j& A' G6 [0 w  @% r' a% T

; Y7 _5 ^6 C/ J/ n0 _% j' Create the results content. ' p" t4 U% c6 W' p6 X: x! R
Dim content As String = "<table border='1'>" + _
8 F7 ~2 g9 ]  i9 m1 e; Y% E* p  "<tr>" + _ 1 H; H% \5 Q" \( h' b) L* u
    "<td>Part Number</td>" + _
" W0 b6 M& D0 K. ?- p1 _    "<td>Description</td>" + _ 0 I- R$ s" Q, I: S* T
    "<td>Cost</td>" + _
  T. G/ r5 ^% v) s, O    "<td>Quantity</td>" + _ # l% X: J% A8 b" v" x+ a' s
  "</tr>"
' r. e4 _7 d! G& M9 a& @
3 v0 [  b- W* N# p' Iterate over the BOM Items ( S% y  Y. e3 i6 |0 x1 K4 b" x2 U
For i = 0 To count - 1
  |$ e$ N+ H- b  l# T( @! `* G' Get a handle to the relationship Item by index. ! P/ [, ^3 B5 m3 T1 o  z
  Dim bom As Item = bomItems.getItemByIndex(i)
9 P+ C8 X4 B: ~( E; V% v2 r% | * a2 T5 v3 X( o" K( c
' Get a handle to the related Item for this relationship Item. 4 r9 I( M" T- \, L+ F
  Dim bomPart As Item = bom.getRelatedItem() + M7 q7 V5 i6 N- Y: k7 H
! P7 U1 [& Q2 Q9 b* w4 \
  content += _ ( B# |3 m8 a7 w  I; t
    "<tr>" + _
0 e& o9 R2 c5 X      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
/ p# A0 v- h) T, ~      "<td>" + bomPart.getProperty("description") + "</td>" + _ , M1 T3 J- k% f5 K, [4 a
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
' ]- v. S" f% h; m' G      "<td>" + bom.getProperty("quantity") + "</td>" + _ 8 t' Z) A* ~# m) ?  [( W* A: f
    "</tr>"
" d# f" }7 g$ GNext 7 @! d" z/ m) T1 m( I4 K
content += "</table>" 0 |6 }' Q5 j& N8 N9 w! \
3 d9 {. V; f4 ^' J; d. |+ E( ]
Return innovator.newResult(content)
- L/ }" A( }7 a4 c3 ?/ v8 ^  o! n# C2 y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了