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

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

[复制链接]

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

admin 发表于 2013-10-30 13:46:00 |阅读模式

admin 楼主

2013-10-30 13:46:00

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

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

x
- J/ ?- k3 {) d
  1. Option Strict Off
    ( R  m- k: ~* D3 i3 N6 U0 s

  2. * z# }+ i) _# f4 |$ _0 z
  3. Imports System4 T8 Q2 H- n, |9 ?8 d1 p7 b( }
  4. Imports NXOpen
    6 f1 V! o5 L- |" l8 b& {- u
  5. Imports NXOpen.UF
    . R' \2 q& l% Z3 H+ Y1 M" v
  6. Imports NXOpen.UI8 v' }/ t$ |6 Z  C
  7. Imports NXOpen.Utilities3 r7 R% t3 d- \3 z8 i
  8. Imports NXOpen.Assemblies
    2 p; j" T0 R: _
  9. 8 a# e" x5 k' p4 ?. d" N4 L
  10. Module create_array_of_all_bodies_in_assembly
    % ]' b6 W. g( |6 _' E( }

  11. ! m9 L& Y- ^2 j' X. ]
  12.    Dim s As Session = Session.GetSession()
    - O: m& r6 {) o5 r" {" k+ U0 m
  13.    Dim ufs As UFSession = UFSession.GetUFSession(). }4 K: ]1 @: }* K* b/ A/ T
  14.    Dim lw As ListingWindow = s.ListingWindow0 I6 u: n9 y% |2 q. `- p8 _9 `
  15. * Q" E  v. z7 d# |
  16.    Sub Main()
    ; K% l, `% {, `( X! T
  17.       lw.Open()
    1 T3 a5 X9 M. D& q+ m5 H

  18. $ g0 p# @& x" o  t
  19.       Dim dispPart As Part = s.Parts.Display()+ \: N" ?' y3 i

  20. ; J: d4 |9 r" j1 q$ k, L
  21.       Dim root As Component = _) c6 z0 u$ ~' u+ |3 }8 ?% T, f
  22.                   dispPart.ComponentAssembly.RooTComponent/ d2 @" ?8 l9 x9 ~% V

  23. + }) y- Y8 G0 H, S# }
  24.       Dim compArray(-1) As Component5 A' B, z6 ~, J9 y! u1 z
  25. ; E+ ]' F/ R3 g/ }
  26.       stuffComponentArray(root, compArray)
    8 `$ i* r3 n* U, I5 f% }
  27. : \( P* |+ a& i3 k7 M
  28.       lw.WriteLine("Component Array Size: " & compArray.Length.ToString())4 U4 k  s7 }3 E9 r$ T7 w8 l% `; y5 ~
  29.       Dim bodyArray(-1) As Body
    & r' \# |% F6 B0 a

  30. " x9 e! f( h) f+ r
  31.       stuffBodyArray(compArray, bodyArray)
    % w* j+ U. W' e. R# L
  32. , c" U. f$ U  L1 V* _
  33.       lw.WriteLine("Count of bodies in array: " & _" n6 {* E1 H/ Z$ F' B( O8 x, i
  34.                    bodyArray.Length.ToString())
      M6 f5 `/ b) X% z1 @
  35. * C" h7 L2 V! s) S

  36. - P; f. w% d$ F/ N7 T; W! W
  37.    End Sub
    1 f) X; S1 s- L; l

  38. ) ^7 j( O' G+ j$ C7 F
  39.    Public Sub stuffBodyArray(ByVal ca As Component(), ByRef ba As Body()); s; i0 s. h( E
  40. ( W5 I# g& n( q/ S3 O" u( a
  41.       For Each comp As Component In ca9 ~, M* m- n5 A$ F
  42.          Dim c_part As Part = comp.Prototype2 l( n" v* `. r" ~
  43.          Dim localBodies() As Body = c_part.Bodies.ToArray()3 ]% K0 B4 r9 D' X2 m9 ?8 n$ n$ D0 c
  44.          For Each thisBody As Body In localBodies) j$ A! D/ Q. t: h1 h. k4 w
  45.             ReDim Preserve ba(ba.GetUpperBound(0) + 1)
    5 M% }/ \. s8 K2 M, v& A
  46.             ba(ba.GetUpperBound(0)) = thisBody
    / R( p# |1 _1 k2 v) J" w! S: [" P3 g
  47.          Next
    6 t/ C0 j& ^$ U, s+ g) [5 `$ i1 d
  48. ; Y. X4 c1 @& j# O& `1 w  c
  49.       Next
    / ]: s, U  D6 S( g' N& q; c+ \
  50.    End Sub
    / _. \: ]4 @/ l6 S+ D& b6 c9 H: F
  51.   g, v! r5 I: |3 {" O
  52.    Public Sub stuffComponentArray(ByVal cmp As Component, ByRef ca As Component())  b$ C  B7 E% t- i
  53.       Dim child As Component = Nothing1 f- o+ p1 Z/ Q5 y
  54.       For Each child In cmp.GetChildren(). J$ W: ^$ P5 o; [  k# p9 G/ N( A
  55.          ReDim Preserve ca(ca.GetUpperBound(0) + 1)
    % E; K/ r1 \, s& c3 v
  56.          ca(ca.GetUpperBound(0)) = child
    ) H! ^  W: u- Q. S3 A1 u
  57.          stuffComponentArray(child, ca)
    0 s  _  N6 s& M5 h3 h% _
  58.       Next: C+ ^) p+ [/ i0 h' _
  59.    End Sub
    8 y, S) V) |* [( @7 d; ~& e! `

  60.   `  ]9 P% k; @  |2 N8 }. f
  61.    Public Function GetUnloadOption(ByVal dummy As String) As Integer
    : J/ h) Z& O5 f8 L; W. y: u/ r9 l: z

  62. ( G- K* j9 @) E7 c
  63.       Return Session.LibraryUnloadOption.Immediately  Q9 U3 ]  ~* P3 \- A3 y1 Y

  64. ; G  p. ]1 C% p6 |9 ?
  65.    End Function
    ' i) ]+ }) ~/ I. P7 m" s! W2 \

  66. * I# T& X- e$ p2 M2 @: D% o/ z6 x
  67. End Module$ q' T/ y+ U! q5 Z5 g& p
复制代码

0 m0 J- o4 c5 h! [3 O! _* B0 R5 n# b; b5 `; S9 m
6 L1 Z* |% ~( T& \
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了