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

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

[复制链接]

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

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

admin 楼主

2013-10-30 13:46:00

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

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

x
" u( f( k" b2 f! d, z, ~+ s
  1. Option Strict Off% j; m1 |7 S- N, w6 `7 R0 |1 f7 y4 |
  2. * W7 C& Z0 N0 z4 R; v0 H0 O) J
  3. Imports System
    1 J* F- L5 R3 G8 ^- J/ ^$ @6 w
  4. Imports NXOpen
    8 d( A, N6 ]6 ~' ]* P
  5. Imports NXOpen.UF
    8 i+ J- u2 S/ c1 `
  6. Imports NXOpen.UI
    2 h) W9 g7 B  P& E# G* ~5 s+ ~
  7. Imports NXOpen.Utilities
    . T1 P& ?/ c( W' ?+ Y
  8. Imports NXOpen.Assemblies
    6 X) W: v' U( a3 V% P+ c3 S% t  A: {8 T
  9. $ ~. D7 U4 R' _# w
  10. Module create_array_of_all_bodies_in_assembly) g0 G# S! r& D) m) f$ y- O0 d

  11. 2 F! n9 G% m# x2 b% Q2 [
  12.    Dim s As Session = Session.GetSession()/ [& c% y/ Q0 s2 @
  13.    Dim ufs As UFSession = UFSession.GetUFSession()$ b4 x9 A* v- _. w
  14.    Dim lw As ListingWindow = s.ListingWindow4 d" W+ H" G, P. `
  15. 0 A( Q5 p$ ]/ Z3 H0 h+ Y$ e1 O2 e
  16.    Sub Main()
    * w" P. R1 C  H! }2 [3 G' M
  17.       lw.Open()
    # Y$ K: C* e' h# G, E

  18. ! e5 ?. E1 ^, ]% a/ I9 J
  19.       Dim dispPart As Part = s.Parts.Display()
    . b- _7 Y6 F, c, @

  20. , c; [( K" n& `# s  W- m
  21.       Dim root As Component = _% U9 S4 C& q0 j+ t. ?
  22.                   dispPart.ComponentAssembly.RooTComponent
    , E  v. \* Z) }2 ?5 e" M1 l9 L5 G. P
  23. 1 l' S& I1 @! ]. N9 [& \- E
  24.       Dim compArray(-1) As Component
    6 J, u& h6 K- y! W8 h2 L) W3 D
  25. " p% a+ f  |( _
  26.       stuffComponentArray(root, compArray)
    6 d9 v- `+ Q% K0 W

  27. ) R. V, r4 H0 A' b
  28.       lw.WriteLine("Component Array Size: " & compArray.Length.ToString())
    $ J' [: w' m7 C3 b$ q# P. n+ ~2 G
  29.       Dim bodyArray(-1) As Body; ^4 m* E* {& |4 O. n$ p

  30. + E3 F0 R/ w& U. w
  31.       stuffBodyArray(compArray, bodyArray)' U" @/ j6 x* Q2 w, U# L
  32. % J2 u5 j9 Z7 R8 z6 G' ^& s# }0 D8 |
  33.       lw.WriteLine("Count of bodies in array: " & _/ |) [7 [0 F2 n% y5 p5 D  T# \5 `. b9 T
  34.                    bodyArray.Length.ToString())9 I! Y% l* k# }& ^* X

  35. + d# S6 I4 D/ l( |

  36. 9 A+ M( p0 b; {
  37.    End Sub
    7 W  d% n) A2 p
  38. : C4 G+ \7 [* ?8 b& Z3 P' N
  39.    Public Sub stuffBodyArray(ByVal ca As Component(), ByRef ba As Body())
    , T! ]2 ?' u" e1 \% P3 {
  40. . u/ d6 L; `+ l6 [& r# {& u
  41.       For Each comp As Component In ca
    ( v  u9 L: s6 H5 u
  42.          Dim c_part As Part = comp.Prototype
    ! V6 {; f8 A5 y5 n
  43.          Dim localBodies() As Body = c_part.Bodies.ToArray(), \" p% G2 h& \8 [8 u
  44.          For Each thisBody As Body In localBodies( j( J* R. w: K$ x( q6 F2 h
  45.             ReDim Preserve ba(ba.GetUpperBound(0) + 1)
    # F1 ^& |- t: }6 b2 I
  46.             ba(ba.GetUpperBound(0)) = thisBody
    " b! s' h7 S+ u! ]
  47.          Next
    5 d8 `$ o* V: H* F# j

  48. ! }# P* D0 a. L1 i- s
  49.       Next; s/ W/ a0 s4 t4 w5 Z
  50.    End Sub# c( H$ j4 Y/ u6 B0 B5 f, k3 T

  51. " T, T4 y0 K! ]' S8 l+ \8 P' h* o+ u
  52.    Public Sub stuffComponentArray(ByVal cmp As Component, ByRef ca As Component())" T, C+ k+ G' L7 R
  53.       Dim child As Component = Nothing
    & k" k' U6 [; N; G! i3 e
  54.       For Each child In cmp.GetChildren()# V3 Y; T9 t: K$ m
  55.          ReDim Preserve ca(ca.GetUpperBound(0) + 1)
    3 O2 C0 |8 S: p- T$ r
  56.          ca(ca.GetUpperBound(0)) = child( U: B8 }( @9 ^0 m4 i
  57.          stuffComponentArray(child, ca)  [- C" @& b4 r# |2 ]1 |
  58.       Next
    ) X- u- Q1 J4 C
  59.    End Sub
    9 E7 ?/ n' O1 A7 B/ i1 X- n, b
  60. $ W! m& P; A7 ?
  61.    Public Function GetUnloadOption(ByVal dummy As String) As Integer
    5 a( J, T9 B: R" L( M7 B

  62. 4 R0 y% N& t  c, y
  63.       Return Session.LibraryUnloadOption.Immediately2 T/ m& o1 J, V9 J, k8 ^/ K
  64. ; L8 d+ M- r, U# j% i5 [
  65.    End Function
    & {2 V. b- |- x
  66. 4 l* z4 o  b0 I! `- j' d" r2 e7 z
  67. End Module
    4 t$ d; l- k( O. v, v  {
复制代码
. Y6 X: ]% C2 l8 C8 G4 q

3 J: t: [+ t" n# Z3 K  M; s5 S$ C: k! F- s8 o7 _
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了