PLM之家PLMHome-工业软件践行者

[二次开发源码] NX 二次开发源码:从整个装配上获取所有的实体

[复制链接]

2013-10-30 13:46:00 3845 0

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2013-10-30 13:46:00 | 显示全部楼层 |阅读模式

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

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

x
2 b" t! |, q# w" L# l+ D
  1. Option Strict Off3 O8 x, z, }' y$ f# U
  2. " o1 W% U) `3 H; e$ n8 y1 M/ Q9 ?
  3. Imports System, U, E' U' J) M! F& L1 i) O
  4. Imports NXOpen) k' |8 A  O& y. ~) |
  5. Imports NXOpen.UF" t2 f0 u2 [& R/ }! H
  6. Imports NXOpen.UI
    + S* g0 L' E/ a) h
  7. Imports NXOpen.Utilities+ u. j9 Y5 F- v+ ^, W: @5 c! _
  8. Imports NXOpen.Assemblies2 f( j/ G8 m1 p$ f

  9. 4 {; l$ W7 l: r
  10. Module create_array_of_all_bodies_in_assembly
    2 w6 W% D3 W/ a' T5 y
  11. % k* M: h# B  @) M9 v. Y" A
  12.    Dim s As Session = Session.GetSession()
    ( D8 E3 N& n( U: ^6 x$ ^
  13.    Dim ufs As UFSession = UFSession.GetUFSession()
    3 X. M, r* j% B% a& @% M2 _
  14.    Dim lw As ListingWindow = s.ListingWindow" [, z& i: w; J7 D

  15. . j6 f9 K# F& t+ l
  16.    Sub Main(): L7 |" z) d- k+ w
  17.       lw.Open()/ J5 K1 L; A" m4 S

  18. 5 y' u! B( g& D
  19.       Dim dispPart As Part = s.Parts.Display()+ f/ S( |3 j) P- i- J

  20. 7 v1 R! t. V6 n% [
  21.       Dim root As Component = _1 N* W6 t, e8 _5 L( o* d6 [
  22.                   dispPart.ComponentAssembly.RooTComponent# @1 R' `6 X' i+ c; p# N, m4 F
  23. ! m: h# p1 b. A& e1 V
  24.       Dim compArray(-1) As Component$ W* j% W7 j- f. F

  25. , E' M3 a+ I- I9 @& G
  26.       stuffComponentArray(root, compArray)
    / L& x5 j9 }0 M5 U

  27. 6 P  A6 o/ H8 z5 p& d6 I
  28.       lw.WriteLine("Component Array Size: " & compArray.Length.ToString())1 L3 ^( \9 G) t( y1 r5 H' B6 U
  29.       Dim bodyArray(-1) As Body+ n" k& Q" {1 D# C2 C

  30. - K/ n+ \& o3 M0 u& I( A
  31.       stuffBodyArray(compArray, bodyArray)
    " J) ~" J+ x" ?, p0 i0 Y$ k

  32. % ?' H5 |- E' l' Y) L
  33.       lw.WriteLine("Count of bodies in array: " & _
    1 x: K2 K$ P; x& t- C
  34.                    bodyArray.Length.ToString())4 o  T& S- Y) t. n

  35. : R" l8 `$ d/ @) j5 g
  36. , b6 r7 r8 T8 K) S7 c  s
  37.    End Sub& ]+ d3 b* t9 |- V

  38. + V4 I' ]$ Q3 _9 s
  39.    Public Sub stuffBodyArray(ByVal ca As Component(), ByRef ba As Body())
    0 ?$ A2 l* p4 w' @5 c" ]  s& _

  40. % f* F) t2 D. G6 Y0 |
  41.       For Each comp As Component In ca
    % C+ G( F+ `! p& W" L7 o
  42.          Dim c_part As Part = comp.Prototype
    ( w( C6 w4 F' z
  43.          Dim localBodies() As Body = c_part.Bodies.ToArray()
    9 q! Z. D2 u' G# O  H2 n/ b" g5 [
  44.          For Each thisBody As Body In localBodies! a0 M( O7 i4 e; o' C
  45.             ReDim Preserve ba(ba.GetUpperBound(0) + 1)5 ^1 {, u- O3 e  o4 x& ~% f
  46.             ba(ba.GetUpperBound(0)) = thisBody
    : I5 z+ ~; |- P( C
  47.          Next9 D5 C. t" K* O

  48. % c) b4 w) |* s' o: x0 v
  49.       Next
    % `5 p* D# O. m6 q
  50.    End Sub9 D' \' Z, L; g8 g( V5 C
  51. + e9 G. ?) @( M3 P( c
  52.    Public Sub stuffComponentArray(ByVal cmp As Component, ByRef ca As Component())1 Y5 i2 U( X& ^) A) D% t$ t$ ?
  53.       Dim child As Component = Nothing
    ' h2 Z4 ]; Y( L8 W. M5 c# K
  54.       For Each child In cmp.GetChildren()
    , T2 E% H/ k- v
  55.          ReDim Preserve ca(ca.GetUpperBound(0) + 1)6 O% U: D, Q% r/ S- t0 M% u
  56.          ca(ca.GetUpperBound(0)) = child* _  C7 Y6 T" ~8 }
  57.          stuffComponentArray(child, ca)% E* \" S. B( \: _) K4 J
  58.       Next
    + |/ f; B' B" |6 M
  59.    End Sub
    ; ]. D- V+ r( c" |/ s
  60. - e: D# N8 o6 K0 J
  61.    Public Function GetUnloadOption(ByVal dummy As String) As Integer
    1 W) s4 H' e# j# l! S% U, K
  62. # z1 h/ Y) _8 G& S; Y8 m& p  c  {
  63.       Return Session.LibraryUnloadOption.Immediately
    " `# X! m$ w+ ~' ~0 C/ G* r
  64. $ x4 q8 |2 E% c( ^' B
  65.    End Function9 ]4 R6 @9 a# Z' a9 b4 @/ z1 M

  66. / T3 q* c/ k9 k2 o/ Q6 \
  67. End Module) P( G/ w; h" `3 W: `8 J* E: y+ g
复制代码

3 g+ O0 z  ~" w; ]2 V3 X$ d* O/ k# G7 y5 S
1 y/ I$ o! F! R5 V& c
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了