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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ) H2 X. n, A# g9 U% ~1 m
To query for an Item and retrieve its structure you build the query as the structure
& M  r; h+ [9 P6 ]you want returned.  Use the IOM methods to add the relationships you want and 9 D# m; H6 H% b. S, H  y
build the structure in the Item.  The server will return the structure that follows the
5 m! g6 v. r3 l! L9 C: w5 Prequest structure.
9 v: R! X: H) ~" m- T# EThis recipe illustrates several related concepts together, which are how to get a set
7 E8 O* v" Z7 s' k& mof Items from an Item and how to iterate over the set, plus how to get the related 1 G2 ^. x* Y5 ]
Item from the relationship Item.
9 `: o* Y0 y% [( tJavaScript  
! C  V) X& l& @6 A; Vvar innovator = this.newInnovator(); : l/ k- o  I! G# u& A0 m* f
2 E% L$ M/ _% f7 T
// Set up the query Item.
' @' t6 v, \) ?; z: evar qryItem = this.newItem("Part","get"); # ^  S) C5 m- M+ u
qryItem.setAttribute("select","item_number,description,cost");
1 z+ }6 M& [% ^qryItem.setID(myId); 5 k. F9 n# @9 @2 v- P$ G
, d9 S% P, H  |+ K
// Add the BOM structure. 1 O  F9 D, Q* {: a4 C
var bomItem = this.newItem("Part BOM","get"); : q/ k: [, N, G; n' G  v
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
2 h' B5 N6 e' A/ GqryItem.addRelationship(bomItem);
5 x) _. ]5 P( J5 x0 `. K; F* j' E( c
" P: N- ~1 D) I# w1 r// Perform the query.   ?) g# F) Z: W
var results = qryItem.apply(); $ N7 p- a! Z* H( A& {* W5 w
! n1 n# i( }  E! Y5 A
// Test for an error.
( w  S7 m* q7 I4 e! P# rif (results.isError()) {
: {% D. B# h. n* H  top.aras.AlertError("Item not found: " + results.getErrorDetail());   t4 ~* Y7 E. D+ ~" z8 M3 \+ c
  return;
! H( C) a; s3 J1 j} 4 C# [% G1 r2 h- ?: x* n

8 Z5 Q" W: o1 t6 \1 c. d$ T1 \: ^// Get a handle to the BOM Items. 6 |; ?" i% Q9 y' l' Q
var bomItems = results.getRelationships();
7 K' R- }1 g  q3 Gvar count = bomItems.getItemCount();
% v. R# ^+ F/ U3 X * @+ p# C$ n9 {+ n' `% s* D0 H
// Create the results content.
9 N- T( D6 p+ z! O" F- x* U6 lvar content = "<table border='1'>" +
2 g' ~; W! _. N  "<tr>" +
) @% ^) T- l) k/ R    "<td>Part Number</td>" +
& W5 J- N2 L8 r0 C7 X. B    "<td>Description</td>" + 7 H8 f& e0 X. Y$ Y5 R
    "<td>Cost</td>" +
6 R7 l) B* K4 r, {/ }2 t" Q1 R    "<td>Quantity</td>" +
9 K& [) z0 E3 l9 M- W' B  "</tr>";
, ]0 J" a. `$ N7 d
# K! [, D8 }$ U7 Z3 I. `' ]// Iterate over the BOM Items.
+ X2 q7 D4 H! ffor (var i=0; i<count; ++i) # w' N. S" H  P' N
{
6 S3 z3 u+ n( `) B8 p// Get a handle to the relationship Item by index.
7 j1 h. G% `/ {. {9 q2 |  var bom = bomItems.getItemByIndex(i); ( b" B$ u/ ]" a8 t# D
// Get a handle to the related Item for this relationship Item.
7 C, m# a) C+ I+ {4 d( E- C  var bomPart = bom.getRelatedItem();
, Y, J3 V; Q9 i5 z
8 |# U2 ~  e6 R5 A  content += "<tr>" +
5 [2 o1 _& X% _3 k  P$ M      "<td>" + bomPart.getProperty("item_number") + "</td>" + , i+ l8 d! x8 ^
      "<td>" + bomPart.getProperty("description") + "</td>" + - S! }. U! U, l- @
      "<td>" + bomPart.getProperty("cost") + "</td>" +
/ }+ A% B3 A  d3 ~( i% ^      "<td>" + bom.getProperty("quantity") + "</td>" +
5 K. y' T  ^8 z1 y. T9 U/ j    "</tr>"; * W: n; v- I, r* e4 @
}
2 [1 E5 d/ a8 E5 b* ]+ F& areturn content + "</table>";/ R  l8 _3 Q. K) A

& k' D. U: W4 Y6 q" A2 I/ U
" Y9 {! N& k" U5 F  @

4 j$ N/ x- |1 O* J/ ~) `9 \- y
# G4 w! F( c3 s! {0 ?! g
C#  
! G, A3 R. a7 H+ _2 pInnovator innovator = this.newInnovator();
3 d3 l8 E5 U% E- n# t2 w; U) }2 U
) T% a+ }; [9 V' V// Set up the query Item. " I/ T0 V+ K$ Y* c* F) q
Item qryItem = this.newItem("Part","get");
! }+ x- R! r/ [2 AqryItem.setAttribute("select","item_number,description,cost");
/ m  U! a' o4 a, e, R) h- H0 MqryItem.setID(myId);
: H4 a  f4 K6 K+ E/ K % K3 P& }7 i2 r, ]8 J5 r1 K
// Add the BOM structure.
7 c; c* Q9 v0 u4 xItem bomItem = this.newItem("Part BOM","get"); : B0 ]% K) `4 F3 W3 |2 A+ b
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
" ]$ d# K8 x* m9 w1 x+ l" w6 Q9 ^qryItem.addRelationship(bomItem);
6 O5 m( F# f' c/ g% B; Y' b
! r* {" M$ |; p4 [0 w. U2 ]// Perform the query.
1 X' \4 F, r2 I+ W4 R6 xItem results = qryItem.apply(); % |; I8 _  ]3 \2 y4 T

9 x; P; P6 S9 {1 x6 A. A- t  w9 y// Test for an error.
) n/ y- I. Y& P/ n" bif (results.isError()) { : i$ B/ Z# t: m. H: G
  return innovator.newError("Item not found: " + results.getErrorDetail()); 8 J" r" S; S& n$ |# p" R: Z$ W- q
} & L1 k3 @) v: @- e% S

" B/ _) C, I. B// Get a handle to the BOM Items.
2 d" M: ^5 p  L* f& l) EItem bomItems = results.getRelationships();
+ e, t/ I6 J' S. dint count = bomItems.getItemCount(); + s2 ~& a6 V. b2 p! ]  u% M. w
int i;   V4 O. O/ P6 \; N, \6 e

$ y- j  I* l' c6 u8 o) p& J// Create the results content. - Z4 I- f+ Q! p5 h5 k
string content = "<table border='1'>" +
3 c  g! P' C& E& b  "<tr>" +
$ c. r, {3 ]/ \    "<td>Part Number</td>" + 6 ^  y2 Q6 R1 u9 K) ]1 w) F4 F) X
    "<td>Description</td>" +
. U+ s  m. _- O2 v3 l* c    "<td>Cost</td>" + ' a9 q2 v1 X5 ^) G2 f
    "<td>Quantity</td>" +
% b4 l( y* Z# R5 T, L' E( V: y  "</tr>"; 7 n! y- ^2 @' y9 R9 T, J3 p7 J9 w
' l' u( r  C" }; u/ v4 F
// Iterate over the BOM Items.
# @3 N9 z  q8 H0 _! a- n% zfor (i=0; i<count; ++i)
# d+ x% c  a" q% j{
; A: n' X0 R' R" O* E; E: Q7 c// Get a handle to the relationship Item by index.
: v+ A- v# A) R$ J  Item bom = bomItems.getItemByIndex(i);
, N% M" o# K/ F& ?// Get a handle to the related Item for this relationship Item. / j, @$ J4 l: W2 {# G
  Item bomPart = bom.getRelatedItem(); / W# d; B1 n% v9 q2 o3 H* [" U
# L+ _' l8 _8 C1 d9 M+ K
  content += "" + 1 s9 V' a* u9 R1 L
    "<tr>" +
, X' k, z( l7 u8 g      "<td>" + bomPart.getProperty("item_number") + "</td>" +
( q; T% l) S& I0 b* i$ l      "<td>" + bomPart.getProperty("description") + "</td>" +
. {8 ?4 y' n8 [  r8 {" c& u7 g      "<td>" + bomPart.getProperty("cost") + "</td>" + $ _7 R7 c' r  e
      "<td>" + bom.getProperty("quantity") + "</td>" +
' n/ P" G8 k: \& N2 _0 F    "</tr>";   H2 M. M# }# \: y7 N+ P
} # D) y: Z( e, G2 t" t0 k2 G
content += "</table>"; : A* w4 m- s: G% W1 E: _! V

! S, w# ?! a. h) B! ^% ]return innovator.newResult(content); & G- s0 }2 g% j) G# K) ~

) d) X/ L. ]% I, Y$ ]

5 y: J- \0 J- @7 {0 V
# W- r( d/ i/ [, }# w9 `$ H
6 _1 J# e: t4 Y* V  V
4 k; U# r/ G1 X0 s

( {1 z1 c8 u& L& ? % ]& }! o4 Q8 J
    Page 46 % K$ L9 g' y: c& I2 _+ D. i1 ?

) x8 V0 p3 A* vCopyright   2007
! _. d: l# O& Q8 ]" ^' q9 WAras Corporation.  
" j5 x3 m2 [9 m1 c6 D+ yAll Rights Reserved. 0 g( I+ x9 u% i  M
VB.Net  
8 W; q, S: @, tDim innovator As Innovator = Me.newInnovator()
3 D5 G) \# p) W! J  Q
9 [  \# E' r% o: Z  ^4 N0 H' Set up the query Item.
: Y) U* F! Y; B- L0 B/ CDim qryItem As Item = Me.newItem("Part","get")
& V/ u/ k4 r' L7 ^$ EqryItem.setAttribute("select","item_number,description,cost")
# T; R- }: f8 \+ BqryItem.setID(myId)
5 q: M$ s. d3 ] 0 K/ z* N' j* e& u' l8 i
' Add the BOM structure. * V; K6 I9 M" U
Dim bomItem As Item = Me.newItem("Part BOM","get") 6 q0 R( \2 O" u" r6 N; K+ B
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
; R6 I% W7 Z* i+ U3 JqryItem.addRelationship(bomItem) 1 e8 v+ ^9 F$ N- v- Z$ y) [8 ]

% h( ?- z2 T# j2 M& m/ i* ~2 y' Perform the query.
* ?/ h; r8 ^3 W* p. bDim results As Item = qryItem.apply()
& {/ v! ~/ P( y5 J7 d 7 K$ b3 {$ A- c2 F
' Test for an error.
- o8 x  }7 B" pIf results.isError() Then
' p! {$ \8 G# J/ [4 T7 F5 g+ |  v1 ?  Return innovator.newError(results.getErrorDetail()) ; Q9 C# T6 h8 d. ?) X/ y
End If ( O1 ^9 k* F0 A. t' Z' G; v* u2 R

, l5 U, o8 e# F8 k! _' Get a handle to the BOM Items.
7 i' A( V/ C: o7 G+ I+ M1 wDim bomItems As Item = results.getRelationships() 8 T1 L7 K  C" A/ i
Dim count As Integer = bomItems.getItemCount()
5 y3 Z: q& W, ^9 hDim i As Integer 3 X/ M" j5 ]) n! {$ [0 e
, h& J3 h+ s3 k5 ]4 q' Q+ s9 |$ Q
' Create the results content. 5 o0 y3 M0 D" P4 ^4 [6 P
Dim content As String = "<table border='1'>" + _ 8 M* ]+ N$ Z- K3 N  W8 x
  "<tr>" + _ , d8 ]2 M" U/ S4 U+ C0 ~4 o( [
    "<td>Part Number</td>" + _ & }0 ~" L; w1 k
    "<td>Description</td>" + _ " _! U+ ^9 t' R  o
    "<td>Cost</td>" + _ 5 V$ O4 \% o) P) G  |# c/ S0 a
    "<td>Quantity</td>" + _ ; W" @% ?6 k3 Y: r9 ^
  "</tr>"
+ `( e, _3 M% m, `+ A3 A$ S 4 T( S+ h5 u, Z4 d  O5 i
' Iterate over the BOM Items 8 |- \" k9 o" r, C8 C  h3 _
For i = 0 To count - 1
1 i. c4 O4 k* P% A* l' Get a handle to the relationship Item by index.
+ ?3 G5 K( ~$ V1 H2 Y5 s' M) Z  Dim bom As Item = bomItems.getItemByIndex(i) 4 W5 P. V3 n8 i0 m1 J: P

/ b. x% P7 l+ \/ m3 C8 Z' Get a handle to the related Item for this relationship Item.
6 @" |: \' a4 W4 i  Dim bomPart As Item = bom.getRelatedItem() ( C! \1 m0 r/ R* ~  l3 ^5 ~
- K/ a0 W' u! v( \/ G* B
  content += _ ) b, C; |# o+ B
    "<tr>" + _ 1 _" o" k+ r6 Y
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ $ R9 f: F" V3 I/ a6 \7 Q
      "<td>" + bomPart.getProperty("description") + "</td>" + _ % N/ {* L5 u( q0 |8 P" d+ j; w
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
1 t, k5 {. ]( I6 u      "<td>" + bom.getProperty("quantity") + "</td>" + _ ; c0 }9 y" a, k: X! g; W
    "</tr>" ( H; P4 i! z( i- h- V
Next ; g# i2 o4 m3 w* B+ q% r
content += "</table>" 5 d6 z. I4 q- R

$ }3 H' p/ v, U( y6 D! ]/ ^) _Return innovator.newResult(content)
. w4 B! D! I2 Q% A5 |- J
' ~7 G- G+ L1 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了