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

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

admin 楼主

2018-8-1 13:41:14

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

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

x
Technique  / [$ s/ v6 w) O. E9 N, u2 R
To query for an Item and retrieve its structure you build the query as the structure
, i4 A. [% U. s1 a( Nyou want returned.  Use the IOM methods to add the relationships you want and , j5 V6 m- P& b& @* u$ }
build the structure in the Item.  The server will return the structure that follows the
% Y. Y. i" |+ Urequest structure. 6 F3 P& w0 c, V6 a5 b. ?
This recipe illustrates several related concepts together, which are how to get a set 7 Y2 K6 Q4 n6 s+ p( y0 R: E2 {. h
of Items from an Item and how to iterate over the set, plus how to get the related # {+ z, O4 V8 [) S: o2 u; g
Item from the relationship Item.
" y* S% G$ F5 t8 j4 U" L: cJavaScript  
; y7 `" z" f* F3 pvar innovator = this.newInnovator();
9 P% n# K0 j: d9 J
/ G+ T) F; N0 n3 T* z5 g$ ?// Set up the query Item.
! x6 v8 O: v# @" \* N# d7 t$ [  |var qryItem = this.newItem("Part","get"); 8 [# q8 C' s& H  g& R% R2 W
qryItem.setAttribute("select","item_number,description,cost");
4 P" m" S$ S& v9 m, F1 HqryItem.setID(myId); ) G' F+ M8 c3 ?8 @. x
2 T* ?5 }6 t# {" B% i3 C4 G
// Add the BOM structure.
" c: S* a9 F! w, J6 }. Y. B+ gvar bomItem = this.newItem("Part BOM","get"); $ \! ]; X4 V7 H; E9 B3 ~
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)");
  j8 B! m3 d% D3 zqryItem.addRelationship(bomItem); + o2 j6 A. ~# D4 E

) R+ O0 K5 m8 f  [, E0 A$ U// Perform the query.
  A2 K3 J# V2 A0 G% yvar results = qryItem.apply();
' i! C" \8 K0 Z' s+ e / o) ?" z; J8 r
// Test for an error. ( h3 D- i, o' y7 C) m
if (results.isError()) {
7 ?- O$ }2 x5 b  top.aras.AlertError("Item not found: " + results.getErrorDetail()); . m3 Q, i. u& P. H" P. V3 Y$ G
  return; ; B; ?6 C& g# G& l
} 4 Y" r' ]8 x- n- Z- a% Q  I  {

5 R' S" L  v5 T8 a; p+ o; _" S// Get a handle to the BOM Items. 9 p$ `7 Z1 g; V' q8 w
var bomItems = results.getRelationships();
$ t2 \$ T4 t- Pvar count = bomItems.getItemCount(); $ `- z. M5 k8 F
5 t9 x% m- |/ j# {9 H' ^2 A
// Create the results content. 1 ]" K6 a9 u/ H# [( n" V
var content = "<table border='1'>" + + Q. j. U: T  z% L) s" t& v# u% i
  "<tr>" + 7 J# o6 Z; M+ P! o
    "<td>Part Number</td>" +
: `& r6 q0 H. q/ i; d    "<td>Description</td>" +   [, P2 p/ p/ ~
    "<td>Cost</td>" +
0 s! T( R- {* \4 F. x    "<td>Quantity</td>" + 7 Q% u( `1 e& R8 p+ |
  "</tr>"; ' S# b5 e5 d* a7 F) Z2 y
' W5 `5 S% M7 [) p" |' L1 i
// Iterate over the BOM Items. ! k0 g9 ~  B/ K" R
for (var i=0; i<count; ++i) $ y3 d# l. ^) F. C9 `) x
{ 7 O8 g* ^+ U! i0 w! z& U
// Get a handle to the relationship Item by index. - }  z1 V6 ^$ H3 Z$ n! h
  var bom = bomItems.getItemByIndex(i); 9 }; o1 W( ~' M1 C2 _1 w
// Get a handle to the related Item for this relationship Item.
) D9 d$ X2 O8 Q  var bomPart = bom.getRelatedItem();
- H+ c0 R) w0 C. R( l) @& o6 l 9 r% `  B" Z' u1 `; y/ v, i
  content += "<tr>" + $ o. C' X. t2 A9 V1 I5 i
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
) k7 O9 V# \3 n8 t/ o9 o      "<td>" + bomPart.getProperty("description") + "</td>" + % q  u$ d: k# q. P( A& J1 z
      "<td>" + bomPart.getProperty("cost") + "</td>" + ) ~) Z) J$ x" ]/ h& I1 i/ y
      "<td>" + bom.getProperty("quantity") + "</td>" + , q1 K1 I6 ^& u/ q1 `$ P
    "</tr>";
8 U# ^7 Q. w1 x5 e* ?% U% c* p}
( [- P1 v: I. B$ c1 Z0 R) E. _. z  i- ~return content + "</table>";: v5 l6 l; m- \! {8 f# ?
) Z$ J! a' |, ?# V2 ^
! `% ?- L+ P8 K5 b# e

! D' v0 z4 r2 g# M: Q* m

" A5 {3 g- }7 aC#  
6 |2 c: N* I; J3 U% XInnovator innovator = this.newInnovator();
( O6 e0 U! Z: _3 \8 h! Y0 e& c$ f
7 E! T  u" U, D6 J) i  N3 i// Set up the query Item. 8 r7 C' M8 S: u7 O0 h9 c0 s
Item qryItem = this.newItem("Part","get"); 3 b2 n9 [4 G- g" B4 q- |
qryItem.setAttribute("select","item_number,description,cost"); ) Z( Q/ x; h& h
qryItem.setID(myId);
4 s' J3 ?) _4 R5 s0 ~: [7 T 7 V: T8 m6 T1 `+ @4 c$ l
// Add the BOM structure.
* I5 S; o- D1 U+ uItem bomItem = this.newItem("Part BOM","get"); 6 W) h) A7 {5 x1 c7 x
bomItem.setAttribute("select","quantity, related_id(item_number,description,cost)"); ' M9 {  N6 T% t, P: ~
qryItem.addRelationship(bomItem); + c) \* }8 |( w9 {9 w, n. x
) k% r3 B6 s; o9 A
// Perform the query.
3 b( M6 R/ A6 LItem results = qryItem.apply();
, x: K/ Q% @, Y( g4 e6 _
+ J% R0 c& e, p7 U2 V// Test for an error.
- M7 r/ k1 H& t% r6 b7 D( O! fif (results.isError()) {
# I  ^) c& V4 l, a  return innovator.newError("Item not found: " + results.getErrorDetail()); / b$ I3 e, H' H) r# j0 n& R& J5 z
}
0 Y- f4 W. [. ]  h, d  ]0 t 6 I( H; Z) P0 O! ^: _  ]8 Y6 _0 y
// Get a handle to the BOM Items.
8 F" D- q. l4 U5 A7 h& bItem bomItems = results.getRelationships();
% q' U1 P8 j7 F  W7 N- G: Nint count = bomItems.getItemCount();
+ j9 u/ p# c9 p4 fint i;
" F; j) p1 j! e, D7 ^, G1 w+ F
5 Y, W1 i( m5 Z, L) h% N4 a7 \3 ]// Create the results content. 3 }6 a! y6 y. @: `8 h4 C. E
string content = "<table border='1'>" + ) U9 ?* y' K0 ]  V) z5 T
  "<tr>" + 7 i6 I" I) ?( g3 h( V7 a6 v
    "<td>Part Number</td>" + 9 Z( l+ `" E& L6 L
    "<td>Description</td>" +
6 @' G# w1 m5 j1 V$ r& f    "<td>Cost</td>" + & t$ H# t  Y3 k+ `+ |
    "<td>Quantity</td>" +
9 A8 k, I9 a5 |- B2 c  "</tr>";
' T" P! z: b6 w) B4 j1 R3 o/ ? ) |0 w/ f! n# E$ D) {
// Iterate over the BOM Items. 7 c# I; z) A3 I5 r# U7 G
for (i=0; i<count; ++i) ) u: P$ S1 I9 Y; ~) r
{ ! d! P) t& v- N7 @
// Get a handle to the relationship Item by index.
% C2 W3 w& Y( [0 |% r  Item bom = bomItems.getItemByIndex(i);
5 c: D5 J: `+ Q9 g/ G// Get a handle to the related Item for this relationship Item. , r& e' u7 k2 h' Q0 v2 ^5 ^* w- [
  Item bomPart = bom.getRelatedItem(); 0 `  |  G, y2 y4 e& g
+ z0 ^$ W2 S8 `* ^( K1 j& @
  content += "" +
) Y( e- J  M; O% ~+ }  ^    "<tr>" + , q# Q! K+ V" i+ T# [7 p& ?4 u
      "<td>" + bomPart.getProperty("item_number") + "</td>" +
7 g+ z7 H' m5 l4 F* |6 ]      "<td>" + bomPart.getProperty("description") + "</td>" +
: S# z8 }% m6 n: [0 V) n, L& g      "<td>" + bomPart.getProperty("cost") + "</td>" + ( R2 Q/ I, p0 `5 z3 G; V
      "<td>" + bom.getProperty("quantity") + "</td>" + / `! i- w2 d$ I& |
    "</tr>";
/ j% i6 ]0 D  d5 f9 Q}
! i5 R) l* `) n- G3 Xcontent += "</table>"; + f  Y  z" |5 z1 Q
; S4 `- V+ I" }/ L4 S# c
return innovator.newResult(content); 0 X0 c( B+ ]  Z
2 a5 R' B  _- \5 M: A
8 y) o) l; [# ^9 l- P2 y& P
5 y( @$ P5 z* W6 v. K
5 o# I' i  Y3 k' c
9 |+ t$ D( T; h( a5 H

/ H1 a+ S6 n% N3 I1 _! f* C
" F) A- S- ~% }    Page 46
+ P* T* t- o! `/ B2 @+ e1 c
& v6 y& y! d$ UCopyright   2007
$ j5 A$ e7 C2 u% j$ u5 ^+ t+ |Aras Corporation.  
- p) U6 s9 c( |4 w0 kAll Rights Reserved.
; X/ ~1 D) X# s9 e. ^$ i0 H8 _* oVB.Net  * Z7 C. E7 S7 z( k
Dim innovator As Innovator = Me.newInnovator() 8 h' a  u+ O' v7 L% o; Y1 F3 u3 M

$ p* P5 Y5 U- Q" {( g' Set up the query Item.
9 m5 b! v; W. ?6 `, uDim qryItem As Item = Me.newItem("Part","get")
' y: @) J* v: {4 W$ H7 fqryItem.setAttribute("select","item_number,description,cost")
) {! l/ F: M7 \8 U: g. QqryItem.setID(myId)
$ N  E  {& F( {) k9 R2 g6 h. _ ( _$ l$ L! [6 c$ A2 u9 M$ n" J
' Add the BOM structure.
( }7 ]9 b7 y7 x  d" o* O% |7 }1 WDim bomItem As Item = Me.newItem("Part BOM","get") . {" \7 j3 _( g2 e% f* K
bomItem.setAttribute("select","quantity,related_id(item_number,description,cost)")
2 k; \0 }4 S- \! A# Z' I' |qryItem.addRelationship(bomItem)
) \9 B/ i- E% _+ r9 Q
+ J# c) m( C& w6 b* ]( N8 v% e' Perform the query.
& Q" X. Q9 W+ CDim results As Item = qryItem.apply() : u1 k8 Q) B8 L2 l9 @! S

: Q9 G' t, C1 z: H$ E( K' Test for an error.
, S$ F) `& w7 X7 F* A8 NIf results.isError() Then ' b2 \; b3 A4 p$ J1 K7 S
  Return innovator.newError(results.getErrorDetail())
7 G8 \7 k' z5 `- x3 h% hEnd If / {4 l" y% d! o3 J" b
2 E7 k, f4 {3 O5 U( @
' Get a handle to the BOM Items.
- L( d/ v* R. l6 L9 QDim bomItems As Item = results.getRelationships()
9 R) W8 {/ B- W  ?. Q& wDim count As Integer = bomItems.getItemCount()
% T( f% n% K9 yDim i As Integer
" H7 ~9 @. U0 g1 L9 y- g 1 f  Z) b0 D& A$ |6 V
' Create the results content. + I* s1 J7 o( l4 P) R4 B
Dim content As String = "<table border='1'>" + _
! N9 D3 o0 E1 x  "<tr>" + _
! r/ z; T7 @& |  r' U    "<td>Part Number</td>" + _
* r4 Z/ e9 S$ n    "<td>Description</td>" + _ / l/ Z" R- w* |( {! E
    "<td>Cost</td>" + _   S  P5 C6 v& s+ j- R4 s- ]
    "<td>Quantity</td>" + _ # f: @8 s; e% ~' J5 _) l% p* M
  "</tr>" 0 i) k8 Z: p" b* J

# m& x5 H4 v2 H, i6 X- a' Iterate over the BOM Items
2 z1 k, ?3 z" L% \5 r6 AFor i = 0 To count - 1 0 X5 K& P7 h! }4 J% K$ A- ?. r
' Get a handle to the relationship Item by index.
! ~% b* j' t  I( l) S" T/ B$ j  Dim bom As Item = bomItems.getItemByIndex(i) * X7 y% F* p+ E" E; E- `& V/ }% ^0 s1 e

& }- V% d# \( x' Get a handle to the related Item for this relationship Item.
* H' ]6 N9 U; Y# O7 ?  N  Dim bomPart As Item = bom.getRelatedItem() 8 u! ^5 Y) u$ g$ E

) x5 i7 p& w% `! U) w+ Z( r0 P  content += _ 9 a# q0 a! d2 {) [
    "<tr>" + _
: }5 L( W, t3 J      "<td>" + bomPart.getProperty("item_number") + "</td>" + _ 2 Z% ~. G2 @0 _$ l
      "<td>" + bomPart.getProperty("description") + "</td>" + _
7 K/ j) r- L6 H" M5 T  |5 R$ q      "<td>" + bomPart.getProperty("cost") + "</td>" + _
. S7 z1 _6 Q7 s! }. B4 X, ~# A0 J1 ]      "<td>" + bom.getProperty("quantity") + "</td>" + _ . M) J( h# n. q5 |2 c! F7 m3 k/ f4 I$ G
    "</tr>"
/ Z; X9 X0 H7 sNext . x$ e5 B& |" [- B1 F, i. `7 N
content += "</table>"
! ]% d1 W& r) I5 D" c6 ~ 5 c+ Z" W) O- ?$ H0 m7 Y
Return innovator.newResult(content) ) h4 L! F( N2 P, V

' m+ I4 A# v7 L- H) c( l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了