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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
9 W% M1 h( C- [% [! k+ PTo query for an Item and retrieve its structure you build the query as the structure
; o, [) I1 k" @1 y3 X) wyou want returned.  Use the IOM methods to add the relationships you want and + B' Y1 q) s" ^8 L6 a9 w8 p$ O
build the structure in the Item.  The server will return the structure that follows the
0 f; M# h* W# ?8 _: jrequest structure.
0 a% {/ Z5 o0 P' K6 u& b4 xThis recipe illustrates several related concepts together, which are how to get a set
' |. ?5 o1 n6 M6 ]of Items from an Item and how to iterate over the set, plus how to get the related ! Y; F- Y% S' j: x: J
Item from the relationship Item. * P* ^9 `% J1 }+ n' f  t
JavaScript  
" z& m8 K* t1 b& o, X1 Kvar innovator = this.newInnovator();   Z' X; }' [' b8 d1 _

, @6 T" @* F% }* Q  w" ~1 j// Set up the query Item.
. m4 E8 k' b' m# d; k0 f7 tvar qryItem = this.newItem("Part","get");
+ [* P: o3 l0 W2 f( ]7 SqryItem.setAttribute("select","item_number,description,cost");
4 Q) r1 B. s* }/ {' {qryItem.setID(myId); 9 T: |# x2 S) O" H
+ `, }! C; @" F# C8 f- p
// Add the BOM structure. - ~2 m% Z" O; B0 R1 j
var bomItem = this.newItem("Part BOM","get"); 3 x' G. A" g6 A$ W6 K( r( \  Q6 U
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); * a* c0 K4 f$ _
qryItem.addRelationship(bomItem);
) B/ V$ ^, j. Z% v6 o  S3 Q! a 0 p  ?4 c0 ~( r5 I, f* `) {
// Perform the query.
5 u* t/ f1 S' s0 D' tvar results = qryItem.apply(); 5 Q& L; c9 G' y4 n: i' v

, {2 s/ E" w) o+ S5 S8 e// Test for an error. 9 \4 k& }, a% J0 q4 K2 m# Q
if (results.isError()) { / U; L$ n9 p6 r8 f6 }; G( G& d
  top.aras.AlertError("Item not found: " + results.getErrorDetail());
$ ?- U+ e5 D$ o+ |* t6 y" d  return;
6 E% U) C- p1 z% `% z' ?0 x1 E} , r0 }2 o* k5 h% a! B3 g7 r
2 S+ S. h' l5 x, X$ x& Z
// Get a handle to the BOM Items.
2 i5 S7 C4 k8 cvar bomItems = results.getRelationships(); + A% {( _: O! }. z" e2 _( c
var count = bomItems.getItemCount();
9 D& ^3 T! O( H# Q- @7 J - r* z0 K, F* D" s
// Create the results content. ' d4 L6 c9 p9 O5 O  f9 h
var content = "<table border='1'>" + ( H. H9 `) g& s: i% G/ _
  "<tr>" +
* Q, R& O8 r) y0 t' G" i# j5 M) d6 V    "<td>Part Number</td>" + # r; ~6 G6 q# H' g! I- o; U0 S3 \, ^+ R
    "<td>Description</td>" +
- [- O, ~( I" u6 Q' _    "<td>Cost</td>" + ( T/ M  H& W0 o) B+ v+ J: R
    "<td>Quantity</td>" +
" V( t4 p/ b, o; `/ W  "</tr>";
' Q3 f3 p! {$ I/ I/ P2 D+ F   B4 J8 j5 j" }1 U9 c+ ?
// Iterate over the BOM Items.
; E+ p( }7 K3 M* Xfor (var i=0; i<count; ++i) 3 j" b+ e8 ?) j
{
" d0 X1 _1 K+ i* [3 g2 w// Get a handle to the relationship Item by index. % v& S6 I9 h& k7 p  X( p
  var bom = bomItems.getItemByIndex(i);
) m9 `6 t; d+ C. p: c, ]$ S// Get a handle to the related Item for this relationship Item.
: v( N* r+ ~* ?7 f0 N  var bomPart = bom.getRelatedItem();
! _* T- g1 Q+ q$ g8 x7 M- X4 C, }
3 D+ |3 G. o# H' A0 g0 N  content += "<tr>" +
" z7 s6 g: ]0 k, f      "<td>" + bomPart.getProperty("item_number") + "</td>" +
: ^. ~/ P( y" g* j2 P3 `      "<td>" + bomPart.getProperty("description") + "</td>" + - z; x# e3 _& p; }
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) D6 b( P( V) X5 `: M
      "<td>" + bom.getProperty("quantity") + "</td>" + 8 M' M* [/ _8 l+ r4 r# \" C
    "</tr>"; 7 z% v- K8 x  ]& R$ Z) x
}
- Z  M5 T6 t& H) z* Wreturn content + "</table>";! \. u6 a* P$ |3 F$ q
: J7 o0 O3 T, U7 m, }

2 j7 w5 H. D- J2 E) P7 N: `+ r$ M0 j: v- z5 R  I* z9 ^! p
  p, L: ^& T2 U* A
C#  9 Q, S4 G8 `3 J; ?% P% ~
Innovator innovator = this.newInnovator(); $ F  U. t" G; B5 z

$ K' g6 W0 B8 l// Set up the query Item.
  Q  x# z6 K) y& b% vItem qryItem = this.newItem("Part","get");
) ]$ n. ?5 s, E% k4 Z( pqryItem.setAttribute("select","item_number,description,cost");
' {* [/ v9 ~2 _. h  r/ _* K/ AqryItem.setID(myId); . N) `' I' ?3 Z$ o% v1 ?

6 ~# f2 r# [, n: w$ S8 _// Add the BOM structure. 2 i& s9 x9 |( R$ Q
Item bomItem = this.newItem("Part BOM","get"); / z/ M0 R& t  N8 B" K4 b6 Q
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");   y$ C6 J( E' x8 Z( T2 \# M
qryItem.addRelationship(bomItem);
: D1 j: w/ q9 W
' [  y2 J+ f! C6 ]5 n// Perform the query.
0 a( }5 g; u6 ~6 h% y/ {# ]( o) dItem results = qryItem.apply();
- V% J$ p1 x5 d( N$ q: f6 C- n 7 O2 _2 b6 i0 m$ L$ h5 b
// Test for an error. 1 _& [0 u3 H5 C, W+ M5 Z  Z% |" _
if (results.isError()) {
* F2 P4 r% K* J  return innovator.newError("Item not found: " + results.getErrorDetail()); # U  C/ G, x+ Z0 S/ H
} % B9 o- y0 S" U
7 L: Y2 g& K2 x5 Z' p) ~
// Get a handle to the BOM Items.
: |* S* N( s9 i5 S* x9 sItem bomItems = results.getRelationships();
, L" r& R, a8 {" \& B: J& e0 Uint count = bomItems.getItemCount();
# u( y2 @! i* F; B  _int i;
% E+ ~  i( [4 p4 b7 u& D : U5 ]$ ]1 p' [& _3 v  L6 @
// Create the results content. " u4 \' d9 _6 h/ E
string content = "<table border='1'>" + ' A) O2 B+ Y) Z6 ^
  "<tr>" +
; Q/ o: _5 u+ @( O8 N4 y) k- Q    "<td>Part Number</td>" + & J/ j' k* d0 ]
    "<td>Description</td>" +
. H- k9 s: a1 X( R  Z    "<td>Cost</td>" + : l% O4 i. w+ @  O* \
    "<td>Quantity</td>" +
" {+ W5 X  v: b$ I7 r) y" R" P3 G  "</tr>"; . @4 S5 q/ ^4 O) w* z
, Q9 M# r8 Y1 u0 d0 s- {
// Iterate over the BOM Items.
! z1 U3 b$ B, B1 nfor (i=0; i<count; ++i) $ i+ {  K  G  J3 n; k
{ ( c7 u: q/ }9 }
// Get a handle to the relationship Item by index.
  w# Y' T0 B8 L9 n, A$ H8 V0 _( _  Item bom = bomItems.getItemByIndex(i);
1 H9 B& u' H4 x# d, h" Y// Get a handle to the related Item for this relationship Item.
; i6 v' n5 n7 m' v. q  Item bomPart = bom.getRelatedItem(); & J( h2 F& H+ r  t) n6 K

; ~, `! a1 I, {! G  content += "" + 0 i% {5 m# q3 x
    "<tr>" +
9 O9 u7 M6 F; G2 w      "<td>" + bomPart.getProperty("item_number") + "</td>" +
5 A( o' g) O' W6 s! t$ M" {% {) s; J* ^      "<td>" + bomPart.getProperty("description") + "</td>" +
2 s  A9 A  d4 X' l) ?      "<td>" + bomPart.getProperty("cost") + "</td>" +
7 ?* w" t: f+ t* {      "<td>" + bom.getProperty("quantity") + "</td>" +
9 f; M$ l$ D+ ~) c# g5 X    "</tr>";
. O9 N- d: M, ~8 J; V} 0 S/ U. x2 H6 V: }6 U* b
content += "</table>";
. U% Z, E/ F# [- e! O$ g2 k3 i
1 z: Z% u& s4 C, Greturn innovator.newResult(content);
; U5 P$ h+ T, O4 r1 t3 `& [
" r1 D6 E7 X# {6 T

  |3 c. J" r  s: x9 V4 a; x( _$ w/ w- @7 S
4 }2 Q" ~9 a; ^1 y! x; W7 g. j3 d8 p
- o# `' z2 K8 W2 T0 |, w! O: f2 D
7 _: s. _1 @  I9 q6 [1 D% Q  m7 Q
8 _5 c7 I# X) h
    Page 46
; L8 z0 B( i' T( T+ F* Z$ r0 c9 \/ o  d 7 d5 `9 i' i2 k# N) c
Copyright   2007 - [1 t% o0 K4 b. E9 w2 S$ z
Aras Corporation.  7 k8 D: s9 L: r* N9 Q% e$ V
All Rights Reserved.
( j4 H1 Y: x3 @; Y' |. Q, Z1 H- FVB.Net  , M  R; ^' i8 [* J6 ~% Y' X9 K
Dim innovator As Innovator = Me.newInnovator()
2 h4 W- t$ B2 H: n9 s$ z ' _7 m/ a- |$ o6 Y
' Set up the query Item.
% c( ^; u! e$ I: j$ L% y* A' xDim qryItem As Item = Me.newItem("Part","get")
$ [' y5 \" }. wqryItem.setAttribute("select","item_number,description,cost")
* Y+ g) p3 _$ Y* H' O5 SqryItem.setID(myId)
0 \/ |6 L/ ?/ E' {% J: o0 d
4 H- R8 A; k$ ^' Add the BOM structure. ) @& x% c& F& v% N
Dim bomItem As Item = Me.newItem("Part BOM","get")   {6 f  F4 G: G1 j; i8 L! S, v
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
. Y3 o" s. N( @9 S( b5 x4 s% xqryItem.addRelationship(bomItem)
; i  p% M( P/ G- a! O9 u" v % m1 _1 [# Y# `+ m* a. a9 f' a
' Perform the query. 9 D/ @- |; F9 G$ U* \+ Q
Dim results As Item = qryItem.apply()
2 u5 R- H' [5 C+ j
. D2 R6 m0 ^) R0 ?0 @* p' E, p! p' Test for an error. - H- K, b" k4 ]* A3 N
If results.isError() Then
! }( }6 X% c0 G1 z" s: f  Return innovator.newError(results.getErrorDetail())
3 V5 C* @: \3 _6 `End If 4 o3 e' k, H$ J0 `, o

% L) r: U- K: a' Get a handle to the BOM Items. # q6 A) j6 N, b. Q$ E9 x3 \. S
Dim bomItems As Item = results.getRelationships()
6 i! B5 P3 ~" WDim count As Integer = bomItems.getItemCount()
! ?3 D# ?) D4 W" V* Q- u) yDim i As Integer ! e! }2 |1 J) D, c/ Q: z

- i' f2 T* @% [+ p) v/ m' Create the results content.
# O: S5 B! ~  _- g" {6 WDim content As String = "<table border='1'>" + _   {4 y( T2 R" s, L; m$ p+ p; _  i
  "<tr>" + _ / c+ O) w2 A6 i' R2 W0 x9 Z9 [
    "<td>Part Number</td>" + _ * d" d. V8 B0 W. D1 e0 d1 i7 L, Q
    "<td>Description</td>" + _ % B1 P8 m* }2 p" q0 h
    "<td>Cost</td>" + _
* J0 k' j* x$ V% V# [8 d6 }    "<td>Quantity</td>" + _ ; e( l$ e8 ?* R; ]! T6 D
  "</tr>" ' Y% t% C/ i9 c( \/ y

4 D2 A2 l% D% e9 [, R' Iterate over the BOM Items * C. x6 ?& V; L! h8 J1 z
For i = 0 To count - 1
% ]* ~% u, o/ A+ |, z# k' Get a handle to the relationship Item by index.
$ N. ^2 v4 i9 d  ~8 _  Dim bom As Item = bomItems.getItemByIndex(i)
1 Y* K! H& ~) G5 R4 s
) d) Z4 ~# s: G5 E6 ^4 ~; q' Get a handle to the related Item for this relationship Item.
/ S  ?9 c% P* c+ d  Dim bomPart As Item = bom.getRelatedItem()
. v% m7 z+ w9 D6 R) m0 U& D
1 u. `- l& {" c  content += _
6 `+ e+ I7 Y% h1 |3 H: N    "<tr>" + _ - ?# X, [" Q. ~9 W
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
2 O% s- v3 U5 c      "<td>" + bomPart.getProperty("description") + "</td>" + _
, T* v6 H2 Y- N* R, l      "<td>" + bomPart.getProperty("cost") + "</td>" + _ " f& d2 A; z: c
      "<td>" + bom.getProperty("quantity") + "</td>" + _
- L+ B5 y; ?5 k* c1 ?4 m; H/ l+ D    "</tr>"
8 A% D- g: K$ {4 B, [, P7 aNext
& L* E* ]! B+ q8 q/ b/ u- z: mcontent += "</table>" ; t0 ^8 Z$ S$ ]/ l
6 L/ V" J* D4 y9 s, j
Return innovator.newResult(content)
3 B; c. c; S! Y& f/ \3 q- o
. _4 }' J/ e7 O" ^9 P
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了