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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
* A) q. H* d9 |. {To query for an Item and retrieve its structure you build the query as the structure
* S4 C$ u" U6 G0 s/ t: E2 ]" Cyou want returned.  Use the IOM methods to add the relationships you want and 8 B" h1 E  i4 q& J9 J# {% B
build the structure in the Item.  The server will return the structure that follows the " w1 A" `; J1 \4 h5 U
request structure.
0 N% c; r; T3 B; r" u1 q/ cThis recipe illustrates several related concepts together, which are how to get a set
8 R4 b' C3 h# I8 Vof Items from an Item and how to iterate over the set, plus how to get the related 2 A; @* u8 o3 X, A3 q- ^
Item from the relationship Item.
, U7 i' B8 o2 z/ T5 TJavaScript  
9 D1 Q9 \) F+ v, |$ D2 \var innovator = this.newInnovator();
& x" M5 [) ~1 q  B 2 }6 l+ A6 C1 @; g# I
// Set up the query Item. 8 N# u, E- }3 M& [. G) b$ ?
var qryItem = this.newItem("Part","get"); 2 h! X+ T& D* o- b$ ^$ H
qryItem.setAttribute("select","item_number,description,cost");
$ A  y& E5 |& O! ?. ^qryItem.setID(myId);
  S- n6 L& J& ^ $ L4 v2 u6 Q' ?9 y
// Add the BOM structure.
6 I/ H* K; ^# H" X/ S8 Pvar bomItem = this.newItem("Part BOM","get"); # X. t8 d& W* O6 d
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); + E7 R" _1 \1 h/ v% l8 I, n
qryItem.addRelationship(bomItem);
, N2 ^, y  }4 P: T7 M. s  U+ ` " [! t+ Q4 y- f* S+ w, h! Z
// Perform the query. 2 S2 l3 t! `# |8 ^( U, P
var results = qryItem.apply(); : v  A0 M; W0 A* k7 T8 k2 E% ?

0 V. \: A& e. r1 g1 e// Test for an error. ; t9 V- z  g" H. [
if (results.isError()) { # S  f7 G2 A; Y8 t( R
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
2 p; ?5 @2 m' ~2 H% W' k5 b  return; " j4 e( M( S. U: L
}
1 d  z0 U- E' ?0 }1 O$ n$ u
5 a- d# U0 z% b- E, c4 l// Get a handle to the BOM Items.
. w! h; \1 z0 _* K! avar bomItems = results.getRelationships();
) D( G! \6 W( P) [' i0 K# `var count = bomItems.getItemCount(); ! j, z% }: O2 b! V7 }
& ]8 ~2 M$ n# ]1 p4 F: v
// Create the results content.
- P5 [7 t* t7 r8 I4 E1 Vvar content = "<table border='1'>" + 6 F2 c1 Y7 b- x6 ?. r) J4 W& l
  "<tr>" + ; ?9 y. h2 A) V4 z* u
    "<td>Part Number</td>" + 4 f+ ]0 z# n2 v  o! A0 V
    "<td>Description</td>" +
* c/ r1 H9 Y* t0 r    "<td>Cost</td>" +
  S: [' R) G' K- X. l( ]8 o, Y    "<td>Quantity</td>" +
( v9 S# S( ]" H$ ~# b# {  "</tr>";
  k0 P4 R& J3 B, e 1 Q3 ], n) \4 h$ a" @
// Iterate over the BOM Items.
( M  J( r  D4 Hfor (var i=0; i<count; ++i)
, k5 q9 d* V; ]2 ~, ~{
8 y* W) d  l; R$ ?5 k# V// Get a handle to the relationship Item by index. 0 y6 }. n7 l4 b  y% f
  var bom = bomItems.getItemByIndex(i); . t7 G' U+ Y( e6 V3 _, G
// Get a handle to the related Item for this relationship Item. # {# Y( j8 v- _# j; p; @
  var bomPart = bom.getRelatedItem();
, q  |" g4 W" v4 R   c' v* W# ~/ a7 g3 z/ g
  content += "<tr>" +
$ e# V6 Y) a2 {- \, F      "<td>" + bomPart.getProperty("item_number") + "</td>" +
6 t' O7 J. f$ C) B+ e      "<td>" + bomPart.getProperty("description") + "</td>" +
. g3 ^. r% K( K- z/ @, D$ R      "<td>" + bomPart.getProperty("cost") + "</td>" + ' \7 G5 I; j; Z( K$ p& g& x
      "<td>" + bom.getProperty("quantity") + "</td>" + / A1 Y* X$ G3 E# O) Q5 x) z  N
    "</tr>"; 6 P* k: j! |' @. q* c3 k
} ' _: D7 B. _% P7 q9 a( K; Y
return content + "</table>";
) a7 C' U2 N: P6 E: c/ m+ a1 ^$ e( T4 e
1 _* [6 ^3 a7 e! _: q" T

2 X9 [+ t4 i0 ?, r% O- J
) g, V5 y/ g: X* E8 Q
! F2 S! d; c: E9 J
C#  
) {# g( D* D$ dInnovator innovator = this.newInnovator(); & E: t: F* r4 n# P3 }

; Z, E1 b, o, }! C$ ~2 \// Set up the query Item. 9 I4 c/ ^( Z+ [+ e! v1 {
Item qryItem = this.newItem("Part","get");
: G0 ?) l0 i* M4 [! jqryItem.setAttribute("select","item_number,description,cost");
3 R* f* `4 f9 I9 ~qryItem.setID(myId);
0 N; R; y; B2 ?; z) H/ z 0 w0 `# m: J  I1 Z
// Add the BOM structure.
. r# f0 q* G) z! ~2 V! S: V/ IItem bomItem = this.newItem("Part BOM","get"); * _3 R" T, V8 Z% S' q7 d
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
# y8 U8 ]( [8 d, ~; \! [& T2 oqryItem.addRelationship(bomItem); 3 b6 K( c! u5 ^4 E. i
* g7 f! `: B3 x; j
// Perform the query. , |9 J/ o/ j9 U# W+ D) w
Item results = qryItem.apply();
4 `! r, G4 v0 J+ T% ^ & `& S' n% I# m) F
// Test for an error. $ q& f" B3 O, j' U* w
if (results.isError()) {
# {! {+ U  n* J: `8 d" h) ]# U0 a  return innovator.newError("Item not found: " + results.getErrorDetail()); 3 i( f( o4 o6 I1 D. @# Z  _( Z
} ( f4 Y8 ~, t1 o' c) s) t
" {5 [9 F. r8 _7 U% T- k
// Get a handle to the BOM Items. , ~+ n. m9 H2 `7 }. V5 b! @
Item bomItems = results.getRelationships();
  D4 U8 |4 Y. k9 e+ n$ B" I* ?int count = bomItems.getItemCount(); ) I1 U5 \7 u' T: S2 I, X
int i;
3 z/ r! z- E- j; f/ z
: G5 }6 K0 l, F3 J9 f4 u// Create the results content. ' P5 [4 K$ ~9 D' z" C4 ]' A$ U$ g3 Y
string content = "<table border='1'>" +
. C2 E7 ^4 k( q  "<tr>" + / U. l* Q" j+ g& f+ f; l* i
    "<td>Part Number</td>" +
5 J/ b3 [8 F  T/ J$ ]" ]* {    "<td>Description</td>" + & o, W: {; ]3 `  t) R0 j
    "<td>Cost</td>" + ! E% Z8 [6 y. b, X; a
    "<td>Quantity</td>" +
4 w9 s8 F. l/ {5 F  "</tr>";
( C0 f+ J: r4 A0 Z/ x6 Q. B9 G% K& g
9 R- u! L/ K" W/ [6 J1 \8 X  ~! X2 f, v// Iterate over the BOM Items. 0 x* E7 Z0 c4 D4 @8 W; M5 t7 ?
for (i=0; i<count; ++i)
# r" p2 W  s$ _" Q{ 9 M: R5 _" [' M7 ~& ^
// Get a handle to the relationship Item by index. $ N3 ~1 z3 i( D( Q1 C, G0 S9 U+ v
  Item bom = bomItems.getItemByIndex(i); 5 @5 g& f6 x, \# [- E4 w& ?7 }+ M
// Get a handle to the related Item for this relationship Item.
& E* r# t8 @: @$ n& P! z, e  Item bomPart = bom.getRelatedItem();
0 c/ S2 z/ y3 Z4 [ # @) h  W/ [. H, Q) L$ E2 V
  content += "" +
+ p8 A$ r& b$ N7 f    "<tr>" +
( A0 A8 X+ W  {" i      "<td>" + bomPart.getProperty("item_number") + "</td>" + 7 K4 d; s: h/ v6 w' w- Y
      "<td>" + bomPart.getProperty("description") + "</td>" +
- R& J, u4 p3 X" {; M$ w& G) b+ T      "<td>" + bomPart.getProperty("cost") + "</td>" +
2 w  p, f7 s" _* M, S      "<td>" + bom.getProperty("quantity") + "</td>" +
: F# ]2 a% l) S/ j8 Z4 p9 _    "</tr>";
. e& E: c7 e# r( n( m3 X} # I; o( Z: v* ]& Z! v
content += "</table>"; , L& w* `& n: g6 k0 G; [" B
) P5 E/ l( Q& P3 X% G
return innovator.newResult(content);
& t3 }- N2 j% G: ^% \& B. X- _  C
2 W3 N8 a3 \& M5 [9 X- H& O
/ d5 U; _8 r' O0 c  j2 @

0 V3 _3 ~& Q0 w4 y6 {# w! r$ U' {2 i+ a- f

  q( B. h2 Q' f( T
" f3 _& @" k, I    Page 46
' l# C- T  L5 s' s3 w* \ 2 o# |0 O! d/ g$ w4 ?+ ]
Copyright   2007
' D  x" h% P! m. S: }- N! gAras Corporation.  1 s6 O) Y- z: d, F5 z& c7 _
All Rights Reserved.
) [3 k- y, }% }7 ~; Y# m2 jVB.Net  2 l* n) w/ g; ^; G
Dim innovator As Innovator = Me.newInnovator()
# X2 K0 B0 }, q; F" c 8 h) T" |& j) F) a1 L$ y7 @, j
' Set up the query Item. + C& N' t4 m% a, `8 G
Dim qryItem As Item = Me.newItem("Part","get")
. c' N: C$ y" x! u$ }6 w- KqryItem.setAttribute("select","item_number,description,cost")
0 s8 x6 w- @: G6 XqryItem.setID(myId)
  w0 ?+ Z: _  |" {; x; { : f+ j! \/ i; W$ c
' Add the BOM structure. 7 d7 c4 Z8 k. f3 W' t6 t& M: Q
Dim bomItem As Item = Me.newItem("Part BOM","get")
" F5 Q- d+ V$ k+ }5 gbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
) G9 g- p1 l! e3 xqryItem.addRelationship(bomItem) 3 p4 C; Q$ S; P# m: o, g

) q+ G; B8 T: p, e% X' Perform the query. , B  J9 o& z" `8 `% Q9 l
Dim results As Item = qryItem.apply()
5 v, M8 M! O1 I" L! ]
9 ~# t( Q% Y- Z9 p' Test for an error. , w, C+ s7 n6 |* T* N* h
If results.isError() Then
0 D2 f$ f4 R4 N0 N7 Y+ m( K8 M  Return innovator.newError(results.getErrorDetail())
8 M; G' A( o2 X) R  _: |% MEnd If
' s8 y  W/ I# Z# M( e3 U% I# u , q$ v! D+ V* C$ m: V
' Get a handle to the BOM Items. 8 M0 M: j( f! P! w) f( [. b
Dim bomItems As Item = results.getRelationships() , @% L0 r! q6 k+ [
Dim count As Integer = bomItems.getItemCount()
" q  b) g* R: `0 X8 @6 {# l/ fDim i As Integer
6 Q9 g; a* H% `( r1 f 5 {2 o' Z( |) q
' Create the results content.
! N  j0 J$ ?# R6 dDim content As String = "<table border='1'>" + _ % O( y8 c$ {2 K5 }' [0 |
  "<tr>" + _
( O" Q2 X$ c' D8 x/ y2 X) d    "<td>Part Number</td>" + _
! G4 l5 b8 P' A% g, j8 J1 [    "<td>Description</td>" + _ $ {% u4 h" W0 M6 m- }9 D
    "<td>Cost</td>" + _ % O8 [+ t) S, r1 K9 w' Q
    "<td>Quantity</td>" + _ 5 |+ W. ?9 y$ A" ^9 S  c2 e$ ^: }+ B
  "</tr>"
( g7 \7 Q' j# c1 P
7 Q! v. I9 R4 ?$ h, f+ O# w0 r" {' Iterate over the BOM Items   ]1 N! T7 o/ [
For i = 0 To count - 1
, ], o- h; @3 ^- H7 T* C6 U5 V' Get a handle to the relationship Item by index. - j% ?9 N, T+ V/ G
  Dim bom As Item = bomItems.getItemByIndex(i) " l5 e$ B: U, _. ?  l8 r6 Q

( ~* \6 ~" ]' W# E' Get a handle to the related Item for this relationship Item. , B4 x5 N2 A: m! A% J
  Dim bomPart As Item = bom.getRelatedItem()
) s, h  `, H- B6 h# `& |
. K& A) L! x$ u. ?2 a  content += _
, F% }2 B" \" {/ a0 V    "<tr>" + _ . e( ?, s9 ^) O- s* ]
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
' D$ ]  J- n1 }: a9 p7 L      "<td>" + bomPart.getProperty("description") + "</td>" + _
. _8 u0 H# _% n: P$ y      "<td>" + bomPart.getProperty("cost") + "</td>" + _
& l4 N# a4 P2 C4 w      "<td>" + bom.getProperty("quantity") + "</td>" + _
. Y1 t( u* @- _5 ?4 N- c0 y$ @    "</tr>"
; J9 ^; L$ s/ _, V& V# f' D7 K5 RNext
% l% d3 J/ ?3 [: Ncontent += "</table>"
5 P5 X& Z; p5 j
9 J% A4 a" D* R# s  w" WReturn innovator.newResult(content)
& V# A8 M) _9 N( K) ], B/ j# d
! N8 _$ ?$ z5 i: n- M3 V: B; n
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了