PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

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

[复制链接]

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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  ) [% z* y$ Y+ m  j8 I
To query for an Item and retrieve its structure you build the query as the structure
& ]/ N4 J- O- N1 J: @7 g# Byou want returned.  Use the IOM methods to add the relationships you want and * f3 n, k7 ^6 w* D' B
build the structure in the Item.  The server will return the structure that follows the ; ]/ Z' o- L! M* v5 b% n9 x/ T
request structure. 8 v) z! b" S  h6 {/ F) e8 E
This recipe illustrates several related concepts together, which are how to get a set ( ]/ E: k' C# |3 {1 h2 z( @
of Items from an Item and how to iterate over the set, plus how to get the related
& h6 B6 h1 G( r- nItem from the relationship Item. & p" ?5 L  _6 ?) u
JavaScript  $ H8 i3 Y# q" C" l' I
var innovator = this.newInnovator();
# L+ E7 y0 o  w9 ?! J. @( B8 C 4 G& d7 q( p0 t% f4 n- e0 i
// Set up the query Item.
; m5 X) v6 o9 O1 ?* Q* }! C: Dvar qryItem = this.newItem("Part","get");
: U/ F( Q% M( U; _qryItem.setAttribute("select","item_number,description,cost");
' K/ N+ e7 n4 O/ c" Y& N6 xqryItem.setID(myId); + i, x8 }' d0 z: @6 |# ~
5 N2 C$ x2 L) k4 U) l
// Add the BOM structure. : F* L5 n* n5 m
var bomItem = this.newItem("Part BOM","get"); ) u4 M: E: o6 l5 z: Z$ ]+ [
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
8 f" ]: _$ J; A% ?6 n$ t+ v" WqryItem.addRelationship(bomItem);
/ v2 G. O& L) |5 e: w
3 v4 R" n* O5 S2 @! c// Perform the query.
, t0 f1 N( l$ B2 ]" ~8 Mvar results = qryItem.apply();
0 T% q! ~/ \7 _5 E; z4 w: t
; E% \% q5 a0 W" P& w$ k5 w. {- e// Test for an error. ; R( R  X' a% S
if (results.isError()) { 8 R. X5 W# D5 s  X4 H) N' V$ {% u
  top.aras.AlertError("Item not found: " + results.getErrorDetail()); - M5 z9 P, D7 ], T
  return;
3 k( k1 T) x  S}
# l- y2 L8 c0 T  q% U/ D ( I# \; z" ?, j" L" r% t+ B
// Get a handle to the BOM Items.
9 Y% n' l3 G( E4 C' g6 E) Tvar bomItems = results.getRelationships(); 0 R0 @8 G8 |+ Z
var count = bomItems.getItemCount(); # O7 L4 c& n7 H" l

3 k4 ]6 T' f2 t/ j' T// Create the results content. ! M; p+ ]* r; v* x
var content = "<table border='1'>" +
/ X. T' f% ]( _. d5 m. S8 P  "<tr>" + $ M& ^4 A  b* B2 H6 u% `3 f4 t: `
    "<td>Part Number</td>" +
7 ^& ~$ \% T. G    "<td>Description</td>" + 7 M9 c5 c$ r/ _; p& Q& p6 l9 D
    "<td>Cost</td>" + ; u8 Y8 G% ]& M, L" \3 I% ]
    "<td>Quantity</td>" +   T' k* a) m8 @3 Q6 Z9 D1 `, Q
  "</tr>"; , E& b$ v3 \8 H! z: ~* U# B0 h

6 M* w- V$ j7 r+ G* j! A$ X// Iterate over the BOM Items. ' I) ]0 y6 W: \+ a; E- m
for (var i=0; i<count; ++i) 1 X( w  c5 `( L* E7 t% |
{ 0 I, c7 ?) T* R) Y. s
// Get a handle to the relationship Item by index. - D3 Y# R1 w+ n/ t( y8 B% ^
  var bom = bomItems.getItemByIndex(i);
9 z/ C' d6 J6 R' H  x) u// Get a handle to the related Item for this relationship Item. 1 Y. e! j' @1 o/ M" ~) i
  var bomPart = bom.getRelatedItem();
% ^% ^* c& t$ B 7 d% B) G" i- C; y
  content += "<tr>" +
. {& G0 y4 l# @! B. x0 a2 e      "<td>" + bomPart.getProperty("item_number") + "</td>" + ' D. l/ y. Q4 g0 f  C" D
      "<td>" + bomPart.getProperty("description") + "</td>" +
9 j$ [" ?5 R! ^4 T* F* ]6 }/ X      "<td>" + bomPart.getProperty("cost") + "</td>" + $ Q% \8 v/ \: i$ X( j7 }( K' A; K8 Y
      "<td>" + bom.getProperty("quantity") + "</td>" +
) G8 ^3 H+ m3 b) O! U, H    "</tr>";   S/ U* Q- w, T7 U! C
}
8 x% _3 I1 y/ |4 R4 B' B0 \return content + "</table>";
, p. d9 r, E# @( F, k& z" E& `5 @/ p
# o7 D' _) Y) `9 P

' T. x, P+ D0 b- d7 @

6 S# P( |3 z' R- QC#  
& _/ C  T6 R% G9 G7 b) f" EInnovator innovator = this.newInnovator();
8 C. R5 R0 |. w# K- X
6 B, N# K; z4 p3 o# t// Set up the query Item.
# W2 J  {/ q5 g& x! Z* H9 s* xItem qryItem = this.newItem("Part","get");
; X6 B3 f! S0 T( u% u) _2 kqryItem.setAttribute("select","item_number,description,cost");   T' I+ C$ R: D9 R, w4 B' X3 }
qryItem.setID(myId); 6 c( y+ p& I- J$ W; h- `( {4 l
) s; W% s& q7 s# \% A" B. s
// Add the BOM structure.
* q: m2 J9 ~  Y# O; T: BItem bomItem = this.newItem("Part BOM","get"); / I: |2 C7 s9 I: Z( n: r: G/ W9 u
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
) Q$ ]9 m/ z/ {2 EqryItem.addRelationship(bomItem);
" ~5 r- T, X$ S1 Z+ \1 g) Y( `- ? 5 a! Y- i* U4 F) ~
// Perform the query.
/ r# m# {4 O2 R( ?& Q+ kItem results = qryItem.apply();
" p5 @/ }: n- k- r& j6 b, i5 [
- @& y6 p8 Z! @// Test for an error. - d; A/ b) Z( I8 ?% r2 ]
if (results.isError()) { # n* `) [/ z5 y
  return innovator.newError("Item not found: " + results.getErrorDetail());
: D0 h- G# ^- S+ e9 P} # r* {. o; ]; t. e0 W9 N

6 d5 b( g6 U6 n, q3 p* J// Get a handle to the BOM Items. 2 k! e" L1 k1 D9 H
Item bomItems = results.getRelationships();
) {) g4 h% {. \" Tint count = bomItems.getItemCount(); 2 r3 [+ U) Z6 m3 s3 _! j- m0 W
int i;
2 k# C& \- K( E, {7 `' M9 N. h 0 m) m- k- R) U" S; K1 W! d& m
// Create the results content. ' H: _( x! O1 v  D1 r" ]  U
string content = "<table border='1'>" +
4 C1 O+ S$ Z& B5 Z3 |* G  "<tr>" +
7 C# u4 k0 M6 k3 j. a, q) I2 c    "<td>Part Number</td>" +
) d( Z) ?" N# X$ e7 j    "<td>Description</td>" + ' l) |8 r- u' u- [( C# l9 V: @
    "<td>Cost</td>" +
9 ?# h7 w2 \: c6 _8 \2 _; H4 Z    "<td>Quantity</td>" +
% I- L& u. ^  P1 S) A  "</tr>";
- Q' i, L1 D* H( \: N1 w
: }$ |$ N0 [1 `4 b0 M* g// Iterate over the BOM Items. 0 {0 t* y& O) I5 d+ U' s; N
for (i=0; i<count; ++i)
/ y0 n1 s# R8 {/ \- }: G( O; O{ $ A9 c. G/ `: f
// Get a handle to the relationship Item by index.
5 k9 n+ ]2 t$ h) b8 ?" G) E  Item bom = bomItems.getItemByIndex(i); 6 I& F5 O5 T, O8 f1 ]. W
// Get a handle to the related Item for this relationship Item. 9 z( V. {& N* p( g9 f$ o
  Item bomPart = bom.getRelatedItem();
& [0 W$ p1 {! L9 ^  D+ m& V , q8 @% w9 r/ B/ i/ R( n3 O; P
  content += "" +
: [  }8 k9 v% J7 C    "<tr>" +
( j9 M4 c& W4 x  t6 H$ W      "<td>" + bomPart.getProperty("item_number") + "</td>" + + r8 O8 p, T" t2 V: E
      "<td>" + bomPart.getProperty("description") + "</td>" + 5 U! o1 x5 U5 ?* _# [" `" _. q
      "<td>" + bomPart.getProperty("cost") + "</td>" + ' }  W  ]7 N8 r& A
      "<td>" + bom.getProperty("quantity") + "</td>" + 5 ~+ L! n7 x! [$ _$ Y
    "</tr>"; 5 w# @" o% S# u; q  |
}
/ a$ ^' ^& F$ K3 Ucontent += "</table>"; . \# Z, C$ N6 |

9 B% a- e& D1 y, m1 t; breturn innovator.newResult(content); ! O8 r; L2 q6 a$ ~
& ^  x' r0 D  D/ P0 q6 c1 j

  N3 ~: [9 ?$ E! t& c' U
. F3 E: f* n1 L4 u" H* ?
2 X. Y! `4 p* W
# J8 \" y0 b& N6 E0 G4 m: p
, P  T' Q$ i: l! ]) U8 h5 D
/ V1 K# g: w: s0 H& x
    Page 46
/ _& T1 C* X- K8 e
; ^  i; S/ y( ^9 m0 OCopyright   2007
% i; ^2 h! ]; G- o  N6 q( Q; FAras Corporation.  
8 `' V; A0 x' X' X% rAll Rights Reserved. / ]  q/ r' I" B% Q
VB.Net  % _: ?8 Z  S9 A3 ?' L- C' K
Dim innovator As Innovator = Me.newInnovator() , u8 Q) d" c2 U/ m
; \9 Y* [0 S6 Y) x$ m0 e
' Set up the query Item. ( y/ r9 P5 M8 a* O$ ?
Dim qryItem As Item = Me.newItem("Part","get")
" M  S6 J$ q1 {$ ?4 W2 EqryItem.setAttribute("select","item_number,description,cost")
. u& H* \4 B. k1 uqryItem.setID(myId) ! i3 a; Z* i0 f
4 {1 t. e: s! ~5 F/ [2 d' ]; b# g4 E3 V
' Add the BOM structure. & ~2 _4 a- Y2 h! T1 P2 f
Dim bomItem As Item = Me.newItem("Part BOM","get")
+ d7 \5 a$ g" N1 V. L6 n4 U0 f0 obomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
* D3 X6 Y5 i% I8 M3 k  ~8 E  y2 iqryItem.addRelationship(bomItem) 6 h( p0 K; H3 W! m# J! [
1 d. ^6 |1 i! f6 y
' Perform the query. ( z8 \0 m0 s) ?/ f
Dim results As Item = qryItem.apply()
5 l4 p; Z' I6 T2 a: l8 Y
+ ]8 g/ _6 |4 {- W2 w4 n' Test for an error. ) i; ?3 z6 Z; A6 X5 `4 q- V
If results.isError() Then ; E: x2 J9 v, V
  Return innovator.newError(results.getErrorDetail())
& @! J0 Q* G; iEnd If
) ~0 S! [0 ^1 g7 X: ]' @ + P8 e; Y) c% a* v: F: R
' Get a handle to the BOM Items.
' d. M1 E0 k! ?4 \Dim bomItems As Item = results.getRelationships() $ B+ w' ^! b( O: ^3 m5 w9 |
Dim count As Integer = bomItems.getItemCount() $ H! @& `" I! j, j+ Z2 l4 S( x
Dim i As Integer
& k0 c3 D  {! g+ e- R " ?( C) e) v! q2 y& ?
' Create the results content. 7 q  A5 x) T. t, r9 h) |# Q
Dim content As String = "<table border='1'>" + _
6 g' w( {% R& r" x. y  "<tr>" + _ 8 s# d1 a% A: c" u& ?
    "<td>Part Number</td>" + _ 8 }7 c0 B+ A* Y! N$ t! W$ W7 z
    "<td>Description</td>" + _
: j$ v8 _7 p( F0 U9 E  }* ?" ?. C    "<td>Cost</td>" + _ 4 f2 k: a- @' f: |3 M! Q. r
    "<td>Quantity</td>" + _ : F2 n  m4 {" W
  "</tr>" & v5 [3 f/ ^0 z" Z% \, O2 M! F
* R6 Z8 N; d+ l! i# ~5 e$ R" J
' Iterate over the BOM Items 0 }8 |- _, H" p
For i = 0 To count - 1
! ?8 Y6 _5 R" T; \1 W+ v0 ]% b  @- G' Get a handle to the relationship Item by index.
8 n! Q% i% b5 Z( v, ?, A( \  Dim bom As Item = bomItems.getItemByIndex(i) : A! J, [- X& S6 `
. K! ^, y: A2 V8 m  t
' Get a handle to the related Item for this relationship Item. 0 N+ ~( S% x& S% V! k1 O9 K
  Dim bomPart As Item = bom.getRelatedItem()
( `" K$ c' F4 t- q3 \1 @
* q; @% k  i/ G$ [5 m- x0 U. |  content += _
: i1 r# K0 P; S! A9 {- s: P0 w    "<tr>" + _
+ C9 `7 n: X0 ~; |' T8 O      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
% z% D6 i( k, q7 D' v* v! n      "<td>" + bomPart.getProperty("description") + "</td>" + _ & {* L2 v& S* @9 U% ?8 o
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 0 k" t5 k7 ?2 ~2 Q
      "<td>" + bom.getProperty("quantity") + "</td>" + _ 2 Q! B1 ~  \4 Z9 X7 w( }# X4 n8 e
    "</tr>"
+ l$ Q: K6 q2 i$ N  T& LNext
' b& F# Y- N7 a+ h5 Y, bcontent += "</table>" % Q+ c% {8 o$ G

( o3 ], y! ]/ W: A* `Return innovator.newResult(content)
4 a/ \+ B) h. F2 f
1 ?$ D& W' D) J% D# W+ 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二次开发专题模块培训报名开始啦

    我知道了