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

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

[复制链接]

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

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

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System
) j3 i9 U: r! ?+ DImports NXOpen1 \0 \8 i8 F. y$ `" w
Imports NXOpen.UF
: E7 Z$ r! a9 eImports NXOpen.Utilities( t3 x1 Y: E7 m$ u1 x9 Y" `' A
'5 O, W& d) [2 ?# n0 l, D
' The OpenComponents() parameter2 J7 P7 q) n/ q! p
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly1 G; n. T& p* j9 p1 ?) B1 _& c
' only opens unloaded components fully (see also PR-8406345)
& O" ?, ]# o: \+ Q$ W( R3 Q  ?' Workaround: collect and open all components individually; x  b* E# Y6 f( Y
'
8 Y! q+ C+ N2 h0 P: cModule NXJournal+ h2 H/ d3 {: ^. |! z1 w
    Dim theSession As Session = Session.GetSession()% V# a) R& e- B4 y
    Dim theUFSession As UFSession = UFSession.GetUFSession()
! e9 Y& S" K2 b8 K. e    Dim dispPart As Part = theSession.Parts.Display
) Z0 @/ Q* K) x7 Y' f( F' m  w; i1 A) g& |6 t! k
    Sub DoIt()5 ?' e1 Y+ r2 p" [
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)% g* j9 |- r6 R
        Echo("Number of Components: " & allComps.Length.ToString)4 x9 d+ g7 ?3 L  v
        For ii As Integer = 0 To allComps.Length - 1: P; a: T0 k& l, H1 ]- w
            Echo(allComps(ii).DisplayName)4 V0 k. ?% A$ n$ ~. h
        Next+ Z1 r( g  v# T+ U, |# _

/ H( v' z" Y. o* N        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading9 B) Y4 `' x2 I; c
        theSession.Parts.LoadOptions.UsePartialLoading = False7 E% w/ [) }3 r7 I' U. r. V

3 |$ ]$ L" H5 H7 v  ^9 Y6 f        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
+ b: X# J2 M. ?        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing! T2 \# p3 z" Y- l2 P" d1 A% I
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(( |5 V+ I1 R1 S7 g6 I" A
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
) Z4 O/ Q$ Y, `* \6 \4 a
' P( Z. g5 K* Z        reportPartLoadStatus(partLoadStatus1)) G% n. h4 Y0 c* ~7 q
        partLoadStatus1.Dispose()
) l+ f  ?- U2 c5 N8 K- d$ t4 ]3 z  E3 S+ g8 p4 Z) H( @
        theSession.Parts.LoadOptions.UsePartialLoading = option1
# u3 U9 w& o# e0 _; Y2 X7 w, G- m1 a. o7 m$ R1 C. U9 Y4 P
    End Sub, H8 D, q6 _+ W: S

; T/ r$ o) `3 e$ J    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
% @: Q& U! J; Y' I3 Z        Dim theChildren As Collections.ArrayList = New Collections.ArrayList/ k; ~5 M8 Q0 Z# t" r
        Dim aChildTag As Tag = Tag.Null
  e/ R5 [/ E3 {% k& j/ d' g
/ a( _: B+ E. Z/ s  B6 F5 B        Do4 m$ `5 L' [; `9 S8 X) k/ v$ O7 l5 a
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)/ t1 O- f6 |1 ?$ E& ]. s
            If (aChildTag = Tag.Null) Then Exit Do8 ~5 [  _1 `: q
: R6 m/ Y8 v7 ^- L( w5 \
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)1 ]9 i2 b, E# _" a: J6 G" Z
            theChildren.Add(aChild)
* _6 e( H# s& q5 F3 s  L9 X        Loop0 I! t" U$ V% }" [0 l) }
        Return theChildren.ToArray(GetType(Assemblies.Component))
% m5 l) ?. \) \3 A5 t3 d$ ^7 k
) o2 ]! Y7 Z/ W$ n    End Function' h/ l2 \: j. L: z( P* z! I8 y

, M) U3 O! m9 E* @9 ]    Public Sub Main(ByVal args As String())1 G+ }1 i, w1 t) W5 T
        If dispPart IsNot Nothing Then
, d% g) @2 y; c3 q8 Q+ r            DoIt()9 j) n2 s& l- ^" _) C1 j
            Return
" r0 @; r8 z+ l        End If
. f7 @6 z/ k% I, U, f- i6 a3 p( m1 A7 \3 k
    End Sub
! B: _# |5 _8 m. b( t1 T( F0 r1 T! X# P6 f# l. w
    Sub Echo(ByVal output As String)% y: }& I" k9 H( X
        theSession.ListingWindow.Open()
$ [! o; z/ s; g) Y2 ]        theSession.ListingWindow.WriteLine(output)
6 \; P8 u0 w/ D  S        theSession.LogFile.WriteLine(output)
) M& V1 E  M: T% O* j6 A- z& ^    End Sub
- d( }' s5 |- [, R, Q
5 Y. {7 e/ `: \    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
* `; w. h+ |: V) i        If load_status.NumberUnloadedParts = 0 Then
$ U( c5 B2 Q( l/ I: s' \            Return
3 \1 ~0 X$ F: F. W1 ]) i        End If& X) `9 D0 x2 E9 W

" r1 b9 y1 X; @4 G        Echo("  Load notes:")8 K0 k' L" d# T- Z; j
9 t2 C9 e3 Y9 D% [9 J& X
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1$ G+ X6 P. K2 _3 i9 Y3 z
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
8 h: F9 R8 f" O        Next7 J2 t6 b' T# Z3 ]0 r
    End Sub
  y1 d7 o) x$ m' N5 t, k) r$ y4 Q, E+ P: J
    Public Function GetUnloadOption(ByVal arg As String) As Integer
( \5 Z% X' A  g7 j. r' T        Return Session.LibraryUnloadOption.Immediately. x3 |3 u. a5 m7 o
    End Function
% L: W1 i( g$ y# F# J- t7 U+ Q8 X: w$ B8 L" `5 R) w
End Module[/mw_shl_code]
' E0 R! _8 F" b; U% O# d
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了