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

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

[复制链接]

2019-4-12 09:06:31 2447 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# K; V, p* ^' _9 ~9 r5 |
Imports NXOpen
( b& Z5 y4 G) T  sImports NXOpen.UF
* L4 ~; k" a' F4 z" a, dImports NXOpen.Utilities
. g% u2 e! W5 x+ ]+ {'
- u5 X8 i( O7 ~9 c, f& e3 T' The OpenComponents() parameter* s3 [4 y9 j7 l4 s: n$ t- w( N
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly: t% l8 }+ s7 g5 x4 X% x
' only opens unloaded components fully (see also PR-8406345)' c5 O! z+ C. J
' Workaround: collect and open all components individually
4 t% `3 p( i# ~* {+ i'
4 ^$ ~0 D% Y- O; PModule NXJournal
( S& H1 y! b, A5 ?. l    Dim theSession As Session = Session.GetSession()7 L) b' i. ]" }2 P3 @
    Dim theUFSession As UFSession = UFSession.GetUFSession()
4 A4 C# W4 f% r/ I1 {    Dim dispPart As Part = theSession.Parts.Display
- y& r' k( c* m8 y7 O5 M; L! n9 h, C
    Sub DoIt()' e' x+ a6 @1 `
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)8 O) s: H' I' v7 s: |1 L( I/ }; A
        Echo("Number of Components: " & allComps.Length.ToString)8 y& a: r1 F, L% t3 j1 \$ p  i
        For ii As Integer = 0 To allComps.Length - 13 x/ }6 e' p. M- I2 S# w4 ^+ J, O& q4 l
            Echo(allComps(ii).DisplayName)# \$ |- ^# T8 R; I% z/ @/ z& A
        Next
! ]: H; ^, b. t/ Z+ }+ T1 O8 D$ T
7 I7 _2 _+ O: J( A3 r        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
1 T6 _) d8 }6 i6 ~9 i4 `8 l! L        theSession.Parts.LoadOptions.UsePartialLoading = False
5 W/ U7 ^" Y: r( w  A$ }
' i2 N0 l5 H# g7 X' g4 [! r8 t: ]        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
1 {# s9 V5 g1 ?  l4 i/ y6 t! p        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing3 r( l. l  n' I3 y' U! X7 s
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
3 A5 s; w' F  t$ L2 S' X            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)& f! E" `4 e# F3 k" I8 w$ t. j
) z9 |  q6 l% b5 w' O6 _* M; `
        reportPartLoadStatus(partLoadStatus1)$ g' A0 A1 |. o! z7 H
        partLoadStatus1.Dispose()
5 ?5 ?* m1 V( p* D8 S& N, N9 m1 W9 O  n/ k6 t
        theSession.Parts.LoadOptions.UsePartialLoading = option1
4 u1 ]2 _3 X& d0 G* t% i4 T2 x$ n2 B. ^
    End Sub
" F4 H7 X% {/ a0 f8 v+ l
" \9 r& @6 A/ t, Y9 E) `* y    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()/ x4 C" z: j! G1 i# R3 ~3 }; j& U/ i
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
  U0 h8 T& v+ c' b( m        Dim aChildTag As Tag = Tag.Null
* v6 O" w% |- {! R; V6 E1 D! z, @2 w
        Do
/ B. f' d* L9 T" |: {& W/ O, C4 Y            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)( Z. B6 [1 c2 a5 Q7 h0 k9 |
            If (aChildTag = Tag.Null) Then Exit Do
9 y6 C& A( d, @( }8 k6 Z' R" R" T# c  o+ v
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)! U; t! r8 V5 _
            theChildren.Add(aChild)+ F( x6 F* Q' Q3 g* M0 {
        Loop. A2 _+ i0 H' `# k1 ~+ h) w
        Return theChildren.ToArray(GetType(Assemblies.Component))
: [. ^5 ]: W. F2 L. v% L' ^) O, K
    End Function
( c% D  {% Q$ @+ p1 v1 \7 Z6 S% b+ o/ a, C8 j
    Public Sub Main(ByVal args As String())
# a' s/ r, W0 D# j        If dispPart IsNot Nothing Then5 S" r3 u0 H7 v0 d  E2 ]7 e
            DoIt()) @+ E  T5 ~/ Q  X- b4 F
            Return
+ j9 U& ^3 |( n- ?4 j; c        End If- _$ @! t% z9 g& L, l

# m5 P+ x, n0 }' j7 r, \+ c; `    End Sub. d" L1 I1 `% i6 i1 b# b

- ?; P  O3 j5 ~- J. e# M    Sub Echo(ByVal output As String)
9 a* Z+ W: ^. Y        theSession.ListingWindow.Open(): Y! s9 a8 c! h) g
        theSession.ListingWindow.WriteLine(output)" K2 ]2 S1 E5 x8 t; I; O, l, I: X
        theSession.LogFile.WriteLine(output)
/ V7 U+ k+ K' p3 A    End Sub
2 n" _) |2 x% B; b( S1 [; ?5 _5 c3 O/ q9 c7 }% v
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
2 D" g/ U: g1 _; d- l        If load_status.NumberUnloadedParts = 0 Then
0 O2 w3 y  B0 d& b4 J            Return
5 N7 }% b+ a- s5 @. |. ^$ G/ ^        End If8 c% b! K9 r/ ]1 L" [
* }# M+ g# y+ J5 l; t
        Echo("  Load notes:"), ?4 R$ a9 S; x! ]
/ F9 p. r. a  y* s! v2 o8 Q
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
8 E5 X9 N2 Y6 v5 z8 F4 W            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))( u( K8 j/ v, i4 `
        Next# u) k3 U9 U" I+ ]/ p
    End Sub
$ M- |- n$ Q3 ~. g4 ~. N+ `% p4 F7 X9 D8 g; ?5 S
    Public Function GetUnloadOption(ByVal arg As String) As Integer: j/ V! H# X; l% L9 c4 T: P' F5 [0 \  Z
        Return Session.LibraryUnloadOption.Immediately0 E4 U! p- Y+ _
    End Function
2 w* {, K' w: V+ T  I6 O5 A6 f3 y! [
! z6 f' _* C6 W9 l" jEnd Module[/mw_shl_code]" m& d" C$ f& g2 u1 K+ |! w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了