PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  5 k* A2 K! p7 _& E# ?& I/ x
To query for an Item and retrieve its structure you build the query as the structure
4 {- q4 Z+ ^0 nyou want returned.  Use the IOM methods to add the relationships you want and 0 r; J& q. Q7 ^3 c# [
build the structure in the Item.  The server will return the structure that follows the
5 ?5 R# t  b/ F' {) |request structure. 4 K; Y- T$ B. S  G
This recipe illustrates several related concepts together, which are how to get a set
# H  }3 C* V1 B, N% ?6 }of Items from an Item and how to iterate over the set, plus how to get the related 7 z  C7 |# A. M# [$ t
Item from the relationship Item.
+ J- A2 \5 B9 e3 R3 jJavaScript  
8 {0 B$ D4 |* p! |  E2 Ivar innovator = this.newInnovator();
8 w' m" R3 c. s1 b' T
5 k# s7 ?3 a- V! a# j  a// Set up the query Item.
+ j* N* f+ q9 I$ C- |' ]( ?var qryItem = this.newItem("Part","get"); 0 J/ n: f' d- B
qryItem.setAttribute("select","item_number,description,cost");
; W9 A' Z2 V& @% }& {6 AqryItem.setID(myId); 3 {2 r- U7 I5 p3 O) a# H. L
6 G0 E9 g" f* d- U
// Add the BOM structure. 5 P! T. i! p# }
var bomItem = this.newItem("Part BOM","get");
& i# b0 }6 F1 O4 ~, k" [4 ]8 |bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
0 Y" i" k$ b- V( r  S8 o  NqryItem.addRelationship(bomItem); : J; a1 x! @$ N/ D
* x9 o0 a& m0 b/ T8 g0 A/ S$ V
// Perform the query. - _) v; i0 _5 y6 P3 g) [+ u
var results = qryItem.apply();
3 z( y6 Q0 I% i2 g . }0 A0 Q3 ?% k, C: g
// Test for an error. ( M0 Y9 G. w. Q& o" U1 j1 S
if (results.isError()) { , A. Z5 m) c+ \) u& Y% q) m
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); / Q6 P/ C* o: [( J; n1 h
  return;
( B2 Q  T0 d, H* N% c} : o) e, a7 P; j
0 p) \; l# b+ z7 d  K1 v
// Get a handle to the BOM Items.
0 k0 y" w4 o6 j3 Y1 v7 [* Nvar bomItems = results.getRelationships();
2 I) Y7 C& n. m; hvar count = bomItems.getItemCount(); + M/ V- j! H$ s& @
( o3 R0 A8 s8 R$ y1 C4 d
// Create the results content.
3 s. q. N6 ^, ~' R& I! @var content = "<table border='1'>" +
/ O! H7 A) i- _; a3 {& ~  "<tr>" +
/ w, s( N8 b+ {( ~: Y$ p6 d    "<td>Part Number</td>" +
6 C7 S0 h/ Q, @    "<td>Description</td>" +
  d. b2 H4 G5 P: ~: ^% ]) \  A    "<td>Cost</td>" + ! [. E7 u, \% S; A3 P' U" g
    "<td>Quantity</td>" + # Z; n$ F  y4 ~+ T: N+ \& o4 L; W
  "</tr>";
2 Q; d. g% _3 t8 N / T+ G5 S' x' t! g1 e- v
// Iterate over the BOM Items. 0 y8 t% v, p9 _6 x/ O; ?: R
for (var i=0; i<count; ++i) . t3 X' }: T' L4 V2 L3 R
{
" L% Y% z: p  S// Get a handle to the relationship Item by index.
6 R0 O' R( p3 T- O  var bom = bomItems.getItemByIndex(i); ' @! P4 m/ l/ c8 ~
// Get a handle to the related Item for this relationship Item.   G, S% r# D' _8 p0 V* }
  var bomPart = bom.getRelatedItem();
' u- [7 V! k7 s6 g ( E. B: o  b! _& c! X6 W0 l0 U
  content += "<tr>" +
+ ^) _) o" Z: w6 U6 o      "<td>" + bomPart.getProperty("item_number") + "</td>" +
2 Z: E7 Y. M( P8 z. y      "<td>" + bomPart.getProperty("description") + "</td>" + , n9 J' h! _( e# R
      "<td>" + bomPart.getProperty("cost") + "</td>" +
- G. F( q' L% \6 B      "<td>" + bom.getProperty("quantity") + "</td>" + # l( X) B' t+ L: H, |, s( u
    "</tr>"; 9 [# v' {2 S7 @  J. f
} . C) k  a, Q* D: V/ ]6 X2 y6 B- O/ J2 T% f
return content + "</table>";6 s5 i0 p. @3 |, J7 f: \

! I+ ]9 G% ?# G" @
0 ?! n2 H1 h3 ?4 x' M9 d
1 Y$ f: S5 ]- n, m0 l1 A, I; x
5 b$ r! a2 }+ ^  F9 N
C#  ) X: [# I2 V) z: r, x7 j+ O7 ~# j! \+ x
Innovator innovator = this.newInnovator();
% L- r: I& F8 b7 e7 d- P 9 b& N! s! ~2 J# I5 u2 t6 o
// Set up the query Item.
) v5 s, |4 o" m% A! VItem qryItem = this.newItem("Part","get");
; y; j5 h0 w/ YqryItem.setAttribute("select","item_number,description,cost");
% Z2 G( @+ ]0 M8 G+ l3 W1 TqryItem.setID(myId); " O" c7 l# T' V; P

: D/ D: }6 c3 M4 T5 W// Add the BOM structure.
: l  p' V' C$ ^$ K, b2 ]Item bomItem = this.newItem("Part BOM","get");
* `. I" b/ Y: m% G9 e3 A& mbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
* G# o# D' Z$ ~; }* |3 ^qryItem.addRelationship(bomItem); , O7 M6 F4 L- ?7 d) A
1 x- W0 S% M8 Y3 R5 P
// Perform the query. ; d9 B9 N( P! Z( v
Item results = qryItem.apply();
) {2 }; _: q% N) @. Y1 z
! g- y3 O3 h; z7 p4 ?0 l' @/ W// Test for an error. 3 d/ u: H' w: v3 s8 L" L
if (results.isError()) { 4 x: S8 j+ j  H& k
  return innovator.newError("Item not found: " + results.getErrorDetail()); 2 o# o& p" [! [; p( _8 _+ v! w- f
} 3 I" A# ]7 m/ Q8 O- A7 ~5 o8 Q* }" T! U& R

+ {( Q0 C% _# S) \// Get a handle to the BOM Items. : [7 ?" Z* R+ e3 k& s. X- M
Item bomItems = results.getRelationships();
6 e* m. C1 ^( c( M. ?% u4 I# l8 Yint count = bomItems.getItemCount(); : t. E/ q, _4 r$ P0 e/ b
int i;
9 T& x5 u( ~  R
" ]& o/ ^0 X( a$ F// Create the results content.
( w" U) i$ V6 g0 Estring content = "<table border='1'>" + / \$ p1 T: [  }
  "<tr>" +
: t) q  a. b% ?0 k    "<td>Part Number</td>" + 5 N- ?! G) Z2 O% J
    "<td>Description</td>" +
$ ~8 W! H9 L0 }+ u8 L* [    "<td>Cost</td>" +
; j( G8 @8 w- E    "<td>Quantity</td>" +
4 f6 E7 G, D5 |" q9 Q7 s  "</tr>"; 2 r7 D  Z( Y" s- |4 T
. ?/ U- c/ k  g4 c
// Iterate over the BOM Items. 1 r% k8 _, p! }: a
for (i=0; i<count; ++i)
- O! P/ n7 f! ?& A{
" c& ]0 c; ]% |9 r- L3 L4 ~) z// Get a handle to the relationship Item by index.
- j( v' L5 }" {& k4 @, i4 @, T  Item bom = bomItems.getItemByIndex(i); ' t% {( R3 m1 T8 h2 k
// Get a handle to the related Item for this relationship Item.
3 Z, F4 o3 _9 v2 i6 |' A  Item bomPart = bom.getRelatedItem();
' _4 N! b! F$ P$ B) B " y+ b* _. G7 J  M/ \$ I
  content += "" +
! T- L0 N  I+ [    "<tr>" + ; D5 Y! g6 j% I/ S
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
; j# y% {% E  u7 x      "<td>" + bomPart.getProperty("description") + "</td>" + % {' t. l3 |- e
      "<td>" + bomPart.getProperty("cost") + "</td>" + 3 A! W6 Z+ K( H1 J' m9 V9 r
      "<td>" + bom.getProperty("quantity") + "</td>" + & N6 c" A8 U  V! G% C9 R
    "</tr>";
+ C* z4 v) Q" M- ^* a+ n} : g9 F* ]. n& w5 o# Z  x0 X
content += "</table>"; ! l5 E7 ^' P1 U3 K
4 b0 {# h1 G+ g$ P* K: ^& t/ t
return innovator.newResult(content);
  n3 L& T" T* K* M8 o
- C9 i- P4 I/ I# z" H3 m

5 d- \+ U+ p- o+ @4 W# ]- E$ ]
" Z6 |, W3 H9 w4 _6 N

5 _7 ^9 o5 P) v1 o) Z8 q) E) V/ w! D! }- U, _% i8 D" u4 F  o

  f. A( e7 ]& [# k/ R4 b# X* z ) x% d* Z1 P$ D3 N; x7 X
    Page 46 1 C' x! Y# T& j$ |5 K" Q

/ ~4 S( u( i& g0 ^: b% p& hCopyright   2007 % M2 k9 F7 ^( A- a+ o9 Y5 Q
Aras Corporation.  
( O3 i. u2 n, F1 S1 X- k7 u* kAll Rights Reserved.
$ b5 g5 q5 |6 e. S6 u, l3 }VB.Net  
4 \% i8 T( U! eDim innovator As Innovator = Me.newInnovator()
: `; T9 n3 `& s0 D, U, C
# \& g5 u9 \6 h7 j0 i1 {2 ?5 M, N' Set up the query Item.
- `) D4 i& F9 E, _( ADim qryItem As Item = Me.newItem("Part","get") 0 V8 L, Q6 D1 {) y) H- o
qryItem.setAttribute("select","item_number,description,cost") ) F% ~2 h% O' N' i6 ^' F  N
qryItem.setID(myId) ' q5 t& c& O9 h' A
8 N  ?$ R! H2 u2 d: d! }' o
' Add the BOM structure.
/ y; g0 J+ Y& l1 n& c+ T1 k) GDim bomItem As Item = Me.newItem("Part BOM","get")
- B2 Z6 g1 A# E( |3 m6 ^' [' BbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 0 @. B- G. n; L2 y1 f/ Y. Y1 V
qryItem.addRelationship(bomItem) 9 T9 @9 V# x+ D$ S1 a( D

5 Y3 F( l( a3 K# f' Perform the query. ! }5 r4 i0 P8 Z" e% S5 p4 ~  v
Dim results As Item = qryItem.apply() 8 o" D* x- o1 A$ \. h  J: l% n

2 T- b1 f5 P: i2 X" _5 ~' Test for an error.
$ B$ y0 U! f) J  r$ _5 L# f- h) \If results.isError() Then 8 T- c+ O5 j/ P0 Y3 a, k
  Return innovator.newError(results.getErrorDetail())
2 }6 r1 S7 M4 L- K' |1 WEnd If ( N- s' D2 E- s6 @

6 A$ i8 b4 P+ ^& a: i6 `9 ?' Get a handle to the BOM Items. % ^( Q* m, E3 E- {' q
Dim bomItems As Item = results.getRelationships()
  V! E3 f3 y4 A' S- qDim count As Integer = bomItems.getItemCount()
1 z9 ]. p/ E" K3 aDim i As Integer % X: b" f% ?* j; f0 Q% M, p( @% E, a
) `8 |9 p8 R9 T
' Create the results content. , [% `- O# H( a: z
Dim content As String = "<table border='1'>" + _ 6 @6 y& h) O' {" h
  "<tr>" + _ 9 }* X+ [, Q$ g0 e8 Q+ T0 Q0 K( U
    "<td>Part Number</td>" + _ - z  j* `: _3 A1 [: ?' @' ^' b
    "<td>Description</td>" + _ 2 O0 T/ w; ]2 F, U8 a  e+ C
    "<td>Cost</td>" + _
+ w; C0 v! S+ M% Y4 T! q8 P    "<td>Quantity</td>" + _ - @' k& K- C$ a* V3 d. w1 S, y
  "</tr>" 1 J2 j: N5 Q+ G

$ J- t; X# {: {& G. n$ J) O+ x' Iterate over the BOM Items 3 g/ V: @% k" J: C5 Z; s5 {, X
For i = 0 To count - 1
  O% y6 ~' D+ I- N' Get a handle to the relationship Item by index.
, d2 F5 Q# z" U# f% U' j4 P  Dim bom As Item = bomItems.getItemByIndex(i)
5 {! G6 N: n7 U( c 8 h  m, F% Y( j2 S
' Get a handle to the related Item for this relationship Item.
, T1 ~+ y* R/ M/ `9 f+ O1 h9 K  Z3 e  Dim bomPart As Item = bom.getRelatedItem() ( V: {: e! Z0 R6 v+ H4 m
- m2 Z/ f- k, L  }! j6 H4 |- N- w  r
  content += _ : g" C2 ^) ]) Z. C% [
    "<tr>" + _ # f( ?+ q! Q0 k* r9 M
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
& H6 m* c6 M* _' r5 ?( P) e      "<td>" + bomPart.getProperty("description") + "</td>" + _ ; _  n: M* c* {9 P
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
$ c6 W3 D, h8 e' s      "<td>" + bom.getProperty("quantity") + "</td>" + _ 3 o) b$ l2 E( ^0 V
    "</tr>"
/ m7 Z1 L) h0 y4 lNext 4 v; W; S3 R7 Y# T5 }! F
content += "</table>" 8 Q* j/ n  Y* M8 R$ I* j
$ W; g6 k7 B6 o
Return innovator.newResult(content) ( [  q7 ^$ G3 s, _: n/ k

) x5 f. j" Z6 a+ j
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了