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

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

[复制链接]

2019-4-12 09:06:31 2462 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( h8 D, G: ?! `( r7 {+ N
Imports NXOpen+ r  t8 q6 m4 _) e7 N
Imports NXOpen.UF+ {# h+ e% j5 c+ f9 t; ^$ ?
Imports NXOpen.Utilities9 J- z' `2 m: P( I1 c1 T; U
'9 U5 z$ h* s5 O3 ^# K3 T% s6 K
' The OpenComponents() parameter
( a3 N3 k, @- S* @2 u, ~' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly4 i) o$ V9 C3 |/ N  ]3 ~
' only opens unloaded components fully (see also PR-8406345)
1 Q7 g( \' F+ M4 I* }3 X' Workaround: collect and open all components individually/ i9 _3 N+ }8 H; m3 E* _
'% P7 U  F8 J, |0 A: u/ p, X
Module NXJournal
( J# }* z, R  E# f. h  c) H9 V( d    Dim theSession As Session = Session.GetSession()
/ f" V* N1 T  C9 ~& [    Dim theUFSession As UFSession = UFSession.GetUFSession()7 N) `3 B# I0 B0 L" ^) o
    Dim dispPart As Part = theSession.Parts.Display
( l/ S. E! k% i' k, ]( a" c3 ?2 B  d2 n2 j/ @4 {( ]3 q
    Sub DoIt()5 n" x1 h$ W9 g3 Y9 ?! c
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
3 ?. {1 Y4 J9 t  {6 e        Echo("Number of Components: " & allComps.Length.ToString)5 Y: Y: t& m" N4 ]' Y
        For ii As Integer = 0 To allComps.Length - 15 U" m/ B  e: [
            Echo(allComps(ii).DisplayName)
7 b0 W- _' j- Y! [, `4 f: S- a        Next
' s, }+ f0 g5 x, Y- h( `/ J1 G9 _- ]7 m' t- i& \7 c
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
* a3 p' \- a$ N8 m( Z) S7 Y& w        theSession.Parts.LoadOptions.UsePartialLoading = False
: R* R" O& Q& K, e9 L+ |$ b, Q+ |# ?# I( o+ {0 ?' Z
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
* J; f4 ?+ G( A0 _9 L) n        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
& I! P. n- `' B; z' H1 e        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
2 @! u( o9 ^9 t+ Z# }; t2 c2 D+ l  V            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
; \+ q/ D- F. U( d7 \
5 P3 {( s9 q/ W* i" \        reportPartLoadStatus(partLoadStatus1)$ ]1 W* {# W$ F
        partLoadStatus1.Dispose()% O; ]; w% Y" [  X) g& ~( b: K

8 L/ q6 W% t: P0 p: t2 m" ]        theSession.Parts.LoadOptions.UsePartialLoading = option10 Y6 P( l/ k+ y# w* _

( @1 L0 x0 Y- ]7 n6 U  H- X7 Q    End Sub
1 O4 z  D% Y6 G0 E, z4 d6 M/ @/ M+ k3 [+ }4 k1 o
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
% @  A& C. R: n7 K7 p        Dim theChildren As Collections.ArrayList = New Collections.ArrayList: R/ G- z" w# s2 i/ _
        Dim aChildTag As Tag = Tag.Null# d! D# Z; Z2 G8 z

* \$ s2 E( T5 H8 I% ]! b- G7 M        Do
) ~, Q3 W& I: [4 j- I. f            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)( z7 N5 j$ e0 e; p5 L. Q% O
            If (aChildTag = Tag.Null) Then Exit Do# J, K/ m0 _6 C( P5 |$ h
+ C' d) n" N1 L3 i% j! t5 d4 z
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
: W/ d) p: L: j2 a% k6 M            theChildren.Add(aChild)  x+ k5 f( E0 S8 I, l1 q6 L
        Loop
1 ]8 S( j" s. q1 ~) F! R        Return theChildren.ToArray(GetType(Assemblies.Component))) P3 [0 y! N! `# V, [7 _5 o; ^+ b) x7 @

" E5 n' d- W" y: b& a    End Function) @% C, ?! B) C- k' C% `7 `) B' `9 E3 g
( P. V) W+ Q8 y# s
    Public Sub Main(ByVal args As String())
# _' }5 M6 c: `8 D; [        If dispPart IsNot Nothing Then& p1 Q/ k! ?  q  y/ q  X
            DoIt()
4 a6 ~- @" e- T% n% S- B            Return
9 _- h& H0 g! y1 Y2 w% q        End If
4 J# x: \. d% f/ D) C2 n
% m' l! w% b0 z1 ?. ]& H    End Sub
2 U; Y9 S. L7 n  ]* U
4 [6 ~1 d* g) r; J    Sub Echo(ByVal output As String)
5 X$ `$ y0 `8 l; C* Y3 t: N        theSession.ListingWindow.Open()
2 y; N: C# {8 ^5 T& z% y" P8 u        theSession.ListingWindow.WriteLine(output). _: f$ G$ I8 B% p& _3 J5 z
        theSession.LogFile.WriteLine(output)
* u. P& M8 Q) r5 B7 n3 d    End Sub
3 d# e( @; \9 H) w5 p) F# w( ?7 \+ u6 S: p
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
( P* N6 C9 c3 O8 x% l0 a! y$ x        If load_status.NumberUnloadedParts = 0 Then
9 D+ _1 u$ B, P2 Z- |, w5 D  n& Y            Return9 h* L6 X1 T( n7 F2 T0 v9 `( s
        End If
; S6 T; ?; t% T/ S5 F9 {5 f2 a9 Y( x, y+ I  L2 y2 a
        Echo("  Load notes:")
; H6 m+ [0 v2 l) @, V; S! i7 y+ K$ Y/ W$ L; d/ z7 v" I: T; X
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
7 q2 s! _/ T- y5 w: T            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))9 {% h9 a1 g) w9 Y
        Next
: J% s  d2 n' k& A: I6 {    End Sub! [# D) V% m/ b8 A# b- J/ C
* w+ s% t0 r' v; F& _
    Public Function GetUnloadOption(ByVal arg As String) As Integer
7 v, q# `& a3 r' e        Return Session.LibraryUnloadOption.Immediately6 L2 c( X2 V2 N: i0 j8 B% v
    End Function7 L8 b7 [$ O: @6 ~1 V
- ~$ K6 t# y+ @6 |
End Module[/mw_shl_code]4 Z8 V$ I. F- H8 ]
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了