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

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

[复制链接]

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

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

admin 楼主

2013-10-30 13:46:00

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

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

x
0 k* J, }+ q* R4 e
  1. Option Strict Off- L8 F* x" d: E: m" H" f
  2. ) A, l) V: M; W- O# M
  3. Imports System) @9 b6 U3 J" a, x, c, G% y% ^( J
  4. Imports NXOpen& @" G% r: X& |, x
  5. Imports NXOpen.UF
    % s  w3 v7 o2 w! W) S, ]7 n. y# K
  6. Imports NXOpen.UI0 w+ u( r: y- j  y! e$ Y
  7. Imports NXOpen.Utilities' F) o* i4 g+ t* Z# u
  8. Imports NXOpen.Assemblies
    5 V% v1 x2 {  V  [  m5 u, z

  9. 2 P- \& P5 n: L. I8 \& N! Z8 ^) \
  10. Module create_array_of_all_bodies_in_assembly
    6 a$ [! S6 b3 c$ A

  11. 2 _7 F& Y& ?; I8 K4 q  V
  12.    Dim s As Session = Session.GetSession()' U# g) ~8 N$ E" ^
  13.    Dim ufs As UFSession = UFSession.GetUFSession()
    # O+ E8 |6 R" D
  14.    Dim lw As ListingWindow = s.ListingWindow9 A7 e4 J) n/ u! w0 E/ i5 X

  15. - S: ?0 O( m+ |1 [8 b9 ?( h( f* v
  16.    Sub Main()9 J: ?# n" H. B) R: P! ?* M
  17.       lw.Open()
    $ S3 q% c: g& |) [3 v' D
  18. % [% G! M. Z: J  l% h- j& q2 r
  19.       Dim dispPart As Part = s.Parts.Display()
    . u& f$ ?: ]  Q$ l$ z2 g
  20. 7 c* x. a. c3 Z! B
  21.       Dim root As Component = _; N0 y9 L7 ~; B$ l, l0 C- w9 F
  22.                   dispPart.ComponentAssembly.RooTComponent
      b8 P9 K/ @. Y
  23. % a9 e% ]/ @2 G- X
  24.       Dim compArray(-1) As Component2 C2 h. X( E. M" Q5 b  E
  25. ' c0 L+ I: O% J# {, \+ [3 a2 b) I9 n
  26.       stuffComponentArray(root, compArray)" |8 u  \: S: ~+ F3 ~
  27. $ p6 w2 e% _& G* g2 L  G
  28.       lw.WriteLine("Component Array Size: " & compArray.Length.ToString())' P0 X& B8 U. Q# F& E
  29.       Dim bodyArray(-1) As Body
    % x8 D! J! z3 D4 r2 O- Q0 I

  30. + l3 `  U2 b7 u
  31.       stuffBodyArray(compArray, bodyArray)  m5 V: d. L8 g9 N) Z7 m

  32. . k0 i" e* ]9 P" N7 k' @  Q
  33.       lw.WriteLine("Count of bodies in array: " & _+ B" a( I) N7 e
  34.                    bodyArray.Length.ToString())) ?, l( O9 C, C' [
  35. ' k: e; L# w$ o9 _1 x, ]. _- H
  36. # \+ z' Y9 {, x- b
  37.    End Sub; u; H9 d& m+ p
  38. 9 m  w. ?0 U" }( Q5 t0 e1 \5 k. j
  39.    Public Sub stuffBodyArray(ByVal ca As Component(), ByRef ba As Body())$ [8 h- u* u, b9 z1 f

  40. + D; W# X* ^: F4 g. ?: |
  41.       For Each comp As Component In ca
    % o2 T- x1 `. p0 {0 X; y
  42.          Dim c_part As Part = comp.Prototype
    - x! o% |' o) S2 a* ?! l
  43.          Dim localBodies() As Body = c_part.Bodies.ToArray()
    6 ?9 N) W. o3 v# b; J8 _* G
  44.          For Each thisBody As Body In localBodies- \3 p) n! ]8 M( T' {  F
  45.             ReDim Preserve ba(ba.GetUpperBound(0) + 1)2 H+ I) R+ t' r6 h  a: O
  46.             ba(ba.GetUpperBound(0)) = thisBody7 P% D* ~, W8 b2 D% Q
  47.          Next, J, c, H( Z3 i: m0 F* H* T

  48.   e# ?  @3 f6 d& M2 c( G6 H& |
  49.       Next
    $ Y( t( c: j' |2 v. x9 |- s
  50.    End Sub5 ]' g- k4 Z/ D! y! l9 ~

  51. 4 p- c: i: l9 J# \
  52.    Public Sub stuffComponentArray(ByVal cmp As Component, ByRef ca As Component())5 a& L& V- ?4 Z4 Q, H' w2 b- L
  53.       Dim child As Component = Nothing; G$ \$ g0 g5 j* A/ N" y
  54.       For Each child In cmp.GetChildren()
    ) h: @; K6 N# x0 T6 E5 i- O
  55.          ReDim Preserve ca(ca.GetUpperBound(0) + 1)
    ' s3 `7 {( p& T; K7 b: D" K
  56.          ca(ca.GetUpperBound(0)) = child( Q! j' p' H; z+ t2 b& }9 z
  57.          stuffComponentArray(child, ca)+ y) @( R( {6 i, i+ B. D) e# x
  58.       Next
    8 [& ~4 O) p& B! c7 a: J. i' ?
  59.    End Sub
    & n/ E- }5 x5 I

  60. 3 q; E+ ~" n" ]6 e+ m
  61.    Public Function GetUnloadOption(ByVal dummy As String) As Integer' T( }( Y/ e/ v, w7 q/ }" s
  62. $ Q' F* h( a# k7 T$ Y: o/ J
  63.       Return Session.LibraryUnloadOption.Immediately
    6 i4 I% ^( t. L/ z" g5 D
  64. 7 o& X- A# g. s: M0 ~
  65.    End Function
    ) ^  u& {1 R2 O( c& n, I# b) t
  66. + ~( |6 |% h/ M! Q* N% Z
  67. End Module4 E) r- s: p4 |
复制代码

8 Q! }3 R7 T8 A$ T8 ]2 s# o" _' v2 I0 q; e

& @+ S# O: n$ b! ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了