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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  - _- L; Q% [' Z- p% n  B
To query for an Item and retrieve its structure you build the query as the structure 4 P9 y; x# w. b" e. j
you want returned.  Use the IOM methods to add the relationships you want and . P! X! b  _- a8 ]) {
build the structure in the Item.  The server will return the structure that follows the
" p. V8 q8 j# o: _- }0 ^$ _request structure. 8 \- `) J- `0 m& X1 J
This recipe illustrates several related concepts together, which are how to get a set
, R1 A* B1 }6 O" Xof Items from an Item and how to iterate over the set, plus how to get the related - {' j- X' Z$ n+ j" Z/ f
Item from the relationship Item.
" ]3 `0 Z- H( r0 D: m, kJavaScript  
0 `' q/ t- v/ [" [" o, `var innovator = this.newInnovator(); ! K7 ^4 T" t0 s/ `: b

$ `% a2 Z1 i; i6 S! w4 W2 Y1 k) k( S// Set up the query Item. $ @( Z: }4 ^# v6 H8 @+ J
var qryItem = this.newItem("Part","get");
4 _( v6 D* I! M7 H# fqryItem.setAttribute("select","item_number,description,cost"); 3 O( B$ _& U; F7 Q7 `$ u
qryItem.setID(myId);
5 d2 Z# R: Z* t5 f8 X' U % o% D% E* ^. p7 I% G
// Add the BOM structure. ! E' c3 [# P3 C- Y( P
var bomItem = this.newItem("Part BOM","get"); 3 e' _( P8 E$ X2 A  B  z1 E
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
$ C+ x/ k7 c+ w& _: O; uqryItem.addRelationship(bomItem);
7 Y0 i9 J" v6 w, c; Z! h
" \( E2 v: l; B" X3 U// Perform the query.
2 g$ z8 t2 j7 w6 \  |0 {* i$ @var results = qryItem.apply();
4 ~6 c& r; a' K & i2 d! a* h+ z' x( K) R
// Test for an error.
+ [5 Y( N3 ~) p' vif (results.isError()) { 3 l  j0 N+ K  Q. V) }$ W
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
1 d2 T  _" U9 E  H1 F2 s  A- V2 N: A  return; + Q1 P. b# N" }
} / l8 i. x5 u$ b1 g& {( c, {+ D
, {+ {) h: N- B- P! G
// Get a handle to the BOM Items. ; T4 }$ ?4 t/ }, a$ G4 N
var bomItems = results.getRelationships(); 7 ]. P# \7 Q0 t  Y0 b& f* b
var count = bomItems.getItemCount();
0 v% o6 i5 q- E 2 S% E8 g: X0 P# i+ c& g5 {
// Create the results content. 2 A5 t/ h) c  O% ?# |7 a5 \
var content = "<table border='1'>" + # f0 G+ P9 {- c) `; \3 ]
  "<tr>" +
) O& r, {2 z7 ^    "<td>Part Number</td>" + , J6 a/ f& v8 g' y1 y
    "<td>Description</td>" +
; q/ `% e4 u1 p+ |: I4 H    "<td>Cost</td>" + : G, ]1 q" Q) t2 ~% P6 h1 n
    "<td>Quantity</td>" + * v' e- S' O# J7 v7 V6 O; \
  "</tr>"; ) w; x! e. {7 _! M1 F* F
* z6 F2 \6 v. s0 i8 y9 z
// Iterate over the BOM Items. . \! h2 n. n1 v& N, C/ G8 L- J
for (var i=0; i<count; ++i)
, F2 }, [/ i' X2 \  u{
. w. Y% m- s4 ^8 A// Get a handle to the relationship Item by index.
$ _& Q5 w# j! E8 A  Q+ ~0 U4 u  var bom = bomItems.getItemByIndex(i);
" {1 w- y4 W2 w& }" g! P// Get a handle to the related Item for this relationship Item.
4 S% A7 p. A( r7 k  var bomPart = bom.getRelatedItem(); 3 s) V5 M2 W" z
, L  u  A3 C! a- O
  content += "<tr>" +
# |; O2 [" k$ _+ s; ]8 [, z& [4 u      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 [' f2 K/ W: T, X9 x
      "<td>" + bomPart.getProperty("description") + "</td>" + : [5 B5 X/ O- J7 \# C
      "<td>" + bomPart.getProperty("cost") + "</td>" +
3 K4 D' P- B- S. P6 l+ e: v# H      "<td>" + bom.getProperty("quantity") + "</td>" +
8 J9 O( z1 g/ Q' e0 D    "</tr>"; : ?( V" C* j% G* E* Y4 u
}
% q# h2 v! [) n6 w5 K# z- Lreturn content + "</table>";
1 o3 `. q& R7 b8 u6 C) O1 B7 d4 b# I! }8 T0 |0 C: C4 b. _3 Z

; I) x- S4 S' E# m+ ^- a* G) h: x7 Z" J% f7 a& N1 P% U

6 G( t3 F% w8 N3 uC#  ( z! V8 \& w: R- ]) ~
Innovator innovator = this.newInnovator();
# n# j( b% h/ [/ G7 K 4 O2 f) @( T3 A
// Set up the query Item.
) A5 Z: y  l" u0 @: wItem qryItem = this.newItem("Part","get"); + W2 |- |" X' C
qryItem.setAttribute("select","item_number,description,cost");
0 z( O! J) }' zqryItem.setID(myId); $ R+ P- [" B: @( m, D" T
* ]8 H4 r* i2 Z! M" @5 l
// Add the BOM structure. 6 e; }5 k9 {/ d6 O$ U
Item bomItem = this.newItem("Part BOM","get");
% M8 F, H- `! \9 z0 m: D* G9 ObomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
9 C& k' K1 b0 g$ D1 C% UqryItem.addRelationship(bomItem); , y$ |8 L, L6 S4 s( Q+ \

- U' z7 K$ D+ a// Perform the query. ' E5 @+ I. g8 Y- G# \3 t+ [% O
Item results = qryItem.apply(); # }4 ]$ w. [* S& b

* y' {  s) c' M8 c// Test for an error. : C2 W, o1 U9 R/ P2 W
if (results.isError()) {
8 k, r- f8 l# ]) Z% `  return innovator.newError("Item not found: " + results.getErrorDetail());
2 \/ \" \; Q; L( W$ @}
. b  v3 z0 w- ~" |5 k
! S% b, R7 [0 @& ?' P' n// Get a handle to the BOM Items.
5 x0 p$ ^$ w9 s& \, U0 n3 W+ I' RItem bomItems = results.getRelationships(); 7 ?8 ]* T; z) H
int count = bomItems.getItemCount();
) Q+ j5 e& B$ y6 z' P' eint i; - N) i2 h8 U. H

2 X( N  j: a/ q5 n// Create the results content.
3 e0 _7 ^; v) ostring content = "<table border='1'>" +
$ y4 h. V" u# \* Q  "<tr>" +
* g+ l, d# [& a5 K5 b    "<td>Part Number</td>" + : ]8 h% K& j  G% `$ S8 S
    "<td>Description</td>" + 7 p9 ?" A( `: ?- P+ }5 D
    "<td>Cost</td>" + & L) |' n( I% u6 c& q
    "<td>Quantity</td>" +
6 A% n' c: V/ a: t6 N. {. P  "</tr>";
6 [! D9 Z) J1 G- t6 m2 g) _  R 6 H3 Y- O/ C% g: h
// Iterate over the BOM Items. # O8 K% e! j" b6 s/ K
for (i=0; i<count; ++i)
- e( M; f3 \5 b) r# i2 \- j{
& Q+ }7 ^, ?- s9 A: g: z# w// Get a handle to the relationship Item by index. - P, W* g& N' Q0 R$ B+ [
  Item bom = bomItems.getItemByIndex(i);
  G+ }/ W9 z- I2 ~/ x& z2 r6 O// Get a handle to the related Item for this relationship Item.
+ q% R0 q1 B. {# l* y% X  Item bomPart = bom.getRelatedItem();
- K/ y5 M4 {( B ) E& p, |# L8 @0 t, n2 ~
  content += "" + " N4 |+ r# |' E% L) \
    "<tr>" +
& T# e4 L  y% Y2 P6 ]      "<td>" + bomPart.getProperty("item_number") + "</td>" + " k0 r. A* j- y0 n  P, y2 H& z
      "<td>" + bomPart.getProperty("description") + "</td>" + : N8 I! d$ E2 Y* t' S
      "<td>" + bomPart.getProperty("cost") + "</td>" +
) `# S$ m/ O- \  ~) Y. K0 v/ X5 w6 G      "<td>" + bom.getProperty("quantity") + "</td>" +
; A7 n& L; d- v# y$ m8 i    "</tr>"; & i) Q. R- P! r6 U9 ^, ~! d
} 7 `% v9 `7 S6 _; I$ j& s) \3 j
content += "</table>";
6 e1 K* F: l7 {, _( u7 z2 a $ N) n. Q8 G3 P( X
return innovator.newResult(content); 4 c2 O: B1 G! o  Z$ L' z" n  C$ q
* b4 }7 R: a% M

7 {$ b# m* K+ H5 O9 n1 a# y0 b, m& z+ f

/ Y5 G6 l9 l5 s4 D% {  p
" W" `3 G' t- E- D7 ^* C: x2 Q

9 W6 r8 ]; D' S7 `   Q9 ^" C4 V2 N5 ]
    Page 46
; h# {3 o8 Q% e" t ( p, }. |6 Z8 U- K
Copyright   2007
3 I: O5 L9 r1 u3 X9 ~6 H* H5 CAras Corporation.  
: f) f* P! n% IAll Rights Reserved. ! b! o& Z. b. {
VB.Net  4 x4 m+ `0 C5 @# I6 A) C; h
Dim innovator As Innovator = Me.newInnovator() 8 }; F6 B6 ~4 A$ [% Z2 \/ ]
' J; V' r9 D9 H2 K- [" _7 p/ v
' Set up the query Item. % K2 @4 A, ?/ D0 G
Dim qryItem As Item = Me.newItem("Part","get") . ~. J. |( |7 f1 A* ^
qryItem.setAttribute("select","item_number,description,cost") 2 e; ~4 k" C$ I/ f4 d! U+ v6 E
qryItem.setID(myId)
# k4 J) `, L2 J8 v5 \8 n
3 i: K: C2 A- ~& l' Add the BOM structure.
( e8 P3 F& Q0 Y2 VDim bomItem As Item = Me.newItem("Part BOM","get") 5 y$ {( a, q6 h* b$ K4 j
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; D) w# H! |+ Z2 B  {qryItem.addRelationship(bomItem) 1 o5 F, h: Q4 M
1 e2 j/ x+ i/ G- M. F
' Perform the query. ; n& Z" l: s) \
Dim results As Item = qryItem.apply() 6 e8 z  O6 Q8 a+ x, U& t! I

  Z) @3 H; W3 e; m6 A0 M' Test for an error.
. G) r3 N& g$ c# M% E1 ~* f# NIf results.isError() Then 1 G8 U, r- w- V0 W) L/ O
  Return innovator.newError(results.getErrorDetail())
! \" g$ i- K/ L  mEnd If 0 G/ D9 o" C8 b9 A

/ j, l! L0 P* N4 c0 v6 _' Get a handle to the BOM Items. 9 f1 y7 D8 I- v
Dim bomItems As Item = results.getRelationships()
, C6 a2 B9 K3 r% ]; Y+ K* ~2 E# NDim count As Integer = bomItems.getItemCount()
6 i& a6 K# e. x* M5 oDim i As Integer
% ^  Q4 l7 n& d: I - k" w2 j& B. L; G! }/ e0 U
' Create the results content. $ [/ C) Q5 k: q- B0 ~& K/ B2 m: C
Dim content As String = "<table border='1'>" + _
- Y. [  Z$ n! p7 K$ w/ y  "<tr>" + _ 0 I  R  q# n( a# O( K
    "<td>Part Number</td>" + _ ' i) P  U7 R4 c
    "<td>Description</td>" + _ * K5 o& \+ y7 u+ Q, e" }
    "<td>Cost</td>" + _
  k/ _5 X1 A8 P4 Z- E. [9 N/ ~2 F    "<td>Quantity</td>" + _ 2 H9 G8 m$ V; k0 F0 w& _; k6 B
  "</tr>"
) n) G* [, N/ @1 G4 R
- U$ K9 p' f$ j" Q7 I' Iterate over the BOM Items
9 W0 F# S9 y6 k1 _# ?7 p' t1 JFor i = 0 To count - 1
' D1 ?# H. i' ]6 w% e' Get a handle to the relationship Item by index. ! N+ |, {& X3 r% r5 H# q
  Dim bom As Item = bomItems.getItemByIndex(i)
: T- t: e% z4 B+ l8 J5 u. ]
3 w' C0 C7 m" w* p, z7 j/ ~. r' Get a handle to the related Item for this relationship Item.
/ {9 z0 b4 c0 v. J3 q. c/ K  Dim bomPart As Item = bom.getRelatedItem()
  H+ f2 i# ?1 u2 ^ 5 Z5 N. G2 z2 n) Y) K* Q0 T
  content += _ ) I7 g- E2 P. ]1 L) K# l# E& f
    "<tr>" + _
5 a( f3 q% D* F7 F      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ - o1 Z; }* S7 y/ P; c9 \7 h" {# h
      "<td>" + bomPart.getProperty("description") + "</td>" + _ 1 S) f/ f1 F7 r" w
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ ) g1 M  e0 G1 C" B# d3 ]2 k- e
      "<td>" + bom.getProperty("quantity") + "</td>" + _
/ B4 n) R& s- z* L+ N    "</tr>" 5 M/ h% M1 z) p6 }4 H
Next $ r6 E5 x; T, T0 b7 G7 x5 u
content += "</table>"
% _4 y# m/ w, {9 Q % T1 n' ?) M) V8 q* y, \
Return innovator.newResult(content)
6 _3 S/ F' U$ {3 D( Y# B/ P
% N4 x# M, q/ z4 y5 n
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了