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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
5 M( L: D7 Z  A5 \To query for an Item and retrieve its structure you build the query as the structure
% D8 P1 h1 u; t3 _you want returned.  Use the IOM methods to add the relationships you want and
) z7 @2 ?: a/ j4 Y% dbuild the structure in the Item.  The server will return the structure that follows the
+ E* m, t- b' I  ?1 e( prequest structure.
, u/ b) H" O/ y% F" t5 WThis recipe illustrates several related concepts together, which are how to get a set
! e7 w7 ~4 C9 F* v( Cof Items from an Item and how to iterate over the set, plus how to get the related ( h4 M( h6 V, c0 s
Item from the relationship Item.
; @4 H" N' n' h& s! r! f& JJavaScript  & ?, C, j4 ?0 w& t* l
var innovator = this.newInnovator();
- I3 l$ I# d3 h; b9 m' E2 u) s, j 6 B3 s( A  ~3 Q
// Set up the query Item. % F; \' D, p; j
var qryItem = this.newItem("Part","get");
' a$ A% y3 ]" k8 FqryItem.setAttribute("select","item_number,description,cost");
  t+ E$ }8 O6 ~% j+ ^qryItem.setID(myId); & o) ]0 W1 n/ w8 H  L) R

  |3 m; H% A/ v// Add the BOM structure. 0 R  d' P/ u' [4 q+ g2 F
var bomItem = this.newItem("Part BOM","get");
. C" |& @. d! YbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); % i  J& k( {& s0 q2 H! F
qryItem.addRelationship(bomItem); 8 A( d& @  \+ N; D% k! v* u
5 B* I0 f' r- V+ W5 t6 E  j& N, `! B) D
// Perform the query.
. C9 W# B  h# K% @, v: W! t' U8 b8 @var results = qryItem.apply();
/ M9 x9 ^9 c+ A( H: Z" p/ g( a  } + D4 Q# q3 N# q5 l! R8 y  E
// Test for an error.
$ |9 c% \' l$ R+ `0 Yif (results.isError()) { % Y. I( f( F3 e+ ~, f4 `5 r9 n  A
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
* R# n5 O# q7 ~" W+ q' G: H) f$ S% @  return;
: e6 K- ?5 ~, J, l* \. R: `6 X) Z}
$ J8 P- {( N3 E$ c; `! A% W
& N* C- l8 R. K4 v! @" K- x// Get a handle to the BOM Items.
" A( v7 {, {. p* i) ]0 pvar bomItems = results.getRelationships();
* Y! K7 x: M# j( T9 x6 Qvar count = bomItems.getItemCount();
6 D5 |7 G7 i' Z- K2 _ 2 m9 ~9 O& H0 y
// Create the results content.
% d. M2 B6 ~  i' ?7 c6 hvar content = "<table border='1'>" + 5 `7 V1 P0 K( q7 e
  "<tr>" + ' n" G7 D% N/ ^$ O7 n
    "<td>Part Number</td>" +
8 K. W5 B2 E' s* N6 r& @) Q. t    "<td>Description</td>" + * a. t0 K8 M) Q' s. A: w$ ?% a
    "<td>Cost</td>" +
4 P) ~) o4 {8 ~, h( B5 ?    "<td>Quantity</td>" +
  O5 Q% i9 K. n: I; G  "</tr>";
8 T& m: T5 e8 u
* L( D  W; M$ l& f: s// Iterate over the BOM Items. 5 J/ s6 L% @7 K: V* F6 }
for (var i=0; i<count; ++i)
& N& {0 ~5 R) _# s{
$ u& q) i- E7 u$ l  W: }// Get a handle to the relationship Item by index.
2 Y6 N) V- K, v  var bom = bomItems.getItemByIndex(i);
5 p, Y1 O: a8 N9 |// Get a handle to the related Item for this relationship Item.   c& {/ Q3 V! m3 z1 p. G
  var bomPart = bom.getRelatedItem(); % J9 V) }& T$ U  d+ \
) J5 e8 C, b$ W2 g, x/ U8 u& b
  content += "<tr>" +
) i% R, u! v- H" H5 [. v      "<td>" + bomPart.getProperty("item_number") + "</td>" +
( I0 B; y4 v  X! ^8 [      "<td>" + bomPart.getProperty("description") + "</td>" +
8 u6 b7 i! P! w      "<td>" + bomPart.getProperty("cost") + "</td>" +
9 }9 O% X# W' ~7 _3 d" [* N3 j6 D      "<td>" + bom.getProperty("quantity") + "</td>" +
5 q1 ?' ~/ P" M. @3 B' ?    "</tr>"; 0 E& n6 x6 R5 j0 p% l$ u* r% t' `
}
; i- f  |, N, ?return content + "</table>";8 ^) p* r/ N7 \$ r) [% H
% |7 o: U$ u2 W' n. O
& x+ u: p! I4 Y, ]; ~( ~+ u8 D: ^
! j. [6 w! a. X1 A; }3 |+ R
1 {! P% r/ j, Y+ W1 T4 W
C#  
/ P8 q( X* Q% ~! t+ xInnovator innovator = this.newInnovator(); . T7 L+ W$ B% E

' |. i& c, S( v0 x, K' z// Set up the query Item. & w. b8 r  q& q  w7 K
Item qryItem = this.newItem("Part","get"); & {3 f5 }  F+ z
qryItem.setAttribute("select","item_number,description,cost");   c  _4 `# \( _* q2 z# h0 }
qryItem.setID(myId); , [8 G3 ?& t( Z6 k3 S
9 [  l4 f7 G& K) _9 t0 [) t
// Add the BOM structure. / |  ^$ k. M9 P
Item bomItem = this.newItem("Part BOM","get"); ) A# S3 s; ]* O" C8 f. S" i
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); * v7 ]9 e. {6 j6 Q$ q1 g4 e
qryItem.addRelationship(bomItem); % a0 q9 _* T1 \* j( u9 C" \
! N- b- B% [/ c, [6 @) ]
// Perform the query. ( C& b; ?- @" s. _: t7 p
Item results = qryItem.apply();
1 F& V: h; b; `. Q 0 o8 U/ a' u5 n" C2 O: i6 J
// Test for an error. , o' @* Q  E& }$ U# X; R
if (results.isError()) { 8 F, Z! @4 Z* j+ V9 {3 N$ ]
  return innovator.newError("Item not found: " + results.getErrorDetail()); : |* ?( @' Q7 c1 U& W! r; B2 K
}
% Y. P3 t, e( a - P/ s  |4 i8 K' b+ w4 P
// Get a handle to the BOM Items.
. ^/ o" Z+ |5 i& ZItem bomItems = results.getRelationships(); . w2 r* C8 u1 A. [) N/ J
int count = bomItems.getItemCount();
' ?0 R6 d% Q& I# @% h- S3 F( Z0 Eint i;
) a2 y) w/ L) b. e; X) p& j
+ g/ V* R5 h1 x2 z, J// Create the results content.
' O: _5 Q0 i0 lstring content = "<table border='1'>" + 9 ~1 n4 ^* w$ K9 v" _
  "<tr>" + ! d) m+ I2 e; {: f0 h
    "<td>Part Number</td>" +
" o. ?7 G5 r4 n6 Z    "<td>Description</td>" + / W, v  ?0 t; X5 A/ T6 U
    "<td>Cost</td>" +
7 d) Z& k( v' n; L' v    "<td>Quantity</td>" + . d5 |  F; }  }, K9 ?# E9 ~
  "</tr>"; 0 l3 M" D1 w$ v9 s" d, ]# O

4 G* E5 v5 Q& z4 o" X// Iterate over the BOM Items.
1 K& |, m/ u* u2 J% M! rfor (i=0; i<count; ++i)
$ a0 u- m2 F' f/ n3 b' n3 J+ X{ 6 l  f- e# P* b5 F
// Get a handle to the relationship Item by index.
8 f& j: c+ E1 o  Item bom = bomItems.getItemByIndex(i);
! a$ `- x2 c7 d! l3 ]+ r// Get a handle to the related Item for this relationship Item.
+ F( M6 J$ g5 e0 O1 s" d  Item bomPart = bom.getRelatedItem();
0 v# R- }9 t8 }1 N  f 1 h! W/ T( c" K& r& j+ t
  content += "" +
! N. O4 r- T: r& t    "<tr>" +
2 J/ z5 Q4 o" C- I, E7 r" m# g      "<td>" + bomPart.getProperty("item_number") + "</td>" + 5 Y1 W' _5 J% z+ m3 u3 C. ?
      "<td>" + bomPart.getProperty("description") + "</td>" +
7 r* H5 h1 \3 \# Z7 N      "<td>" + bomPart.getProperty("cost") + "</td>" + 8 {* l. m- R# l, E* F, u
      "<td>" + bom.getProperty("quantity") + "</td>" +
' b- g# B% q' W    "</tr>"; 3 \" \3 m4 J  g8 u# C/ l3 J" ^  g
} & b$ V  J" z* G" ]0 g# @0 I1 v2 b7 [
content += "</table>"; & S5 E! T  }: s/ P0 R

: v' w' }6 O' l0 v8 Wreturn innovator.newResult(content); ! l8 j% U& ?: K1 @; T4 i

7 N/ I) o' K5 ?. c* O- ~

% w4 L1 u9 A" q" y8 l4 R: R! p

# {, n2 G$ t$ V  h1 x0 r
4 t2 Z2 @- y$ {  n% Z$ E# b. M0 K

6 x2 g9 K  a5 @ ; x+ M) X1 S: g$ u) S# r
    Page 46
3 Y/ B$ j9 o1 h/ G# D' l% [
* Z- R9 J) Y( J" yCopyright   2007
  z5 D5 X; P8 G8 GAras Corporation.  ( b" s, T! v9 r6 i8 ]
All Rights Reserved.
' l# y4 e% Q- V5 O* m: _VB.Net  1 j4 V5 H6 g6 j! F8 o4 e
Dim innovator As Innovator = Me.newInnovator() # N, ~7 Y# M5 m: X6 g4 |* \" f& u4 P5 }
8 S$ i( j$ W9 k; r$ g
' Set up the query Item.
6 f& B1 N( V  ^6 MDim qryItem As Item = Me.newItem("Part","get") ! p- Z3 h5 u! z( d; X6 O
qryItem.setAttribute("select","item_number,description,cost")
7 \: h) a6 I" _8 \1 L' k  b) qqryItem.setID(myId) / a$ C% j* j) d! ~0 C7 M8 f6 U$ w

6 w: G9 p; G5 i, `- m' Add the BOM structure.
, n; Y$ Q, Y% ^* f7 @Dim bomItem As Item = Me.newItem("Part BOM","get")
+ }" @4 ^, p5 D( _bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") / d( ~" T  X8 S8 |7 G5 E/ G
qryItem.addRelationship(bomItem) % H0 a4 v( f6 A2 l: m; o* o

$ `9 d: [  |) y! C, j; X/ i, {' H' Perform the query.
2 d# K" v) p$ q. O; mDim results As Item = qryItem.apply()
1 \- ?& u# c' G- A& n 1 r9 @# `  Y5 b' v
' Test for an error.
7 o, y9 A2 w* s1 S+ FIf results.isError() Then
; f& w8 G" E7 t. |  Return innovator.newError(results.getErrorDetail()) ; a5 E- d  v8 |- q4 G. `: J
End If
3 \. E  t( V' I+ W& L 7 K/ ~0 P6 M" ~# r
' Get a handle to the BOM Items.
- ^: q) \5 l' [7 c  EDim bomItems As Item = results.getRelationships()
+ H) |/ q) k5 K! d4 b# Q" l( ]7 O# `Dim count As Integer = bomItems.getItemCount() 7 ~. j& t% h3 b! _+ v, F
Dim i As Integer
9 O1 S; ]$ H9 ^$ P
  Z3 \2 Z$ n: Y( L6 r% f' Create the results content. 0 A: d  W* P/ B# |( O
Dim content As String = "<table border='1'>" + _ ( r) b: G+ _& b
  "<tr>" + _
! M+ j8 L5 U# Q2 Z    "<td>Part Number</td>" + _ : W  M7 w% U' T/ e- n
    "<td>Description</td>" + _ 9 u4 U! o. g6 n4 F
    "<td>Cost</td>" + _ 8 d7 b4 G& d5 I/ D6 N
    "<td>Quantity</td>" + _
4 B- g& B  b% K9 |- _" J/ N  "</tr>" ; r8 a7 F  @# u" }: j9 l: L& P
: P5 V. _2 R) ^1 v. X5 M
' Iterate over the BOM Items 3 S! y7 O" E' u
For i = 0 To count - 1
) p9 f; h  h- X6 ~4 R1 ?' s' Get a handle to the relationship Item by index. 9 i( t3 I3 r. I! \- z; \9 }. @' Q
  Dim bom As Item = bomItems.getItemByIndex(i)
/ _$ M6 E* I% J* u & I/ u' f* ~5 u7 m1 E9 |) A: l: r
' Get a handle to the related Item for this relationship Item. 0 \  ?( Y: u9 S: Z
  Dim bomPart As Item = bom.getRelatedItem() " [/ }: q- k" S7 H0 L
$ K2 W. G4 z0 A  N8 [
  content += _
2 J: K( i9 D* \& h5 L    "<tr>" + _
  N  i) O, m! t: O0 B# K      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 2 K  ]- B7 c4 ]  D! u4 y+ E- H
      "<td>" + bomPart.getProperty("description") + "</td>" + _
! X8 o9 Q. o; m1 M+ c! _      "<td>" + bomPart.getProperty("cost") + "</td>" + _ - h# G4 p4 J) K
      "<td>" + bom.getProperty("quantity") + "</td>" + _ % r  I( p/ z- t% A
    "</tr>" % F0 M; ^& d; X' G
Next ; e! }! u" I3 m9 x
content += "</table>"
6 o; b; ~8 R& G  x! y
% |5 r# j, B  t, m7 q( e7 XReturn innovator.newResult(content) , \2 C3 N8 T+ @5 C
9 {: C6 S- \$ d! d
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了