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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
  E( p6 A+ ]8 k0 JTo query for an Item and retrieve its structure you build the query as the structure ( m8 s5 Y8 ]2 s% _) j) {
you want returned.  Use the IOM methods to add the relationships you want and , U9 o: j$ w) B" m+ J% b& P/ A6 H
build the structure in the Item.  The server will return the structure that follows the / H0 G. D  \/ w" K0 E/ J3 N3 w
request structure.
5 G5 ]2 p& l1 j5 S. V5 E( nThis recipe illustrates several related concepts together, which are how to get a set ) q/ U2 ^* j8 w" Z9 L# N
of Items from an Item and how to iterate over the set, plus how to get the related ) S0 |; F; H7 ?1 E3 j  E
Item from the relationship Item.
2 I7 `1 d  ~. D9 C7 kJavaScript  
6 j$ ?' e4 B' x# F4 D6 Z3 ^0 x1 o) ?var innovator = this.newInnovator(); ; p/ W; ~- h5 {3 g( k4 N. z: a
4 U' U+ t: T: @& Z
// Set up the query Item.
7 M8 z" ~# C$ S" ~! A+ b8 `  S5 `var qryItem = this.newItem("Part","get"); : {0 s5 ?) q% @2 |& o
qryItem.setAttribute("select","item_number,description,cost");
7 y' l" K- y  v9 BqryItem.setID(myId); ! L3 Q  w2 r/ d; H9 R/ ~2 V

3 r. Y8 S  O* s// Add the BOM structure.
' [5 ^9 ?% O8 V7 D( xvar bomItem = this.newItem("Part BOM","get"); ' X7 v- i+ m- t& ]8 T
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
& D& ?+ F1 r; z( @qryItem.addRelationship(bomItem);
9 v$ Y( g" D/ _- I4 b
. h, _  G5 C7 B2 `// Perform the query.
9 @" M: l4 p" K, k4 i. k; }var results = qryItem.apply(); 2 R( X7 W4 `/ w$ \2 q9 p  w( d

3 ^) ]) Z: J0 a  m; b* x2 b8 k// Test for an error.
- x* B6 O3 r! R& Rif (results.isError()) {
+ p  F' o: d5 d6 @2 Y9 Y  H& Q  top.aras.AlertError("Item not found: " + results.getErrorDetail()); ! p5 T* _. d) {
  return; ( o" ~; L5 t! W) t2 ~
}
, s4 }- @/ I+ c; x
% Y* }* p! h* q4 B( I8 m// Get a handle to the BOM Items. 1 e5 k; n9 [. b3 W8 Q# f: E
var bomItems = results.getRelationships();
4 o1 u" _" a0 Y5 I: {. zvar count = bomItems.getItemCount();
( N  H9 T" L- Q
" w* y- _! }9 o// Create the results content. , ^0 {! u7 c; k# _, ]4 V# Y* T
var content = "<table border='1'>" + 1 X$ H" J1 `" F+ w& w
  "<tr>" + . k0 q4 A* {2 a6 A/ C3 r, e
    "<td>Part Number</td>" +
6 y" C! Q, h8 ]! N    "<td>Description</td>" + ( S' e2 n3 @1 A& L" H# r
    "<td>Cost</td>" +
( O2 e8 o8 J: _5 o$ c$ {; ~' }    "<td>Quantity</td>" + ! j2 G! P. a+ o% h
  "</tr>";
" w) X; d4 T' ~2 W! e, J 1 ?: V. d1 @( }/ v  Y$ U
// Iterate over the BOM Items. 2 u) A+ p; F5 \3 L& W4 ^
for (var i=0; i<count; ++i) ) h% r3 P$ h# O$ q3 l7 c
{
. u. z# U2 p1 X0 _4 f- D// Get a handle to the relationship Item by index.
3 _) [8 G. q; |9 V+ w# ]+ L  var bom = bomItems.getItemByIndex(i);
8 j8 c' o( q- L* ^) R" [// Get a handle to the related Item for this relationship Item. . p4 ]% V3 W- b
  var bomPart = bom.getRelatedItem();
2 N2 Y# d* {% G- I
6 {1 w; G! p+ b2 q/ v$ |9 \  content += "<tr>" +
2 Q$ A5 L/ z1 ?, `7 A  d3 l      "<td>" + bomPart.getProperty("item_number") + "</td>" +
+ [* A" H, i* P0 B$ U      "<td>" + bomPart.getProperty("description") + "</td>" +
, }+ z8 h- v# X3 a5 c      "<td>" + bomPart.getProperty("cost") + "</td>" + 6 _3 g2 k' Y$ _1 t5 v1 @# ?7 g
      "<td>" + bom.getProperty("quantity") + "</td>" +
9 H5 S  a7 ?* m+ u    "</tr>"; 7 K: r  j4 \$ R) @9 n" q
} ! \3 f; G, v9 }  a; H. i4 N, ^
return content + "</table>";1 {" r; R* r7 }# s) W6 `2 l  Z" N
1 v" b$ O% G# N4 b

5 _$ O- B& W0 G  e" G
- |, [7 A  }* A; N% `
# `. g- W8 C( |  e6 i3 g/ f
C#  
& j% d: i* l% {Innovator innovator = this.newInnovator();
# e# ~; l( A' x2 x/ _1 { ! H* Z# z4 J2 B/ ~9 ?4 V$ u
// Set up the query Item. " c  v' j% y1 b7 }6 M* E
Item qryItem = this.newItem("Part","get");
+ A! n" |  |5 V, ?( RqryItem.setAttribute("select","item_number,description,cost"); & z% R) `% u+ o0 A# H4 A* a
qryItem.setID(myId);
3 n# I9 V& ^4 V' v, k  L; j & R/ I( _9 L( |* D0 m7 {8 v
// Add the BOM structure. 4 ^; C! u" h/ N; ~% I
Item bomItem = this.newItem("Part BOM","get");
% Z7 a! s: z  f5 r0 KbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
- C1 i* a0 j/ d% m* @! b( N6 h/ KqryItem.addRelationship(bomItem);
9 x7 ?0 L( [: T9 |- Q6 J5 J
' ^% C2 ~1 D( Z" A* b% g// Perform the query.
0 Z& P' |0 e- @3 KItem results = qryItem.apply(); 7 H+ H+ f2 f0 @- u

1 I5 _* i3 e8 v" ]0 {" W// Test for an error. * Z- i% G3 J5 I- F
if (results.isError()) {
, m7 `: I$ x+ `# }! K1 P4 o  return innovator.newError("Item not found: " + results.getErrorDetail());
. ^7 }2 e; t, R* \9 K2 B8 Z} 0 e9 V% k; t* ]
: v( e& f& e5 N4 t* l
// Get a handle to the BOM Items.
! I. M+ S4 r8 e, qItem bomItems = results.getRelationships(); . Y/ }5 Q: f1 R+ s6 a2 d0 m& p
int count = bomItems.getItemCount();
8 M! d1 i* z& G: t4 ^$ J9 p* Yint i; * p/ E* Q( ~; `

; x* T) d) L# C! Y1 u// Create the results content.
- |/ ?1 ^, T* c0 D  v8 ]string content = "<table border='1'>" + % X+ `+ F' N1 ?
  "<tr>" + : ^$ D8 }- p- S: W1 O* c
    "<td>Part Number</td>" +
3 z3 Y( _! V: R- b* |) V; Z    "<td>Description</td>" +
5 @8 c$ J& m0 ~6 O# P    "<td>Cost</td>" +
6 P1 D& g3 z( \: A7 L, ]    "<td>Quantity</td>" + 8 b! ]& }" L: w5 b7 @( Y
  "</tr>"; 9 N; Q0 {2 Q6 F( Z, C8 W7 x  c

: i) N) }$ p# x$ j' {' u// Iterate over the BOM Items.
0 m; B. T1 h9 r5 I' j# Rfor (i=0; i<count; ++i)
- i( Z9 H( L' G5 g% k, W6 l, ]{
, j; s* J* s- O// Get a handle to the relationship Item by index.
. J+ B- h4 j6 n% ^: I+ E" Q& P" ]' u  Item bom = bomItems.getItemByIndex(i);
. E/ P& h8 r+ s% ?. H// Get a handle to the related Item for this relationship Item.
  F  f3 L" C4 T: ^% n  Item bomPart = bom.getRelatedItem();
& Q9 ?( i9 \) i7 C; X/ G8 m ) S: a/ }3 a* D2 K+ @+ Y& r( C
  content += "" + . V* J3 A( I: T! R
    "<tr>" + ; c! ~- [! K4 e+ f' S9 X3 n" B% T  u
      "<td>" + bomPart.getProperty("item_number") + "</td>" + / w1 C5 F1 U$ g; b) I  b7 {% C
      "<td>" + bomPart.getProperty("description") + "</td>" + 3 f4 j; C4 ~% }# b& ?8 K
      "<td>" + bomPart.getProperty("cost") + "</td>" + 9 b: K3 G1 v: e. O" {- r
      "<td>" + bom.getProperty("quantity") + "</td>" +
( p" B/ s3 Q9 z1 g" U% d    "</tr>"; $ s7 [" N0 E) b/ I6 g6 u' t
} & b. X+ _; N/ R- Y- |) _$ L" Y1 M
content += "</table>"; 5 z! o' w9 u8 s, N. @

* z: t7 s% t6 W8 e) Mreturn innovator.newResult(content); , j8 ~/ D3 Z' W: X5 |1 q
  ^$ c1 j+ `, y, C. C+ {
2 B5 B3 w! f; O( p
! O: S( p+ O2 _5 M( Q% r" C4 M+ _5 ?

. z* A4 ~0 R: z$ z$ W# M, z* H# P" m5 v

, x; v" }" e: x2 {: D, Z ( ~& Y9 c" _& [
    Page 46 1 t3 R; ~: T" S

- S5 M  H+ L7 M7 L4 LCopyright   2007
5 P( u0 ^1 s/ X/ y% v- KAras Corporation.  
# K6 S# }* z: E' L( r  dAll Rights Reserved. ! q4 a3 u4 W( f1 i  E8 I
VB.Net  
' O7 B- ?  a5 P) CDim innovator As Innovator = Me.newInnovator() ; R# A2 O: p! A7 b3 i) N

4 B4 u) T+ ]9 A0 K* r6 H' Set up the query Item.
4 n. l& l! W/ {7 H  N1 D7 |Dim qryItem As Item = Me.newItem("Part","get") " H' |* p) V9 K
qryItem.setAttribute("select","item_number,description,cost") : i9 |0 C9 |0 D: i, a
qryItem.setID(myId) $ H! a- I* D9 z6 Q
/ ^0 T. h1 Q" [9 ]
' Add the BOM structure. 4 ~5 j' s, F* h2 I5 L! K! l
Dim bomItem As Item = Me.newItem("Part BOM","get")
6 F' b2 r& a5 m5 K. `6 O# J- xbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") # o; ~1 B  I0 f3 M: z) ]- F
qryItem.addRelationship(bomItem)
! d6 @. b$ m# f+ B 7 h  q2 _2 p: C9 I) H1 e4 k8 ^
' Perform the query.
, Q/ t% L+ M/ k) H3 F" SDim results As Item = qryItem.apply() & _3 u9 h3 l" \$ ?) M9 b

( d2 [7 F) p0 M! R' Test for an error.
4 w0 q8 q' r7 |+ Q" i* R/ c# ]9 PIf results.isError() Then ' b3 t9 h/ `. l5 E) Z  _+ K
  Return innovator.newError(results.getErrorDetail())
7 I8 i7 B1 k  ~/ Z, wEnd If % o) @3 w$ v8 {

0 @# G8 S8 s6 k$ W' Get a handle to the BOM Items.   f2 J9 V& ?8 w/ m$ G
Dim bomItems As Item = results.getRelationships() 4 _) Q2 b6 S) f2 J  A# Z0 N; @; c
Dim count As Integer = bomItems.getItemCount()
$ O$ W3 o- D9 j7 c$ ~( C$ g3 }. HDim i As Integer / g# ^7 }& s6 z) B
- ~& z8 k, {8 p: D: ^
' Create the results content. & X5 }4 n  c" d
Dim content As String = "<table border='1'>" + _
9 k/ l! k& X2 P7 L1 A& k9 d- Q: n! a  "<tr>" + _ ) r4 l7 _, m; J3 V% A% c- L) A. J
    "<td>Part Number</td>" + _
, p" {9 n. \2 h( _7 s, v    "<td>Description</td>" + _
# p! Q9 G' f; ]$ x; R* K    "<td>Cost</td>" + _ " q5 B2 G' b  O( q6 }
    "<td>Quantity</td>" + _ 8 a/ G. z. E. y
  "</tr>" % _8 w5 @, e- _* U

- F" X. F/ b0 a/ `0 r' x' Iterate over the BOM Items
3 V2 V& U; i& [- r& OFor i = 0 To count - 1
) I7 N4 e' W5 D; ~( ^0 ^' Get a handle to the relationship Item by index. 7 j( O' F/ R6 |0 |: j7 ~
  Dim bom As Item = bomItems.getItemByIndex(i)
# `1 o: G- {; c2 g# G2 _- q 9 s* W3 |0 b' r  F
' Get a handle to the related Item for this relationship Item. ; }) Z; d" H. g3 u) Z
  Dim bomPart As Item = bom.getRelatedItem() 1 H4 ~4 X+ c; a0 W; {, Q

1 h- i" g7 O/ |  content += _ ) e3 V* [/ W0 S6 l, v( e; b4 d
    "<tr>" + _
' s" ]5 g( N1 w0 y3 f      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 3 |0 i4 K' z& p* ~
      "<td>" + bomPart.getProperty("description") + "</td>" + _ $ X; H* }. S' y" ]* w& c
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
/ `5 E% `+ _6 D+ e0 L$ w      "<td>" + bom.getProperty("quantity") + "</td>" + _ 4 w, e; [4 ?* ?" o6 f
    "</tr>" . U( g$ H& Q+ S( s; M/ U* S2 j
Next 4 `# Z& r: C8 ?( m6 D* c
content += "</table>"
% @  f9 h- l5 G- s- h! Q. s
% Z( L5 I  l1 `5 JReturn innovator.newResult(content) $ Q. G% [& i& S: u

6 w  ~( s7 z9 U3 i+ U, U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了