PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

2019-4-12 09:06:31 2424 0

admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System1 j% |9 a8 a8 a+ w# K' k  J0 E; R. ~
Imports NXOpen. T0 j7 s3 y5 u+ F# f* E; _
Imports NXOpen.UF
! Q) r0 O0 S( \% o0 |/ N9 JImports NXOpen.Utilities
' c, M. L. o# d# ~; l'% }3 l& H( {7 e! h0 \
' The OpenComponents() parameter+ W0 E; ^- z/ |( L. e# q
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
+ Z  C2 C; r0 t" Z; `3 @0 y+ H' only opens unloaded components fully (see also PR-8406345), ]1 C7 p! M* H1 a" g( p
' Workaround: collect and open all components individually
5 i" e$ J6 y) l" v* [# ~'0 P, h, M. h' t/ m
Module NXJournal
+ l' [0 H3 B- X- I# M; g0 g2 P/ g. }    Dim theSession As Session = Session.GetSession()
/ T0 @) l+ ]( e0 o. O# B5 P    Dim theUFSession As UFSession = UFSession.GetUFSession(): r1 V" L! a; W; {# e
    Dim dispPart As Part = theSession.Parts.Display  G, K  U# [" g& m# L, s
* |# ]3 z# J* Q1 ^
    Sub DoIt()
! q' Z: z3 ?; z1 W; M        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)  Q1 j2 J, ?1 p
        Echo("Number of Components: " & allComps.Length.ToString): t- |3 z0 R3 ]* s9 n  `
        For ii As Integer = 0 To allComps.Length - 1
+ [9 t9 L" Z. v  J# F! Y) T2 t# I5 |            Echo(allComps(ii).DisplayName)3 m9 g" u, ^% k! c, g
        Next
# K! B5 E$ t6 f  ^1 a& d  a
/ ^/ i9 l8 M* r. Y        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
% O/ W  B' V7 d/ C1 c( u0 E        theSession.Parts.LoadOptions.UsePartialLoading = False
) k- T' u0 J1 A* h) |5 d. ~3 @, U7 N1 _  q& P) w- O
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus+ g- ]; m; N5 X* _. d4 N) J
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
* T. W0 l) Y- w! f- j. a5 l        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(0 I# x/ h2 |( z4 j' a
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
& h3 [- U, q. q% p! L: U0 |2 Q+ ]8 u( P, _" I# i0 Q) ~; e: ~$ B
        reportPartLoadStatus(partLoadStatus1)! i' d  w3 U2 t1 F
        partLoadStatus1.Dispose()4 W! Z  e1 K1 R4 O

$ d7 Q+ Z! ^2 Z# |        theSession.Parts.LoadOptions.UsePartialLoading = option1
2 ~  P) ]5 f# [0 x/ q' N8 ?6 X6 J, d2 r* i+ y$ O0 `, R
    End Sub( q% |0 u9 T0 V

* I5 A7 Q4 ?' s+ [! @    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()6 p) m1 F0 W9 T7 ]& ~
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList6 g1 ~# D6 F, ^. S- H* ~( a# _+ W
        Dim aChildTag As Tag = Tag.Null
4 X3 g: ~  F" f9 j) y. |/ H  g4 K" s/ s# c2 O$ @
        Do- P2 ~, K( B, V7 N
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)- X/ b; x0 ?# c3 v
            If (aChildTag = Tag.Null) Then Exit Do7 Z/ V: L0 _& O# }. r. ^& t

0 Y5 r- d  u9 C' M& H( Q            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
2 S2 ~7 R; y9 R/ q' d0 W            theChildren.Add(aChild)
; K% W1 }* f) N! R3 ~7 l        Loop- n# R% K7 ]+ t4 `7 ^9 y& d8 v/ o
        Return theChildren.ToArray(GetType(Assemblies.Component))  r. O+ r; ^8 V' Q/ o# o1 s6 o

5 q$ b8 f* d  [- ]+ Y3 [    End Function% l1 C+ s5 D) E
! K0 U! T' _5 A
    Public Sub Main(ByVal args As String())$ a) E1 g7 L6 A* W
        If dispPart IsNot Nothing Then
$ m. Z# S1 \9 g" d8 U% d+ f            DoIt()5 d! k, A9 A* z+ o
            Return
9 e" b% h8 `* T3 H+ Z; B        End If6 o6 T( T/ O/ G/ R" G
1 W) {0 S& I* P/ y$ k) F8 d& w
    End Sub* F+ O* o' J. p: z9 u$ o
) A; r% v/ G" M; ]3 n
    Sub Echo(ByVal output As String)+ u, `5 R- ~9 l* d' ~' p7 ?3 j
        theSession.ListingWindow.Open()
( D  u" V3 O, v$ [+ c' H+ Y0 m        theSession.ListingWindow.WriteLine(output)
* J) Y8 A  k0 N' ~" U4 n7 l% I        theSession.LogFile.WriteLine(output)
& J1 d% d8 V3 x) M9 X    End Sub
: f; E0 q( }) d4 G
. s# I6 W* ^% f" a( _0 x    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)9 l8 F; x8 Y. R/ q6 A* a; v1 a& d
        If load_status.NumberUnloadedParts = 0 Then
3 \! A1 N4 C" u7 j$ G2 Q$ y# z7 c  g            Return, x5 r8 h; d" w" j8 e1 X
        End If* j! ^1 C' a0 b9 P' }% ^

1 a: I' r) ^3 w: R        Echo("  Load notes:"); g  [7 m5 h* [" f0 M8 }% A  ?" a
5 A5 i! j8 [/ d5 w6 I
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 18 @3 x; c: V( k; R5 v: x9 k  q6 ?9 Q4 o
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))7 f/ t+ X& P) Z8 c
        Next7 H$ n! ]' [! H
    End Sub
" ^5 L/ A7 ]) T9 W6 b; n9 C" V' t
8 e! B( x/ H2 o    Public Function GetUnloadOption(ByVal arg As String) As Integer
; t) k2 _. l! O  L        Return Session.LibraryUnloadOption.Immediately0 _" Y1 ?- B& x' h$ Q9 _; I9 U
    End Function
/ `+ m- z" r9 M0 {3 Z8 ]  W
, V$ G6 \6 E" V0 m5 A+ ~& A# p8 A) ^End Module[/mw_shl_code], X7 @4 ~& [+ y/ F# s# t2 Z3 l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了