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

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

[复制链接]

2019-4-12 09:06:31 2451 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% ^2 `1 }% {8 S6 s" e4 U$ u" j
Imports NXOpen+ W! w2 j9 _3 K' k! C
Imports NXOpen.UF
# E- x, ~) X# [: A( C5 V- GImports NXOpen.Utilities
8 I* {4 }, \; T3 W9 E4 m  |'
# u3 P2 M5 c' i0 d1 d' B' e' The OpenComponents() parameter
# l, m8 z( e/ x8 S! l' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
* J; m1 d, ?, f& V6 Y; i+ Q' only opens unloaded components fully (see also PR-8406345): Z3 G( z7 a: X$ i. A8 w; z
' Workaround: collect and open all components individually
" ]3 w3 s" l: h0 {- \5 `'
; m+ W1 U8 l* XModule NXJournal
' b1 p/ F- z% ~7 w1 _, w    Dim theSession As Session = Session.GetSession()2 A  X, \& x# Q/ W
    Dim theUFSession As UFSession = UFSession.GetUFSession()* V6 h, j) T" D
    Dim dispPart As Part = theSession.Parts.Display4 K( v0 s) w) S6 Q3 t; _$ X
% A$ s. n! _0 p1 G/ i
    Sub DoIt()
' w9 i/ _/ l* r        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
5 F& E5 j/ f4 Z& z1 w        Echo("Number of Components: " & allComps.Length.ToString), B; l8 k8 s+ R; {, |( b
        For ii As Integer = 0 To allComps.Length - 1, D6 V2 l5 L& H$ J, u# `
            Echo(allComps(ii).DisplayName)
* A( d, `+ t$ Q" W- G        Next
1 F) x" L! z3 K
  Y2 f$ F. G7 g% J        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading6 l3 |: Z+ R( z( P+ G& L
        theSession.Parts.LoadOptions.UsePartialLoading = False9 Y+ c+ I; x% B

2 J! }, u! K/ L* u4 s; ]& ^        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
2 P/ P0 S* w! j, N( W0 {; n! g" b: i        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
- h7 [2 o4 S3 H0 v7 ^. |        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(" H  t2 D. c- g/ T3 A% @! M
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)4 {; @$ X7 k5 |# w1 D( H( g

7 t7 w4 n( d; Y" O- [. c  V        reportPartLoadStatus(partLoadStatus1)
7 o2 o& ~+ d8 ?2 g        partLoadStatus1.Dispose()2 B: W: F2 k0 ~" f) _
$ f$ b8 F$ Z0 @4 H7 Y6 J2 Y  B+ m/ n
        theSession.Parts.LoadOptions.UsePartialLoading = option1
! G. e7 U3 [4 P. V3 V2 {) H
" Y7 X+ n4 r; U  v    End Sub  g8 V1 q+ G; F5 b6 \
5 ?! Z, b* d6 Z
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()0 Q) u" V8 j  a' _8 ]7 ~
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
+ `3 m' }! ~8 K  q& z        Dim aChildTag As Tag = Tag.Null+ [9 z5 R  Z6 Z( U0 V9 ^

. D' T& S; ]6 K1 x; n        Do
) M0 u2 q- |8 n- A            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)  R' T+ X. {* h1 \, N
            If (aChildTag = Tag.Null) Then Exit Do
- i. r0 d/ N8 K5 g; z9 [( v$ B( h9 s2 v0 z( @5 R: V4 v6 v
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)3 O3 w" `7 v, K& K" A. x1 d# U" v
            theChildren.Add(aChild)
" W& f+ a) ~, q        Loop+ c3 v: a; I% v' z$ G
        Return theChildren.ToArray(GetType(Assemblies.Component))  B0 t( Z9 ^0 F1 y: a
( k* x7 t# F/ U
    End Function% F1 w9 x; e& I4 O* [+ l

' u' X/ k! B. D/ I4 \/ m    Public Sub Main(ByVal args As String())
/ g9 I8 ~9 N0 x5 I* B  `: W        If dispPart IsNot Nothing Then
5 E6 G! y, K* b! ^. c' g            DoIt()
' x1 |, r0 j- v# T" ]/ B            Return
1 T6 q- h# W8 q9 u# `        End If
+ z: |; K# M: d; F5 ~/ C2 i; h
    End Sub+ p' \: _2 y6 L, |+ X% A
1 {* A; _+ _5 u2 J( {( L! V
    Sub Echo(ByVal output As String)! _! L6 |3 M5 U. ?; _
        theSession.ListingWindow.Open()# k  I4 L  T5 C
        theSession.ListingWindow.WriteLine(output)& D4 i  Q( `9 n+ X& k" `* t& H
        theSession.LogFile.WriteLine(output)  B+ ]+ E, w8 e+ h8 U# |; ?5 J* ~
    End Sub
3 ?0 x! E, t+ }+ G+ a8 q8 V9 t5 P/ _! V$ y3 G
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
$ u3 O4 U; |( P; F) n& _  V        If load_status.NumberUnloadedParts = 0 Then
1 E. ]( {! W7 k1 V$ U: N0 |            Return
3 J$ r2 k6 Q' H, V* _2 a        End If
) ~8 b! D3 o; F9 ?) Q) E
- V# U0 _9 k% n2 A' E4 a        Echo("  Load notes:")/ y) G  j+ ?. x1 ]6 C0 Y

3 [% Z5 k% E# H- t6 L8 x/ ?        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1$ j/ L) h; E3 s- D# E4 B
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))6 c# i! p+ m- J3 Q
        Next- W' C7 W9 i' ]- M: a! W
    End Sub0 y( M% v& ]9 I. U" x* D
2 M% g& E3 d6 S: L( K
    Public Function GetUnloadOption(ByVal arg As String) As Integer) ?7 N5 q) w  Z
        Return Session.LibraryUnloadOption.Immediately
- k& R  }% S8 @) J! ^    End Function
: g# ]4 o' ~  ]7 q0 L6 E* Y' w- r# ^4 _0 C+ i5 u2 v
End Module[/mw_shl_code]8 J0 @' t/ L: r& 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二次开发专题模块培训报名开始啦

    我知道了