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

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

[复制链接]

2019-4-12 09:06:31 2313 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
/ g7 t( Q, R( c2 f4 S/ zImports NXOpen
+ g0 }9 x. `' h6 y2 AImports NXOpen.UF/ k" a5 p7 n+ A% X3 Y) o5 [- O
Imports NXOpen.Utilities9 s) g4 r% T5 y9 z8 Z$ ~% B
'
9 P* N' T8 o0 q+ O+ R* j9 l' The OpenComponents() parameter
5 c* s8 J& g4 M6 I, s, j' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
9 s- E. L( S5 v9 \$ R5 X3 z1 \' only opens unloaded components fully (see also PR-8406345)+ o4 m+ ~( D$ \- I& Z
' Workaround: collect and open all components individually+ N7 N2 v5 ^7 G4 ?0 i
'
1 t/ J# B" m3 [' W. ]; |: VModule NXJournal# l8 @. G2 k' R8 N
    Dim theSession As Session = Session.GetSession()
1 c9 d) A) \* T    Dim theUFSession As UFSession = UFSession.GetUFSession()
0 x8 u8 L# A% _* B5 T    Dim dispPart As Part = theSession.Parts.Display) A# W. R! N) l5 A7 E0 b

% c) e2 ?( z; z0 T    Sub DoIt()$ C  ]: ~% _. X- k
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
9 O" f: H6 r9 R2 W7 Z        Echo("Number of Components: " & allComps.Length.ToString)
: {, s1 u0 n  y, X6 a2 p        For ii As Integer = 0 To allComps.Length - 1! j' z# E. v7 V# R$ B% Y8 ~
            Echo(allComps(ii).DisplayName)4 z+ r9 x0 i! l
        Next3 M9 Z1 u  s0 g- P

, Y) e9 Y5 K! r- N" a0 p: o1 x6 j        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading* i" _; Z& m7 i
        theSession.Parts.LoadOptions.UsePartialLoading = False
; R+ j! x0 r+ w3 V, ^! V; H3 _# x7 `# H
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus' U% m8 ~1 \2 \. k6 ~
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing9 c0 Q  V# }7 B* \, `  v' k; s' i
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(+ s, X; K2 Q0 L0 ]
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)8 T* E2 r7 O1 P' d1 Z

0 J& V7 d% I) O, r$ F        reportPartLoadStatus(partLoadStatus1)- k4 ]: z* V8 Z) i5 I. X
        partLoadStatus1.Dispose()
' c4 L1 v% q: \
4 c6 y9 e$ a1 Y4 G0 n$ o! W        theSession.Parts.LoadOptions.UsePartialLoading = option1% V$ Z$ y2 o5 P0 _5 K& b* t
& n, c- ?: I3 [" N
    End Sub
8 p; P$ s# h8 w9 |2 ?8 k8 e8 R  g2 L/ _& p$ ~5 {( V5 t- A% v( I2 A
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()4 ?3 `- R1 B: ]  z, v' g2 S& V8 `
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
1 J0 S5 g5 ?' V7 u3 U+ @  f, f        Dim aChildTag As Tag = Tag.Null
% i3 v/ y1 v. D7 c3 l  F
9 `! `7 m  C+ w- B  K! J  j        Do
# Q" _* q. H3 P1 @; t! Z            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
' f. D6 K% t3 h; R# s            If (aChildTag = Tag.Null) Then Exit Do
1 b: r& i2 \! i2 h
8 ^$ [* L% ~0 e            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
2 T  Q7 e: [& i5 K            theChildren.Add(aChild)" j) t9 C  H' B- V8 v; n6 `
        Loop/ T& i4 {" u" S4 M: @9 A1 T$ ~. ^- B
        Return theChildren.ToArray(GetType(Assemblies.Component))
7 S" z; Y( b( S! e2 X3 z4 d6 I$ x# M9 d3 |0 Y0 d
    End Function9 [1 W4 o  O9 d5 D6 y! z

& c- w5 \4 h4 A" ~5 q    Public Sub Main(ByVal args As String())4 K% t2 \  P& H! r) [/ i) U
        If dispPart IsNot Nothing Then
( x. [8 ^- B& q2 e            DoIt()% n, R7 J3 x8 w1 F. Y
            Return
& v6 |3 L/ _& P3 v% B! |- O        End If
# m: C, b6 r! C8 \# ~" v0 c6 G
# ^2 f9 b( t+ @" Q; g& U7 Q( z    End Sub* A& A3 ]$ ]2 W( \+ M: R
3 S) _( O. @! n, Z2 J4 @
    Sub Echo(ByVal output As String)
! j! b+ O# m( f0 `( v        theSession.ListingWindow.Open()* y. O" }; b) J. T- M! m- c2 o
        theSession.ListingWindow.WriteLine(output)% v' O1 I/ v0 t1 P5 Q' k( J4 b$ }
        theSession.LogFile.WriteLine(output)( u9 x2 g! G4 I7 H) J' ?7 x6 i- c
    End Sub  q. ]4 y6 }! @/ N0 Y

4 Y6 A# s* b2 w7 C    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus): |( o2 e- b" e4 }6 R' L  }" v& {
        If load_status.NumberUnloadedParts = 0 Then; f- h6 _$ T' {" a) _' H
            Return
9 A, p. g; z( a1 U! d2 ~; g        End If
. T8 p9 ^6 ~0 t1 \' i: ]
8 Z! V6 }$ x; Y9 v% N5 b        Echo("  Load notes:")0 b; U5 a& e  k8 R7 X- W0 T! g

/ w6 m' P& t& [        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
$ e9 X/ e4 `! g$ z            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
) a& i2 f* G9 D6 _! {        Next% F/ ]# E9 z6 U
    End Sub+ ?1 G# o/ v8 m8 O' H
" b3 \. N" w$ G; W% x
    Public Function GetUnloadOption(ByVal arg As String) As Integer
: g  ?5 O  [, ]: g  L7 x) t4 N$ D        Return Session.LibraryUnloadOption.Immediately; u9 k2 z2 t) R& I2 J; p
    End Function
! i' U) U2 M- j; Q# M
5 G( O$ t* G" Y6 m. nEnd Module[/mw_shl_code]* U  a7 X# {$ g5 A' m9 q; 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二次开发专题模块培训报名开始啦

    我知道了