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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  
' x' J. Y3 g3 ?To query for an Item and retrieve its structure you build the query as the structure
# y- a* N* \/ \9 j& u/ S$ vyou want returned.  Use the IOM methods to add the relationships you want and
7 @% c  M3 S# f6 D. A7 g* ], Tbuild the structure in the Item.  The server will return the structure that follows the / h" i. B& ]% L% W) u' Z
request structure.
, t# @, Y+ n8 I9 D, ^This recipe illustrates several related concepts together, which are how to get a set
/ i; K. {1 r3 X5 C% C6 n. uof Items from an Item and how to iterate over the set, plus how to get the related % ~5 L' A) x7 I
Item from the relationship Item.
2 o" O8 n! E3 T9 XJavaScript  
8 ]8 i3 o. F: X/ R2 Dvar innovator = this.newInnovator();
- K3 Z3 h4 c% j' p
0 x0 ?) U4 _8 t// Set up the query Item.
# ~8 v$ }# c/ j; \+ `var qryItem = this.newItem("Part","get"); 6 h% u# X1 F3 l, u- b. m6 R1 f
qryItem.setAttribute("select","item_number,description,cost"); $ h9 ^5 ^9 Q: a
qryItem.setID(myId);
. l/ I' i: Y0 H0 f9 s" A  P
/ {8 F1 i3 ], [// Add the BOM structure. + i. ^4 V6 j( v, [, ?
var bomItem = this.newItem("Part BOM","get");
" m  M; x7 m0 V+ vbomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
+ T, i" E, X+ k) d6 v& uqryItem.addRelationship(bomItem); ! O9 s( v( C% I/ W: C6 t" _
3 b; I6 j3 @% H9 w2 B0 H! }. i
// Perform the query. - M; T& P( a6 d2 m9 K7 F
var results = qryItem.apply();
. B# o$ q! l! N* c % ^+ c2 g. I: d5 a8 l3 ?: ?% Y
// Test for an error. 1 }, ]4 c, j8 T& k! e  H
if (results.isError()) {
+ e* _8 _7 x% T" k  top.aras.AlertError("Item not found: " + results.getErrorDetail()); 3 A7 b5 n# e2 w) e+ `: L
  return;
5 N0 _0 @: k$ u: D+ S/ |} 3 ~8 K% |0 Q% `& U

* _7 z5 n4 j! ~, y9 k, A, P! z: y// Get a handle to the BOM Items. ' f1 \2 T8 v* T1 X  D
var bomItems = results.getRelationships();
4 }; J; T- }" w( q7 i) Jvar count = bomItems.getItemCount(); ) I8 I$ i, {' V9 v
. `3 a" p3 b0 ?- y8 d& |1 R
// Create the results content. + ~  [; e% V6 B: |, \+ f5 O& X
var content = "<table border='1'>" + 1 Y) I8 r& O4 |$ d' i7 l( l
  "<tr>" + + V5 d- |7 \9 _# v: t( Y/ Q
    "<td>Part Number</td>" + : r2 a* v8 m  P4 \* u: M
    "<td>Description</td>" + 6 r$ `9 R. `: _  I
    "<td>Cost</td>" +
9 `9 Q1 C0 L! Q* V    "<td>Quantity</td>" +
" c' |4 C; o( ?5 g# k  "</tr>";   I( B' P. Z0 D3 u3 C! C

1 R4 F: m& q) a/ w$ e// Iterate over the BOM Items.
# g0 ^+ Q. d' U1 l/ w* i) Mfor (var i=0; i<count; ++i)
! H% b! L+ M! ^3 d& ~3 x{
2 N" O1 G' Q+ x+ @( Q; p3 Z, [// Get a handle to the relationship Item by index. 6 \2 I' b. m, r4 Y
  var bom = bomItems.getItemByIndex(i);
/ E, D7 H- L, y3 B/ ^// Get a handle to the related Item for this relationship Item.
0 p4 y1 w+ N! n  var bomPart = bom.getRelatedItem();
8 i# x8 E; l' V1 d / h$ w% l" ^" {3 n0 @* f. U4 R
  content += "<tr>" + 5 x6 s0 u  {. L9 q& ]9 m7 [
      "<td>" + bomPart.getProperty("item_number") + "</td>" + 9 F9 b7 M$ V3 O7 v
      "<td>" + bomPart.getProperty("description") + "</td>" + 7 o& E+ r$ e4 G7 m
      "<td>" + bomPart.getProperty("cost") + "</td>" + " J; U' ?' A( ^( c- R9 B, B( x
      "<td>" + bom.getProperty("quantity") + "</td>" + 9 r9 f) B9 D7 R
    "</tr>";
( r& p' b5 o" O; v6 V} * q) t3 Z; J/ @
return content + "</table>";. ?0 }, q9 q8 w1 R& M, _& f

/ X6 k0 Q' b% I* n

1 V4 ]( J" |! c- B+ p
7 @% Y5 Q9 m- o

$ ]- `0 x# y' f, i. \1 LC#  
: v9 [! U1 a. p( A- o- i' C0 vInnovator innovator = this.newInnovator();
0 ~: [9 Q! L$ x8 |- R5 {
' H# F9 a7 g* o' i// Set up the query Item. 3 b2 H. R+ q& d# P1 ~# |; Y
Item qryItem = this.newItem("Part","get");
) G: _6 U  H) _' a. \2 O  \qryItem.setAttribute("select","item_number,description,cost"); 5 t9 C6 u- o& y/ p" Q
qryItem.setID(myId); / a7 K/ B/ x- ^7 F% s

: l% _4 |  |) \* V4 w5 W// Add the BOM structure. ; {9 r( f3 J7 H5 V7 d
Item bomItem = this.newItem("Part BOM","get"); & }; B" ]# P0 z- c
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)");
8 `- o3 n: K- G% x/ g  ]. dqryItem.addRelationship(bomItem); . v  C- T$ L' y2 o  Q9 l. D
2 C. ?. q* ]( j  p, R* R
// Perform the query.
/ S1 D  \: e5 h+ FItem results = qryItem.apply(); 2 Z% c1 ]- |" q5 u) p1 M

3 F- K0 l+ J! {. n( i8 S// Test for an error. 6 K1 E/ `# r+ L7 w
if (results.isError()) {
" R, x/ x" r) \+ `5 W  return innovator.newError("Item not found: " + results.getErrorDetail()); # N% d! }0 H4 A0 ?+ X% y& f
} " f& u/ t3 S! q* i
. p$ Q; d5 W5 N% j: A9 b' {& }
// Get a handle to the BOM Items. 4 _3 R* ?! \; h. q
Item bomItems = results.getRelationships(); & `1 J1 l( z' I! ?+ p' m- U4 g
int count = bomItems.getItemCount(); & u2 {+ i$ i! p' y
int i;
( K- X- E" n! ]+ w( _
/ `# T8 V* O2 V: H// Create the results content.
0 w  B) ~! o  rstring content = "<table border='1'>" +
0 u: n& p. I9 O0 ~% N) J  "<tr>" + & w2 r& C0 n( m  c
    "<td>Part Number</td>" + . Q' q$ P, n1 Y% X$ {7 p
    "<td>Description</td>" +
( v* m- N9 ~$ }$ D% D+ l2 G, D5 V' B1 j    "<td>Cost</td>" + ) n9 J2 X) d8 L# S6 y
    "<td>Quantity</td>" + & M3 Z. M; ^8 U( j; v
  "</tr>"; * w% }8 i8 o0 Q& K

1 ^* M* g! t6 @" r  n- A// Iterate over the BOM Items.
+ A1 ^* G1 b& P. ~% \for (i=0; i<count; ++i) $ U  c/ p+ T5 N; T
{ 8 N4 k0 i7 c" r
// Get a handle to the relationship Item by index. 0 {$ Q4 q0 p+ v1 v) ?  ]  q
  Item bom = bomItems.getItemByIndex(i);   }6 O9 S  a% z$ C: z- b9 G; v3 q9 c2 l
// Get a handle to the related Item for this relationship Item.
2 J% i% a# j1 h- l  Item bomPart = bom.getRelatedItem();
) {* D" u# L4 N$ a; |" J; f ) A1 o& l- x# U5 p
  content += "" +
/ W+ }1 e) U) A    "<tr>" +
, N, m4 F0 ], D( P# S      "<td>" + bomPart.getProperty("item_number") + "</td>" + % O* g& ?( I( x) F/ p- V3 S
      "<td>" + bomPart.getProperty("description") + "</td>" + % `/ i. a  a" `" a3 N3 p% H
      "<td>" + bomPart.getProperty("cost") + "</td>" +
* H6 D* }* Q/ q5 L      "<td>" + bom.getProperty("quantity") + "</td>" +
" s& S1 m: [; H7 O    "</tr>";
, G0 r$ L) d6 y6 }+ y2 f} " v, X/ N: k; u! z4 z
content += "</table>"; - ^+ u/ ^: U" Z; G$ c0 \" H9 U9 {) N" k

& k" o) W: d5 }return innovator.newResult(content);
4 r8 i3 t$ E) Y) R8 Y# M
9 t' E4 D5 S8 C) @

3 w) |" l0 w2 o0 M. O  ?/ ]1 v% t2 V' t9 ^3 c' O/ l- Z

8 S. m& T; F8 l: u+ E4 [
5 r6 `% b* y# A' A! |2 U% h8 r
8 e9 k. M' ^0 r% j, I) a' r
9 d% ]5 Q: c# i( Z* p, J2 k
    Page 46 : S4 b% U. o3 {4 k
6 `, M/ g2 u1 D  _
Copyright   2007 8 C0 b) t: b7 C6 l
Aras Corporation.  6 Q3 P+ r# ?9 a. }3 T( m+ F
All Rights Reserved. , ~/ w+ u+ S8 b' f0 a
VB.Net  
& I6 C; j' C0 ]8 iDim innovator As Innovator = Me.newInnovator()
5 M1 F+ @! {5 Z
# G; n  J/ W) ?6 q2 [4 k  B4 ?' Set up the query Item.
7 q2 {; {$ r3 c- M" f( IDim qryItem As Item = Me.newItem("Part","get")   E$ @6 r3 G) y
qryItem.setAttribute("select","item_number,description,cost")
6 f+ l* @% k6 W0 \) ^' YqryItem.setID(myId)
4 Z, a0 }6 z# ?: h6 \9 n
& U9 a, K5 d+ A6 {' Add the BOM structure. 0 O3 G' o2 B, @+ l6 O' j
Dim bomItem As Item = Me.newItem("Part BOM","get")   x- c; g" v$ S; J+ E) Y
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)") ' ?" u6 f; Q& f; Y# ^
qryItem.addRelationship(bomItem) 3 F% e9 o% `$ e

& y3 R0 c) X- x: R! L2 E' Perform the query.
% h9 Y1 b4 c- I" J9 y& oDim results As Item = qryItem.apply()
  Y' M; O+ {( g0 j: n1 a' M7 f ( \, D! j7 o. X$ H& Z4 `
' Test for an error.
+ A# t$ A. f, f5 q, b- x, CIf results.isError() Then   Y, f( f" n5 Z# p
  Return innovator.newError(results.getErrorDetail()) 8 `- X+ A% `8 E4 J
End If 4 z' s  A$ E2 H8 ~5 ^3 F

2 h! F7 `8 w; [5 e' Get a handle to the BOM Items. 4 M# W& C) H6 A5 l$ n7 @
Dim bomItems As Item = results.getRelationships()
5 z% R8 V* z* \7 P) m: h- pDim count As Integer = bomItems.getItemCount() 8 w8 _0 B. i+ d: ]6 M5 Y; _$ @
Dim i As Integer * ^+ b+ n% e9 u
8 O% A. h8 K- U
' Create the results content.
% {5 g4 v- B( J' {  }; bDim content As String = "<table border='1'>" + _
# l8 o+ e% Y; l" O' \! N( w  "<tr>" + _ % L5 g% {% {& ?+ |
    "<td>Part Number</td>" + _ 8 a) M7 W' I; M8 r8 n
    "<td>Description</td>" + _ 7 H% m% a4 V5 H- l) p7 ?; B! s
    "<td>Cost</td>" + _
! Z, Y6 L5 \3 m# f% c; O    "<td>Quantity</td>" + _ $ G' a8 y! Z3 X9 x/ j
  "</tr>" 1 T+ Y0 C* }) E+ X
. m  y& m+ b- B  k
' Iterate over the BOM Items
6 D; A- E9 G) A5 n* pFor i = 0 To count - 1
$ O! G" p6 J* [& l- |' Get a handle to the relationship Item by index. 3 \, V" ?# P) R- @1 ]7 j
  Dim bom As Item = bomItems.getItemByIndex(i) 3 D9 ^% f4 D9 i8 g
% d2 l' x. N+ N2 ~. z* M
' Get a handle to the related Item for this relationship Item.
) Q$ U4 A8 x5 m0 d, [  Dim bomPart As Item = bom.getRelatedItem()
: o3 p! n5 i- ]& p
+ M* E5 [3 z  r" ]# J5 F/ Y* ]  content += _
0 v9 X* @/ x1 ?    "<tr>" + _ ) p) Z' K9 i  n" R/ b
      "<td>" + bomPart.getProperty("item_number") + "</td>" + _
2 \9 S0 c7 ?" J- {% U      "<td>" + bomPart.getProperty("description") + "</td>" + _ 4 l! d% k/ j4 B- X* D) V2 i, W1 J  h
      "<td>" + bomPart.getProperty("cost") + "</td>" + _ 1 `" W2 K. I- e6 J$ i
      "<td>" + bom.getProperty("quantity") + "</td>" + _ ! K/ C4 J- {* q/ v* e' l2 ?; c
    "</tr>" ; `- P7 H& B  }. y# z
Next
" k- i1 |7 Y6 O! J1 z( w& L! ccontent += "</table>" . p" X+ Y% }/ I( D( w0 [$ F% U
& u. p. S0 y8 a' Z' O8 g; n6 L/ Y& C
Return innovator.newResult(content) 3 F. Q# m& z. J- V

9 h" R# D: s, }0 l9 a1 i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了