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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  0 u3 V* F! G& o
To query for an Item and retrieve its structure you build the query as the structure # [* z) R6 L& f0 U! |2 W+ w
you want returned.  Use the IOM methods to add the relationships you want and
" I7 A% |1 _: [3 i, T4 U$ Gbuild the structure in the Item.  The server will return the structure that follows the - i1 S+ p" @/ I* t9 [' a3 Z
request structure.
$ |7 G$ |8 C) Y8 [6 y  P, }This recipe illustrates several related concepts together, which are how to get a set ; _9 g- j) ^: L
of Items from an Item and how to iterate over the set, plus how to get the related " a# i3 e$ d9 s; o4 j: l9 Q+ {: j
Item from the relationship Item.   b0 n2 H9 I! W, G/ c6 N
JavaScript  
7 e' ]& K9 o. P. y( X" vvar innovator = this.newInnovator(); 0 e5 g6 W9 x# y9 j  K

7 N) M1 }( u6 ^$ e3 r, x3 h8 Y// Set up the query Item.
( N4 a/ p3 d6 Z/ I6 c6 Bvar qryItem = this.newItem("Part","get"); % j: |% E3 \9 k# C
qryItem.setAttribute("select","item_number,description,cost"); 3 \. p3 V" G7 F' q
qryItem.setID(myId); + B# x7 Z8 K2 p2 {- |$ d
; s% |4 r, W4 B! z6 s
// Add the BOM structure. $ g% m. ?: E; Y  s2 ]' O. j
var bomItem = this.newItem("Part BOM","get");
$ E& ?. i# C7 ]7 `bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)"); # A9 o' z5 f2 B' h  P0 i, L
qryItem.addRelationship(bomItem);
" F( I$ n2 r* j$ c+ p5 v& `( L: L
# H1 L8 f( K8 l: d, k% R" e# [// Perform the query. 7 B9 w$ `3 B9 P. k1 i& q
var results = qryItem.apply();
; i# E% b+ F4 g, s3 h' | 9 J$ a; V# ?. E8 ~
// Test for an error.
6 R, H0 s( g0 E. ^- lif (results.isError()) {
0 X! v0 d& N8 T9 R  top.aras.AlertError("Item not found: " + results.getErrorDetail());
. B! M8 n+ h% Q- M! d  return; 0 p, ], U$ c" u1 a* R, F
} ' W9 \" L, A# p$ _2 p7 y* s
& K! P3 n  c6 L4 y
// Get a handle to the BOM Items. ' H4 w+ x" o+ o3 b! B
var bomItems = results.getRelationships(); % e7 X" B3 ^3 P! K2 M
var count = bomItems.getItemCount(); 8 r* ?1 o+ ]- m+ p1 b% Q
/ P( j! I% L" R, X  l6 m$ E3 i
// Create the results content. ( s3 w! L1 T4 f+ l% u  v
var content = "<table border='1'>" + # [/ F* _  H9 W! {% `! e
  "<tr>" + , y3 ~! j' Z. J4 b; a1 I- i
    "<td>Part Number</td>" +
7 O: ?! P7 `& q    "<td>Description</td>" + - @2 r/ S9 p9 M2 w5 z
    "<td>Cost</td>" + 8 x- i: d0 |; Z4 o
    "<td>Quantity</td>" + 1 X9 t3 V& w' }4 k
  "</tr>";
3 H. j4 T/ p  B; `& d' D# I
' S2 n! ]0 F8 R// Iterate over the BOM Items.   b6 v- C2 c5 F. j* o$ X% ]3 I
for (var i=0; i<count; ++i) & Q- d' V0 d4 F2 G; V
{ ; W" e1 d4 @* A9 C7 N  I  C
// Get a handle to the relationship Item by index. 2 G" i) I1 B! g; U) N
  var bom = bomItems.getItemByIndex(i);
" i, Z) e; s  f) o+ w// Get a handle to the related Item for this relationship Item. 3 ~; Y% o: K/ @
  var bomPart = bom.getRelatedItem(); . w% W7 `9 U' D) ?* m

0 D7 Q( l: q7 x: T$ C9 s  content += "<tr>" +
) p, y$ z" k0 |7 i      "<td>" + bomPart.getProperty("item_number") + "</td>" +
% }2 P( _9 C. E; g6 ^2 ?      "<td>" + bomPart.getProperty("description") + "</td>" +
; x( ]9 h: ]4 @      "<td>" + bomPart.getProperty("cost") + "</td>" +   A) {6 x( S) S/ I! [' L
      "<td>" + bom.getProperty("quantity") + "</td>" +
& t. i+ D4 w& g2 @0 e) L2 ?    "</tr>"; ( j4 {, M) _; G& b4 K! I
}
4 p: A( M) `; y$ @' ?  oreturn content + "</table>";
% }8 J) W( J) l* G! A
' |. b( `+ R2 B2 Q
- P; T6 h+ H4 }; p' |
+ `! S  R3 a3 l& O

  l/ ^+ @4 N+ A: ~C#  
! m& D. S4 I: a' m" RInnovator innovator = this.newInnovator();
2 b9 ], h: n7 p% p3 E ( X" C. w7 w8 g* Q$ I
// Set up the query Item. % L  K# ]8 ~! `9 k
Item qryItem = this.newItem("Part","get");
. b7 H# Q+ ]+ ]! c, G: v' s& RqryItem.setAttribute("select","item_number,description,cost"); + q7 t& ~, o4 p& b7 G  e
qryItem.setID(myId);
5 ~  N+ u9 Y# x4 r9 ] / U& C) v& Z7 I5 |6 {6 x4 W
// Add the BOM structure. 3 i7 L$ |" C2 m. B) I$ G: q
Item bomItem = this.newItem("Part BOM","get");
( Z' v3 C, h* k# ^$ SbomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); - H5 p# }# U. b4 y5 S
qryItem.addRelationship(bomItem);
5 h2 `3 I4 w9 U7 g
" ?# j( q# d( E4 d+ a, N, C% ~% k// Perform the query.
5 ^$ M) q% K7 P& M+ ?1 R9 ~- LItem results = qryItem.apply();
' z( C  g* W" R* w8 S9 n. X
: B& L) B4 ~2 a4 E( U// Test for an error.   M! ?# @! x- o# Z$ j
if (results.isError()) { : `* U+ |$ f/ g5 v" o# J
  return innovator.newError("Item not found: " + results.getErrorDetail());
. @1 b7 e" U* C+ g" i} 2 O8 O7 k9 n5 h) {8 B# W5 }# }
; A: c( R( D. N6 v
// Get a handle to the BOM Items.
8 q& I/ x6 y" P% r" J2 @/ EItem bomItems = results.getRelationships();
1 s) Z$ a% ]1 x  k# i0 i( Jint count = bomItems.getItemCount();   G1 Z* a& P, D1 S  w& g( c
int i; % i# y( o" n* b

0 g4 i% D  x2 i  D+ K, U7 q// Create the results content. . z: ~7 ]$ y& D$ K  |
string content = "<table border='1'>" + ) v, S; D6 C- h( w& }
  "<tr>" +
- S4 u, y. Y+ m! f4 O    "<td>Part Number</td>" +
" j1 B, l6 J' R    "<td>Description</td>" + $ U0 _+ ]9 L7 G8 g
    "<td>Cost</td>" + , P' g+ O5 ~/ Z4 i
    "<td>Quantity</td>" +
9 n: m  c3 A- k, R4 L* z: b  "</tr>"; * M! C. x! C1 h. q2 `# }  T9 Y

- E5 n$ m$ R$ ]1 [// Iterate over the BOM Items.
8 k( J  n$ O! o' h; wfor (i=0; i<count; ++i)
" H6 g' {  p" V* T' v3 c{
4 V6 \' s$ j! v" u// Get a handle to the relationship Item by index. * _' g1 X4 G" f. s0 l3 @$ i
  Item bom = bomItems.getItemByIndex(i); - ]7 P+ g8 i+ l& ?: [# Z* B+ B
// Get a handle to the related Item for this relationship Item.
& i8 W7 K5 i1 `5 O  Item bomPart = bom.getRelatedItem(); 6 J: I, y4 ~! L) i8 n0 `
2 E; T0 b  J8 a2 x
  content += "" +
  h* W9 ~* {+ m* J# e/ i    "<tr>" +
/ n, m4 W; L8 v: y      "<td>" + bomPart.getProperty("item_number") + "</td>" + 4 ]0 a; e$ E* {2 k, p, }% u
      "<td>" + bomPart.getProperty("description") + "</td>" + 8 y$ [: @# u2 v; |3 w- B0 a# r# }0 E
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) M4 N7 O' E1 F9 n3 k' s
      "<td>" + bom.getProperty("quantity") + "</td>" + 5 F7 A7 |) K7 \5 |8 H9 f
    "</tr>"; 4 e1 o. f9 s6 @2 L  g2 i
} 3 J4 [% w0 x: {0 m/ K- V/ E
content += "</table>"; 7 X' ]  u7 r+ D; k
) q: U1 ^. v+ S) P) W' d  Y
return innovator.newResult(content); 7 r9 ~; f4 f8 o& S: G6 j8 _: t
* v4 V! S/ L. @" B8 o- F
4 z7 A9 L% `5 S5 C( I6 {% Z
7 V) d* w! `* ]

5 a2 Z0 ]* h# p. s0 u# L& l4 G1 r
4 j& i- y; f" w) v( p
3 j  ^0 t, d; a9 ^. n' T6 L

2 b4 R8 I4 r( C  q6 N    Page 46
9 m% `% B. X' M7 _/ H- T3 s3 e5 ]
7 j% X- c- l# VCopyright   2007 : Q6 g3 P3 X5 a; c. O' h
Aras Corporation.  
: M+ C/ L' |0 }! s3 LAll Rights Reserved. % c2 T& F3 j# W3 T' e5 t- B
VB.Net  6 Q7 j  Y6 _- m% Y2 k$ @2 x
Dim innovator As Innovator = Me.newInnovator()
4 Y" z5 F+ |; x * K/ k$ d! ?/ }
' Set up the query Item.
6 [( |$ @1 y9 Q  k! C* }Dim qryItem As Item = Me.newItem("Part","get") & |$ E$ p, E2 ~  t1 _* t7 [
qryItem.setAttribute("select","item_number,description,cost")
# A% Y6 u% ^- x# _8 W0 C5 nqryItem.setID(myId)
4 U0 H# @2 j( A! T / m1 J' O; s2 @/ h2 u$ O+ R
' Add the BOM structure. 2 k0 Y8 a( F8 [# i
Dim bomItem As Item = Me.newItem("Part BOM","get") ( a) ~4 G+ k% o
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") 1 G) X0 D# f8 S6 W1 G- Y) q: Q% b* \
qryItem.addRelationship(bomItem)
) c0 w8 q) @6 ^' Q) g) `$ W- k
, O1 W: _  j* \: L% Y' Perform the query. - S7 x$ y, y! f4 D
Dim results As Item = qryItem.apply()
2 B5 n* |" \/ T2 q) T
. i' j- o' s- e  Q5 j% K+ [/ D' Test for an error. 1 j/ N8 h$ v- C) S! T7 u4 t3 t
If results.isError() Then
2 v6 I! d+ J3 J. H3 Y* c0 l" p  Return innovator.newError(results.getErrorDetail()) 0 {& ^2 N3 E1 V* i/ v
End If ' ?7 }' o4 y! X4 `  j7 b! u
6 @& @" ^! e4 k. S) q& l3 `
' Get a handle to the BOM Items.
# b. ~4 n5 @! d& S) J6 FDim bomItems As Item = results.getRelationships()
* o+ a% C9 c8 p. e2 D. kDim count As Integer = bomItems.getItemCount() - t- Q0 z: M) T; H! y  ?: t: c
Dim i As Integer
$ d4 T2 B' b5 _5 r   h6 J* w# W# w- u( E
' Create the results content. : ?  p1 C, r$ P0 `/ ]
Dim content As String = "<table border='1'>" + _
/ o, B8 W2 k( M5 r  "<tr>" + _ 7 h$ x4 O/ Y( L+ x: B& n+ y
    "<td>Part Number</td>" + _
$ o7 e- z' g- e: h, z    "<td>Description</td>" + _
$ E) l  J# ?5 d: u3 N    "<td>Cost</td>" + _
/ E+ j8 G5 S9 Q% X' y    "<td>Quantity</td>" + _
/ N' A' H% E  ~5 E- s  "</tr>"
3 v& ^: e& s3 M3 ~' U4 m3 W6 H 5 K! b/ p9 P: H( _) D
' Iterate over the BOM Items * i3 O7 h7 D+ Z( U. W+ Z
For i = 0 To count - 1
1 D0 W, y" K; b0 g  t  p' Get a handle to the relationship Item by index. - c6 [) n) k2 C! x/ G& f4 H
  Dim bom As Item = bomItems.getItemByIndex(i) 4 l6 U: |, G6 L% t7 E# r1 l

, m$ H& i) V. B, H6 S' Get a handle to the related Item for this relationship Item. # B& A, B" k) R1 `! q7 N
  Dim bomPart As Item = bom.getRelatedItem()
! t1 W& }" b% P3 o; Z8 n& K1 c7 {
8 R  W" g/ I7 K% k% i2 w* J  content += _ - |* L5 A* e3 j$ Z6 ^1 V
    "<tr>" + _
; W6 l; b! I$ J: s( |+ h* e, Z      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
. R+ q+ m2 u! }; K3 K, I      "<td>" + bomPart.getProperty("description") + "</td>" + _ 7 S: [% w5 r0 W$ W
      "<td>" + bomPart.getProperty("cost") + "</td>" + _
0 ?. ~* q( b8 [      "<td>" + bom.getProperty("quantity") + "</td>" + _ ! H+ ^  r2 X. w/ I5 \
    "</tr>"
# W: |+ H/ w3 o" e1 `Next
' Q/ Y' I& E# t; u& t- P$ r# pcontent += "</table>"
6 V) X( M: [8 K/ H: @; R9 y - k" I( y, |" L. A8 z
Return innovator.newResult(content) # g- r8 N2 m7 q( y
/ m. R) k, |1 @  K/ J7 Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了