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 1501 0

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
% l) ]" u* W8 u" vTo query for an Item and retrieve its structure you build the query as the structure
  _3 X3 V( A1 Y! }4 Syou want returned.  Use the IOM methods to add the relationships you want and
7 s- h1 y9 f, bbuild the structure in the Item.  The server will return the structure that follows the
, P  s4 ]; p" C: u0 [request structure.
) @  t9 _+ G8 x. T$ RThis recipe illustrates several related concepts together, which are how to get a set
. f( L: m& Y. @6 r3 \; B$ K) h5 Jof Items from an Item and how to iterate over the set, plus how to get the related
" h  `* `9 C9 `# ^3 eItem from the relationship Item.
/ z5 B8 S1 M5 A3 M7 y1 q4 dJavaScript  
# C! K$ k+ T( G* K2 C. u+ Fvar innovator = this.newInnovator(); $ F2 k8 O( L" g/ s
1 q9 ?4 u, @2 X  p+ ~& j3 `& {) Q
// Set up the query Item.
* c3 o2 Z" U' Y, O3 E+ I* a: D9 }var qryItem = this.newItem("Part","get");
8 d# y0 n) w3 x- [3 I" e7 @3 \qryItem.setAttribute("select","item_number,description,cost"); $ o" t: S# ^% w5 H5 ?% {) N& y
qryItem.setID(myId); / ]0 Y) b* k6 a

' q4 o! s+ f& S* i* [// Add the BOM structure.
, B4 J4 _. c* X! f+ t; Svar bomItem = this.newItem("Part BOM","get"); , U" B( ]* M/ u" }# t/ v+ T
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
; u7 w, l' `* @5 d2 u9 p9 p& qqryItem.addRelationship(bomItem); $ C3 d; j& G' j3 |

  x, S$ x, P3 }0 U// Perform the query.
4 O+ k  h' E. X' wvar results = qryItem.apply(); " u% w8 [$ z4 \' G; c6 g7 T! C
) t) R5 {% i0 H1 T3 H- _, E- C
// Test for an error. * _: v! c: `4 O! Z7 K% s( L% H
if (results.isError()) {
1 d0 @$ @& z- m  top.aras.AlertError("Item not found: " + results.getErrorDetail());
0 h$ e# E# m2 x9 z8 N2 Q" y  return;
/ {% V/ v. p: i2 P% f$ @+ _5 B}
0 w6 Q) @7 R' O/ s1 o5 r! E0 `
5 e* C3 T2 B/ A4 P% o1 S! C// Get a handle to the BOM Items.
$ v( c( A3 z4 vvar bomItems = results.getRelationships(); & H1 G& t8 D: P
var count = bomItems.getItemCount();
& V# ^1 E+ W7 Q7 @5 G4 n- n
) I1 F  ~: _  c( ]+ J0 c# E// Create the results content.
4 Y. ^$ @. f1 n# gvar content = "<table border='1'>" +
& ~8 S5 |# p' O* u6 T  "<tr>" + - T& w- G; ?& `* m* G
    "<td>Part Number</td>" +
2 h# Q' g% [* H    "<td>Description</td>" + ( z5 k% p6 \. B: t& D' h6 `
    "<td>Cost</td>" + / R) ^& o8 z2 f9 S: c% p0 d6 b
    "<td>Quantity</td>" + % {! b* R, ^( V  M
  "</tr>"; ; `. a# ^6 S, O& k6 g0 b1 r* o) C/ z% |
& U9 @' ~5 g2 X) W
// Iterate over the BOM Items.
7 V" s( p7 Z. E9 N* H% W( xfor (var i=0; i<count; ++i) + E3 X# f( E7 T: [) I
{ 2 B$ ^8 a  `1 e# h
// Get a handle to the relationship Item by index. 7 T0 x6 O' P- U  r! g
  var bom = bomItems.getItemByIndex(i); 1 V' G* ?( n: U& X
// Get a handle to the related Item for this relationship Item.
. e' i3 M4 P& Z3 Q% l7 X: c4 f$ o  var bomPart = bom.getRelatedItem(); 1 l0 t, J0 o' N# {: y/ D& r& C

' Y! C+ L* e4 X( _, \9 j5 q% a& M  content += "<tr>" + : Z# `: z' H. g$ h8 B
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
/ X, l/ {% R$ l8 o* u, w% N% G1 |      "<td>" + bomPart.getProperty("description") + "</td>" + % e8 f6 j$ b: M# V+ y
      "<td>" + bomPart.getProperty("cost") + "</td>" + . R4 ^' g6 ~, P
      "<td>" + bom.getProperty("quantity") + "</td>" +
8 ?9 d; i. n6 [    "</tr>";
) O0 ^8 x9 l; |4 }}
2 k' ]/ `) o. P! ^( i) Kreturn content + "</table>";
: G2 ^3 D3 y+ i: H/ z' ?
( B, S) b. U# L9 R1 {. u

1 V- Y+ t" b  _8 b% N* y4 ~
2 Q6 ?& s& ^1 _. W+ `0 o- C, s9 `
/ V: F3 B) q( e, W
C#  , Z) E( s2 {% |4 \; V8 Y4 L
Innovator innovator = this.newInnovator(); " w3 a* p5 m: h

' g0 j1 i: t# ~// Set up the query Item. ( D7 {" p( C6 x# j- S1 F" h
Item qryItem = this.newItem("Part","get");
* x0 }( O* `; MqryItem.setAttribute("select","item_number,description,cost"); 7 f* m! C4 P( x0 l* d+ i! R. c
qryItem.setID(myId); # E+ J: D1 O+ @+ z

( a8 D2 c! b# i// Add the BOM structure.
. |/ o! G, a, i9 t2 h, m( LItem bomItem = this.newItem("Part BOM","get");
( e: K" C3 J3 ^: q$ s& FbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); 1 E5 F' ~0 m) V1 a9 {& n
qryItem.addRelationship(bomItem); # D8 D9 j6 R" A2 T" o! t
* E) D: q, r4 j2 `
// Perform the query.
/ f/ K+ d8 I3 W( R0 mItem results = qryItem.apply();
$ y; ^4 {9 x. K, X
4 b$ t$ {: _' [* W// Test for an error. ! V9 t' C# b7 |7 o
if (results.isError()) { 0 I/ O2 h2 \; ?; T8 t
  return innovator.newError("Item not found: " + results.getErrorDetail());
$ p, e( S- \6 H% I+ G" P! V( E} 3 C& z& V. I6 H  r8 T8 W) J" x

+ B4 p+ m" c) \// Get a handle to the BOM Items. 4 N1 ]1 h- ^4 g6 f7 M1 k$ {
Item bomItems = results.getRelationships();
% ]& }) g3 J' ]  o  ^int count = bomItems.getItemCount(); , G! d% Q$ E9 n% u
int i; . e& K# R: G7 S+ \! \; F! @
2 [* J8 {. g2 R4 F' F, S, o
// Create the results content. 6 U4 c. y% C6 O. {9 I* C0 u8 T* M
string content = "<table border='1'>" +
* V* y: c# w8 q  "<tr>" +
; S+ ]: L7 C/ Y    "<td>Part Number</td>" + & V* L% l8 w2 f9 u
    "<td>Description</td>" +
( b3 Z( O, t9 g& i    "<td>Cost</td>" +
" W( P/ b5 f5 d/ }$ r" g6 I    "<td>Quantity</td>" +
; w8 T) C# n! x" r' Q' c; K, Q  "</tr>"; % ]- V: c- g6 X" v
. @9 v& T( `: s+ E5 D# F
// Iterate over the BOM Items.
3 Y; ]1 E; |+ @% t0 D; e( Y* tfor (i=0; i<count; ++i) & F4 n: U% X7 ^. O3 x6 j: }' l0 n
{ , Y# S( }" C. @8 D6 M# u1 `  g
// Get a handle to the relationship Item by index.
% F+ H& k; D7 n6 Q4 a  Item bom = bomItems.getItemByIndex(i);
7 _1 n8 a/ ~. t6 Z; T// Get a handle to the related Item for this relationship Item.
7 v: O2 t$ g4 ]  Item bomPart = bom.getRelatedItem();
) {4 K# ^/ e2 A  D& x
/ n$ J4 F: J& p  content += "" + & A1 d$ @7 s+ d
    "<tr>" + % I" Z) z0 }. T5 l  _4 W5 r9 H! d9 q
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 3 B9 e9 ]& P. g! c, @- ^) b' j# E
      "<td>" + bomPart.getProperty("description") + "</td>" + + ]$ y) c+ |2 c+ V5 M
      "<td>" + bomPart.getProperty("cost") + "</td>" +
  Q( u" y% _4 B* C      "<td>" + bom.getProperty("quantity") + "</td>" + # V3 k  e1 u* c* v
    "</tr>";
4 p/ H3 R* R$ z) S0 _8 J}
( x* w/ o. l& F8 _, Y. lcontent += "</table>";
$ c) i3 Z# ?" C& F! B1 D  P " c- Z& z* I8 L- r0 P
return innovator.newResult(content);
/ [$ t+ |2 M* r4 h/ N) H3 Z, Y$ z6 i* K# H8 P4 I  D
& k, G3 I& [) e9 H) a- i
4 Q2 f" r# T0 O; z" m' k

% q& N$ r" X; ^! w- ~1 t- f/ C# E/ m+ @! N, A# }$ x- T" ?1 R1 n
. O  _  ^% Q  F6 {, C0 L

! [- \0 [: w! W5 V; J* U& g: `5 h: f! k    Page 46
, Q0 K! d. u6 V 6 S* R- s4 K/ e+ B: T- l9 X. I% p5 z7 v
Copyright   2007 7 a! n8 j) e: \$ N4 k* }5 {! L: k# [
Aras Corporation.  
) I) k# V; H  A' M2 Y2 {8 U. KAll Rights Reserved. ! |7 ~1 `6 X- Z8 w, E
VB.Net  0 g: @5 ?  T7 D, A  Z4 p
Dim innovator As Innovator = Me.newInnovator() & U+ t. k. s6 E- B
2 X8 T6 E8 d- c* F. v# T, Z. ?
' Set up the query Item.
1 H2 t- J  T6 u( I2 t7 ]% hDim qryItem As Item = Me.newItem("Part","get") " {$ v1 ]! @* V- \
qryItem.setAttribute("select","item_number,description,cost")
# u0 {. {5 b$ f4 nqryItem.setID(myId)
+ o/ q# Y- y  s 9 y6 m0 u/ |7 r) R3 f
' Add the BOM structure.
3 [, R* {2 ]) \# ?* Y  x4 ~7 dDim bomItem As Item = Me.newItem("Part BOM","get") 5 E/ J8 E1 d( }8 u8 J5 v$ m( N
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
, t  b  ^7 p* r2 d# hqryItem.addRelationship(bomItem) ) K1 g" {8 Y5 M

8 Y! W. H/ S! P. Z' Perform the query. % t& W$ {2 |# M. a& d( q# t+ v7 {
Dim results As Item = qryItem.apply()
' B. l" `  t: C+ Z   X- h# g$ @6 P. T! @# K3 `& s
' Test for an error. ' x9 d6 d6 }7 J- q7 i9 J- c# J
If results.isError() Then 3 \2 ]& B5 G3 H" I! j
  Return innovator.newError(results.getErrorDetail())
2 ^) J7 u# ^( V; {% UEnd If
& X( B: w$ E( Q # R) A' e, j1 X9 P. D8 v
' Get a handle to the BOM Items. . W. C+ P1 U. ^  ~. T& Y1 y
Dim bomItems As Item = results.getRelationships()
  V6 Z8 |0 X4 _. D" JDim count As Integer = bomItems.getItemCount() ! q- n1 v; B; P5 O8 |& w
Dim i As Integer
6 I, u, K$ v2 i) \9 k . Y1 v5 H8 p8 z. |. M
' Create the results content.
5 j8 b7 }! U" ZDim content As String = "<table border='1'>" + _
' C' w5 z; R0 T. ]; w: `3 [: _5 y- D  "<tr>" + _ 5 u  _; Y+ o4 x( y& f$ D; E$ @9 T$ p
    "<td>Part Number</td>" + _
/ Z, S( q) p* L+ X* z    "<td>Description</td>" + _
. A/ x' W0 I: o& A, O    "<td>Cost</td>" + _ , h/ O) K2 G& P8 m0 l& S; N& x3 k
    "<td>Quantity</td>" + _
1 B3 e3 {/ x- t6 s& `4 x  "</tr>"
9 K7 [4 e7 Z4 ~1 h) A
7 ^4 P& G' R4 {  Q' Iterate over the BOM Items 5 M5 c' ~9 G! p5 d. A$ J
For i = 0 To count - 1 4 t% k! a& {6 l# h$ o
' Get a handle to the relationship Item by index.
* q" Y: _4 U- }/ Z& @/ A  Dim bom As Item = bomItems.getItemByIndex(i) - m# q2 t5 d; y0 h* e8 d7 \" C

4 ]9 P' P2 ?9 I% C' Get a handle to the related Item for this relationship Item.
9 X. ~) W# f1 w7 l! P* ]6 z  Dim bomPart As Item = bom.getRelatedItem() $ t9 T" N# Y1 a9 X1 G2 ^1 y6 P+ U& `

8 c9 g1 L& G+ Y. Z5 Y5 R5 H) _  content += _ ! V% ^+ Q  B, B" t
    "<tr>" + _
# h& j" U2 g. W; ~      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
) i7 `9 d& W# t, p0 {1 x      "<td>" + bomPart.getProperty("description") + "</td>" + _ 6 X3 |2 t# Y; {8 L7 t" R
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
) R/ p! x: `3 P! E5 Z      "<td>" + bom.getProperty("quantity") + "</td>" + _
7 S0 E0 W4 O$ x. z, }/ {    "</tr>" 0 ^. \1 @- O5 w
Next ! n6 c9 ?- Y6 f7 I+ }' N6 S0 y  |( s
content += "</table>" 0 v$ j6 z/ A/ M4 Q# U

, x& u8 u; H( u2 l# \8 UReturn innovator.newResult(content) ) y4 J( }7 K! ]; s: V

4 `/ Z2 O7 N5 p2 ~! s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了