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

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

[复制链接]

2019-4-12 09:06:31 2487 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
; L: f+ [# u0 s$ M& {! z) T' lImports NXOpen
: V: Z# G; M* k% h* oImports NXOpen.UF
$ g1 ]+ t, E$ C) K9 q- c) e; ?4 LImports NXOpen.Utilities
: D; G1 q7 Z. K  l+ s( `$ i'8 `+ I# a0 w. c. A3 N2 f
' The OpenComponents() parameter/ D: @# H# U( e4 r& ^
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
2 p9 V% N2 H9 W9 G' T! ?& u0 ^- m' only opens unloaded components fully (see also PR-8406345)
& Z% \' o) r# K: _" o' Workaround: collect and open all components individually
! |4 z3 j: d! e- t( v8 n9 c') N, L! l! C2 N* ]
Module NXJournal) b, q" H, |# }* t; U  @
    Dim theSession As Session = Session.GetSession()0 o- N( V1 K4 I& x- v  V
    Dim theUFSession As UFSession = UFSession.GetUFSession(). }% `5 o. e$ z8 i9 t8 K: l3 s
    Dim dispPart As Part = theSession.Parts.Display9 O' O7 d. t3 ~5 E4 ^# }; M
9 a: u" B9 F* q3 i0 R6 l
    Sub DoIt()
( P9 ]. m$ m/ E9 J8 `+ l, U        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)3 a1 h" s7 K3 |/ R: N
        Echo("Number of Components: " & allComps.Length.ToString)& \. l/ c: }( ~: Z) {
        For ii As Integer = 0 To allComps.Length - 1- V+ P7 w9 d5 b% T& y( }7 Z
            Echo(allComps(ii).DisplayName)( n+ O7 L! {4 ]8 B, w
        Next7 f, a2 N" M/ o+ ^1 j+ _2 V0 ?

/ q1 v, b) @5 x" u% u        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading: W; a) N4 O5 U- E) [' }
        theSession.Parts.LoadOptions.UsePartialLoading = False% {1 ]. A& O+ j$ C
, y/ @0 l- y4 ^6 W
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
! P8 f; {! ^  E        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing" z, g' B& s4 w) i6 N3 @
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
& |7 ~9 g1 u; m# z; g( y7 ]/ D$ f0 e            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)* C* T7 l; @; ^0 _( p  f; Z
) ]" f8 P9 W+ v0 W) j$ e
        reportPartLoadStatus(partLoadStatus1)0 A" q0 c& @* |& U& D
        partLoadStatus1.Dispose()
& Y5 s  F! ^: g3 I# a
5 u3 p, u- @$ ~' F/ p$ k        theSession.Parts.LoadOptions.UsePartialLoading = option1
( x5 \6 @* ^# `5 w7 A1 j' z7 n  d7 k
    End Sub
5 A( D: D7 W+ w+ ]; T
: i8 Y1 O( d, n+ u) e    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
) l# z% }5 J+ Q0 {' W        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
) k: N% k3 N7 ^% q% K! Q+ s4 [6 i" k        Dim aChildTag As Tag = Tag.Null2 {" H, Z* l# {: }

3 N- b1 F4 a8 k- H( Q5 N        Do
/ j0 ^$ C( U% ]            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
7 H9 A/ O5 F0 E* j; y4 v$ }            If (aChildTag = Tag.Null) Then Exit Do! ~* j( P$ u# \# Z) D

( c4 v! H5 l. G9 p! l' E            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
7 G0 f8 B) J" ?6 }7 j+ {* k# [: V            theChildren.Add(aChild)/ o$ W: ^2 _8 e& `8 r
        Loop
$ K6 r. M3 `+ O' n3 r: ~, D1 F0 ~2 t        Return theChildren.ToArray(GetType(Assemblies.Component))6 e2 I# t! U: s
6 k, w2 |: N, s2 M! L
    End Function3 V1 Y  I' I0 ?
, b" Z8 D/ R+ b- x" K! H
    Public Sub Main(ByVal args As String())' ^* Y( u  u& l( i5 H6 P' S' X& \6 e
        If dispPart IsNot Nothing Then6 x9 _, Q0 @, u
            DoIt()
" `9 l8 n7 g5 G! l# D. Z+ V4 {0 _( E& X            Return
4 h+ _. Z+ I1 D* o' a        End If7 D. y/ b$ W2 P* D: b2 m

+ A# w  f) c$ {% Z" Q    End Sub+ \5 w" C0 K: P7 f1 a( _3 M
/ G5 T% o7 k" H8 @; c, i3 V& Q
    Sub Echo(ByVal output As String)
% G! a  e3 O5 p0 s8 x4 S6 J! B- H        theSession.ListingWindow.Open()
& j& S" p1 Q/ K* d        theSession.ListingWindow.WriteLine(output)" @3 b- \  k9 v
        theSession.LogFile.WriteLine(output)
$ U" I  o8 F2 |' C- e0 k! ~  }    End Sub- ~, o% o& q! Z9 G0 s: C
; }9 [% V* D" z$ l
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
3 ?& Q+ p1 X% q1 V( D        If load_status.NumberUnloadedParts = 0 Then9 _+ p: [( S; a5 ]
            Return# D& v1 d8 A- b+ H/ s6 @1 \
        End If, P% c2 b# D. d2 s$ C
% Q2 c0 ~8 n% k* O
        Echo("  Load notes:")# ~4 b& v2 M/ Q

, g: I  @7 H+ ~9 I, a5 [% @        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
" H% F4 J& q% D8 N# [            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
* k0 Z0 K0 N9 }  l- m" m. Z        Next
, u& g/ f7 V5 g- Z: B" [  y    End Sub2 {7 R* z! q8 M4 q6 L

, D) I7 T4 n7 g( b) u, b    Public Function GetUnloadOption(ByVal arg As String) As Integer
8 Z* }$ ]7 [' ^, }# ?. t        Return Session.LibraryUnloadOption.Immediately: ?2 ^( e6 p/ b$ o& z! p
    End Function% ^" q9 `6 Z$ O( T- k( t( C7 s4 B
+ Q  c4 T' b5 s
End Module[/mw_shl_code]
9 A+ H. Q+ h, B; u# i9 x9 K, c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了