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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  5 B( Y  ~+ L- u8 e8 v. B8 B8 U, j
To query for an Item and retrieve its structure you build the query as the structure ! t; D8 x0 ?$ r5 d, m
you want returned.  Use the IOM methods to add the relationships you want and ! n3 X, ^& s( B% o0 ~4 f' G
build the structure in the Item.  The server will return the structure that follows the
! g6 L7 ?1 l! Y1 m- Erequest structure. , V& Z% }2 |8 x. H
This recipe illustrates several related concepts together, which are how to get a set * i5 K! b' X' O* ^% o1 F8 Y
of Items from an Item and how to iterate over the set, plus how to get the related * x9 \/ y% W9 B0 f, i
Item from the relationship Item.
% D% s- m9 `! D- DJavaScript  " m8 W, B- w$ b& r1 R
var innovator = this.newInnovator(); + n% V& j0 h' N2 G
  J( z* g$ G# S- l' W, U. f, D2 M
// Set up the query Item.
! X/ ~3 G# u* O) x  p* O, d' T# wvar qryItem = this.newItem("Part","get");
' o* S, \/ ?  N4 \" Q/ qqryItem.setAttribute("select","item_number,description,cost"); 0 G9 _9 Z; b% C+ E+ _
qryItem.setID(myId); $ ]' O- F. K# x- Z, p7 O# E: Y# R

4 s, Z" q  Z5 m, x% v- a& N7 s+ l$ x// Add the BOM structure. ' r7 U' G' J  I4 \& i1 |
var bomItem = this.newItem("Part BOM","get");
, `" l! c$ ~7 Q& r2 O7 {bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; C- t" o, w7 g( f8 _qryItem.addRelationship(bomItem); " k% x) W$ }& w% q' p9 n

' a- C) r. c4 C' g. o& n, c// Perform the query.
7 L4 E* R: A+ V* O9 W/ `$ d  g: xvar results = qryItem.apply();
1 I" A; `6 T, X) h1 T5 \
$ @1 a7 t1 U  K+ f" ]// Test for an error.
; M$ V' ~  d2 @, v  Y+ sif (results.isError()) {
0 ^  H4 D5 j3 A+ w  top.aras.AlertError("Item not found: " + results.getErrorDetail());
* U/ F3 ]% |, ~! V7 E0 _: n( i  return; ) O, p6 E2 h  ^% J  F4 a7 s
}
# s$ L/ {" u4 z6 C
3 T9 t& m; C. F! ]; Q& ?// Get a handle to the BOM Items. % q, f! u" Y, i  X; ?
var bomItems = results.getRelationships(); % z" x/ D9 L* I4 J
var count = bomItems.getItemCount(); ' z) O+ i  Y3 ~1 U4 k3 ?$ ?' D

  _6 {7 T1 X' g1 L% n6 ]& U// Create the results content.
) Z3 ^! U6 v, I5 m  zvar content = "<table border='1'>" +
/ C7 ~$ S% B+ X  "<tr>" + $ ?. l; ~1 O7 K$ J+ r- @
    "<td>Part Number</td>" + ; y4 }! j& t) b& J8 @. p; N
    "<td>Description</td>" + ( {+ t5 Z% k+ C1 j9 p
    "<td>Cost</td>" + " G- g- C5 z+ ^! |- L
    "<td>Quantity</td>" + 5 k/ H* l; z/ U+ S2 X: x
  "</tr>"; % m7 k* }* w0 c4 [) y' G! M( ?

' r) R/ V7 R: V  V0 L3 e4 l( a// Iterate over the BOM Items.
- H1 e1 v; G' ufor (var i=0; i<count; ++i)
5 S- r2 v/ @& {7 z5 ^2 |{ ' v$ m. w9 o$ i" X4 A* z
// Get a handle to the relationship Item by index. ( a) L8 L' q) x- b8 j2 N# Z! c
  var bom = bomItems.getItemByIndex(i); 7 _# S! b! ~+ ^4 \/ R( p
// Get a handle to the related Item for this relationship Item.
4 V% ~) K& u7 A) B  var bomPart = bom.getRelatedItem();
* h) J& M) {! W ; ~5 L: ~. }1 j' Y) J& V$ y
  content += "<tr>" +
4 G# T, s  u- ]  m      "<td>" + bomPart.getProperty("item_number") + "</td>" +
" n1 Y& q. Z8 W, n/ X0 Y2 n      "<td>" + bomPart.getProperty("description") + "</td>" + # V6 h- I8 j: g( F- q4 e
      "<td>" + bomPart.getProperty("cost") + "</td>" + 1 S; J% M4 z2 v% j3 G  `, Z
      "<td>" + bom.getProperty("quantity") + "</td>" +
; b1 Q  ?+ _6 @$ k) G4 v    "</tr>";
8 P  s  Y3 Q4 y}
+ ]+ V# O7 S8 @return content + "</table>";0 \3 @' n5 z: Z; A, \8 l% |; z

$ j: a: A- A7 h1 b. s9 ~5 F1 K( s
: b. E6 D8 d0 D' B' ^$ h2 G4 O. m# _

1 N' Z% B! @8 w% z
, ^' {4 Z0 E" P
C#  2 r1 ?3 F3 a' M0 q
Innovator innovator = this.newInnovator(); $ `4 Z6 `. Z/ L$ I
% [! q3 ^( C6 {6 E8 Q1 A; y+ C; A
// Set up the query Item. 0 `7 a3 X, c+ m+ q# e! ?$ D
Item qryItem = this.newItem("Part","get"); - m- i0 y; q" s, y8 v- P
qryItem.setAttribute("select","item_number,description,cost");
) \5 g8 ]& X2 L7 M" i2 s6 l9 eqryItem.setID(myId); ! X2 p% Z& _- p6 ^: i- a% c
8 @  C! u" I& a  q
// Add the BOM structure.
5 b8 D7 N; x! p. P6 uItem bomItem = this.newItem("Part BOM","get"); 4 M+ E8 ]2 D/ d4 O' O) f! h
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
4 P: q9 ?& N) _% s3 T9 |qryItem.addRelationship(bomItem);
+ k) s! ^) X6 n. f/ B' V2 E
$ W/ K; ?4 e2 M5 ]5 p7 H// Perform the query.
7 s; i4 C, P- g5 _! X* I% LItem results = qryItem.apply(); - F  V; f4 ^/ N  ^* S3 r3 Z

- y# n$ v, q1 ]/ R& _' `5 v/ r// Test for an error.   s$ h" |# ~1 w; H  D9 l, E
if (results.isError()) { 0 M; U; M" p' N6 f
  return innovator.newError("Item not found: " + results.getErrorDetail());
4 m; \) B4 o: L% ^4 x2 R3 H/ n2 d  a}
/ O8 ~! u: a( |% z9 p
- m2 m5 ~: z( Z0 o" ?// Get a handle to the BOM Items. ; [! Z3 y/ a$ U( ~7 ?9 a
Item bomItems = results.getRelationships();
* B- Q* V  b# ]% \$ ?int count = bomItems.getItemCount();
) X" f7 I+ [' m* j. ~int i;
2 ^1 M. S1 O% M0 @5 G6 l6 x; a8 t: n . w; @0 b+ G1 M: ^- Y. u& J, Q
// Create the results content.
- x# F' ]' ~- \2 \) Y' q/ m+ L7 estring content = "<table border='1'>" +
9 ^3 P. h6 s3 z$ ~0 w  "<tr>" + ) X9 g% E- q& ~) Q1 x) V3 |
    "<td>Part Number</td>" + ( a$ X! `  h" h; _& ^! G
    "<td>Description</td>" +
; a, i- A' C* ~$ H+ [  T    "<td>Cost</td>" +
$ B: J8 f* i4 D/ U& x4 @    "<td>Quantity</td>" +
( }( i) @3 O* i8 v6 _$ r  "</tr>"; 0 V3 R/ T5 ?8 e7 b

: ~2 @" ]0 g( E9 _// Iterate over the BOM Items. * {2 e% N3 R3 S8 `* Y
for (i=0; i<count; ++i) 5 b, c  U3 Y& ~
{ # K' h: M1 y  Y$ v$ P' O4 }
// Get a handle to the relationship Item by index.
& a) h$ ]2 o/ r8 Y  Item bom = bomItems.getItemByIndex(i);
8 L5 U+ q0 w9 Q6 t// Get a handle to the related Item for this relationship Item.
9 ^( c, C+ ~' m: d1 w  Item bomPart = bom.getRelatedItem();
8 b2 `/ d! i: ?+ n8 P
' S0 J% ]7 f3 d4 t1 t  content += "" +
* v- i, \+ S  J3 v- ]9 e) l    "<tr>" +
- {* {4 p. I7 q6 r: [1 _      "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 A& p1 U! J6 V& t      "<td>" + bomPart.getProperty("description") + "</td>" + 6 B! \; E& T, E8 y1 P
      "<td>" + bomPart.getProperty("cost") + "</td>" +
9 _- @: j# v, n. d* U  Q2 {      "<td>" + bom.getProperty("quantity") + "</td>" + 5 @7 p- y- B( d& n3 }/ _5 w
    "</tr>";
! G$ ?% l! k7 y8 ?( ^2 _}
% Q0 z* a; M. n8 R) y7 c% P: bcontent += "</table>";
& {6 ]' T+ T, N7 X6 \  P* S9 H0 h& V
+ P: T  E5 f# E- S, Creturn innovator.newResult(content); # e: x( D+ ^- e- R" M& s8 z; ^, }

( m% l0 g8 V$ B1 j2 a$ k! H

2 H& f0 L# {% Y& ?
2 L8 P& D% A0 T; R6 B5 N

5 p4 L7 p  {" W# F: i; u8 ^4 z( t' S+ }

$ X) Q9 N+ C& J! _
+ m: \% a& A/ L* z# M" J    Page 46 % R- H9 k- O. b5 w7 n6 d) B1 g

" b; V: ?, Y) }, pCopyright   2007
' J& L0 L" p1 N' fAras Corporation.  
0 l' U4 f0 a% I4 SAll Rights Reserved. % I- t4 k! ^8 P# d6 H; [
VB.Net  
# x5 x$ v6 f- _Dim innovator As Innovator = Me.newInnovator() 2 c* N% n% o( v$ C+ M9 W) v. \
+ H& Z0 o  o# K; ~2 o& q1 y# ~
' Set up the query Item. ; X% \( ]4 s0 a$ w+ A$ I
Dim qryItem As Item = Me.newItem("Part","get")
  h. J9 ^$ p; M( q8 e: sqryItem.setAttribute("select","item_number,description,cost") : h0 g# @8 A$ ]. |7 j. B2 {  C2 L
qryItem.setID(myId)
  ]! G0 W' Z& v0 g: Y ' k" _  ^' h# c! Y+ M
' Add the BOM structure. 0 s( Z, ^9 |1 I) T2 K
Dim bomItem As Item = Me.newItem("Part BOM","get") * N8 Z, Y1 s% \8 g$ u! }
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
6 g3 }$ m& B7 w7 {qryItem.addRelationship(bomItem) $ H) S0 [  d6 m: C' Z1 e

& ]. @- r7 o5 M; I# y' Perform the query.   P$ E' n, F, l, b! @6 X
Dim results As Item = qryItem.apply()
$ g$ l7 Q( u% R1 x. A2 ?+ K
1 C7 Y( v" M* a$ l' Test for an error.
& q2 b, F* K, tIf results.isError() Then
5 W! L/ w  k' V9 U  Return innovator.newError(results.getErrorDetail())
  r0 n4 C3 R( |' u) y) I. x( \" w. @End If
9 v3 }. x$ _7 L8 f& Q5 G- [$ b " _6 F' {3 s! Z- I
' Get a handle to the BOM Items.
! T3 s7 i) p+ T* @7 w0 w5 RDim bomItems As Item = results.getRelationships()
& y: O0 a6 G/ p' FDim count As Integer = bomItems.getItemCount() ) b9 u3 F' {( n' M9 U" L7 ?- ^5 D
Dim i As Integer / Z) K3 b/ |" E7 h' N

6 f% H: Q& ^8 A: M' Create the results content. 6 p, ]& c  I% ~9 j, D. R
Dim content As String = "<table border='1'>" + _
/ @9 {/ z0 n7 [. _1 e  "<tr>" + _ ! a3 I! |6 X5 D9 Z& S7 L7 X
    "<td>Part Number</td>" + _
8 A7 s: m; U6 _: ]: F) v0 v, b+ P    "<td>Description</td>" + _ ( L* c4 m+ M/ m! c/ X: Q: x
    "<td>Cost</td>" + _ 7 F- x5 q$ N3 O1 y0 G# F3 ?, x% t4 w
    "<td>Quantity</td>" + _
$ M7 S% Z$ Y  C/ ~: I- F% k  "</tr>" ) I; T2 ^- `" R  X3 y

7 w! I- o7 J- d' o' Iterate over the BOM Items & }+ M8 ?% W( B8 M- E1 e
For i = 0 To count - 1 & S4 y# O3 g% Y
' Get a handle to the relationship Item by index. 4 `2 c3 a; n2 y2 g* c* ?
  Dim bom As Item = bomItems.getItemByIndex(i)
3 M; Z* K( o1 \3 C  s0 y 4 `2 T" t% D5 ?' e& C, I
' Get a handle to the related Item for this relationship Item. 3 f0 e& t; L1 Q( B7 d, B* `$ K, q5 [
  Dim bomPart As Item = bom.getRelatedItem() : R* E+ z& f4 R4 u% N" C8 G

" s; P) V5 e  p2 r  content += _ " B/ J7 d$ e! M1 t0 O8 S
    "<tr>" + _
- W1 E1 i) T* g$ {      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ , F. Q. i6 M4 S+ {. L
      "<td>" + bomPart.getProperty("description") + "</td>" + _ : D# ^) p: P  e- E
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 3 a; y/ K+ H* E0 l/ s! m. t9 y
      "<td>" + bom.getProperty("quantity") + "</td>" + _
0 _3 i2 S. Q5 v! W6 G( x: w6 h    "</tr>"
' M' ^1 V- H! yNext 2 f1 [1 y% x1 c1 |
content += "</table>"
" [1 G, e, \2 h( E; h  y 3 g. u$ g2 C* l- |4 R
Return innovator.newResult(content) 1 x* s( }% T* a% S6 e6 E7 l
, ]9 K: K2 W1 y2 P( ^$ \1 H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了