查看: 2501|回复: 0

[二次开发源码] NX二次开发源码分享: 加载所有的装配组件----全部加载

[复制链接]

4

主题

3

回帖

44

积分

管理员

积分
44
发表于 2019-4-12 09:06:31 | 显示全部楼层 |阅读模式

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

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

×
[mw_shl_code=csharp,true]Imports System$ @- W& O; K$ S
Imports NXOpen
* F* s$ q$ v8 T- H: `  j- bImports NXOpen.UF) R$ f: [: c, w1 b$ ]; T( \( x
Imports NXOpen.Utilities" l3 a$ ?* W8 y4 ]+ T
'
- o9 p1 R: i2 v. P) z/ E$ h' The OpenComponents() parameter0 G# F8 A/ A6 D+ }
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly4 a: T. v( H: I
' only opens unloaded components fully (see also PR-8406345)0 F! S4 _. \% H2 N* `
' Workaround: collect and open all components individually
6 ~* X( {! s" w+ o'1 y& _8 [# d5 s  ]
Module NXJournal% M, o2 Y( O! J7 ]' J9 l
    Dim theSession As Session = Session.GetSession()( r4 `' u* V. A: l1 F
    Dim theUFSession As UFSession = UFSession.GetUFSession()
* R# B/ I2 f# E0 X    Dim dispPart As Part = theSession.Parts.Display
; p5 f/ ^8 q9 ^/ ^% @  L$ R
  |  ^5 W" M+ s* }& d    Sub DoIt()8 b, D5 x  n; y) m. F* O& J
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)* f  T! N  s! f# |) j& F- r$ U
        Echo("Number of Components: " & allComps.Length.ToString)
0 G. H$ ], n9 R( \, p        For ii As Integer = 0 To allComps.Length - 10 Y; S$ _  B0 G' l2 d
            Echo(allComps(ii).DisplayName)
, F6 e4 m2 [% @- X' [' B        Next
/ V" k) T$ l, m
! D3 L+ ~! D* e/ r( Z% U        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
1 f$ l3 m4 i5 l* ~5 o        theSession.Parts.LoadOptions.UsePartialLoading = False" }% R& q8 b* i- t- ^& o

4 s8 W7 y; p3 f! U! Z        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
1 m* v! y# ~+ s3 ^# U1 l        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
8 N' U9 a7 t+ M6 b8 G) @# p/ ]/ A' _0 B1 _        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(6 Q- T& o& q  N% h6 v) b" O: Q+ O
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
. {6 K& H5 L9 ~6 z3 S) m2 p; Y& B4 u1 p+ J
        reportPartLoadStatus(partLoadStatus1)
( H* K4 g5 A* K! `9 F1 x        partLoadStatus1.Dispose()
' H$ y* F$ ^3 j  o- i( W% u0 k. ?! j! m4 v; H
        theSession.Parts.LoadOptions.UsePartialLoading = option1+ B- r- E  J2 v3 P7 t# P0 p9 x

7 c! i5 g7 C9 S+ ?5 v6 _    End Sub4 R$ ]5 W: ~4 P; M" X8 r* f

+ r& e& T9 N% @    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()7 R9 r/ x1 A- A8 M4 I% P1 A- j' {( n
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
2 E7 \( ?/ q) G. @5 S- y* u        Dim aChildTag As Tag = Tag.Null
9 N$ r  Y: o" \. L9 e! x: |1 v* k
        Do
/ Q/ N5 L0 S! N2 f6 ^            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
& D* h; C* R" H1 W            If (aChildTag = Tag.Null) Then Exit Do) Z$ v: l7 A" [4 b- }# J- u

3 Q6 J$ W. F: Z/ x            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
$ f% |6 `. X) L, G            theChildren.Add(aChild)6 ?: }" W0 L0 y1 _9 ^
        Loop
1 p/ W1 s/ C: c, ?6 S& N        Return theChildren.ToArray(GetType(Assemblies.Component))
4 T" h5 y; u) n: T! F
1 U0 n. E6 y! s8 y    End Function
$ a; N8 h/ X# h2 S& H9 A
6 F. |3 a0 B7 Z- E. A0 N( V    Public Sub Main(ByVal args As String())5 k) h. w3 W% S2 q. z
        If dispPart IsNot Nothing Then- C; f+ W/ N& m  ?! N/ M- b
            DoIt()$ t) j. M7 d. j2 d
            Return& Y, O* X7 B: b6 [7 U& ?
        End If
3 Z: _: x! H( y4 c! j( K" d3 @5 ^1 b
    End Sub6 H# N6 r+ G- @0 p

# t: h3 N4 E2 l8 P, ~3 a  y% H    Sub Echo(ByVal output As String)  e5 ~% i$ F4 p8 Y
        theSession.ListingWindow.Open()/ R+ v* U/ j& m3 b" d% `
        theSession.ListingWindow.WriteLine(output)
) E6 n) T8 n, _, ?4 R& l. U6 y5 A$ p        theSession.LogFile.WriteLine(output)# S6 _* E9 t; Z8 w
    End Sub- u( u! J7 g: r
  h5 @/ y4 |) ^3 t1 `
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)5 {) ^  z: r1 `4 t1 L
        If load_status.NumberUnloadedParts = 0 Then
+ S& }  V8 g- b- b6 G            Return! _% o) y- v- s" n2 f, _
        End If
0 m5 d% \8 A; O  k6 i5 I0 ^" V$ j' f. [7 r- J5 }5 D
        Echo("  Load notes:"), k: }* r* X+ ]0 F0 o

& b9 z4 `4 u0 c  ?        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
, k  X  c$ o0 c+ H- k4 i7 R            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
$ s8 \8 U$ [. h2 u; n: C( x        Next' D9 Z- R  B, \$ S# X
    End Sub
& ^& S/ n$ h9 `4 `$ U+ |
/ l9 q& Z: K9 N) ~  G    Public Function GetUnloadOption(ByVal arg As String) As Integer/ J- q4 r$ z' P
        Return Session.LibraryUnloadOption.Immediately" m& [# t5 R! `, v
    End Function( X2 Y) C8 V- A  R( U4 d+ |
9 L% [. ^8 b7 R
End Module[/mw_shl_code]" b( w  z& q% Y1 O  V+ r3 A5 i
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部