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

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

[复制链接]

2019-4-12 09:06:31 2480 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
) F% y8 O  u: l1 C8 T% v3 lImports NXOpen
  Z* i0 N: k; Z& I: J2 eImports NXOpen.UF
' L+ @! C1 R2 ^0 n) P' `Imports NXOpen.Utilities
- ^& h0 E4 K* _, m" d! W1 V'/ v  n$ l* r" i8 E
' The OpenComponents() parameter1 s) u! g6 o4 _9 ^# a+ C
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly$ Y( e5 K! e& S6 I9 Z) ~
' only opens unloaded components fully (see also PR-8406345)
" `7 f0 X3 y! R8 X' Workaround: collect and open all components individually
# K5 {. Y3 H  W; |6 Z0 a, t# A'! _! y1 V* _5 P
Module NXJournal( o6 O+ T0 x5 |! ]( J
    Dim theSession As Session = Session.GetSession()3 }) u! ?5 z9 D) p
    Dim theUFSession As UFSession = UFSession.GetUFSession()
9 g3 d$ Y* G# Z$ w    Dim dispPart As Part = theSession.Parts.Display
* U: P+ d* b; t% Z% d# _( A3 E5 E) |. ?8 c
    Sub DoIt()
1 s4 |/ A: ?( d0 r        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
; X. g% L$ S( q" p2 W' {, w+ f6 U+ R        Echo("Number of Components: " & allComps.Length.ToString)
& z  k3 t- d1 P( p- s        For ii As Integer = 0 To allComps.Length - 1! ?& C2 l0 R! q% [# q3 l9 O: p
            Echo(allComps(ii).DisplayName)0 r" U- S3 E$ g- i
        Next
$ P. ^2 A, v7 T/ z8 w
& S  S6 t- g# l9 t' T/ L, r3 L        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading( b5 _7 q4 p* T2 q6 M+ N" J
        theSession.Parts.LoadOptions.UsePartialLoading = False; I# U& o4 R) j9 L

% O$ x: {8 k  w( i6 x( b; H) ]        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
9 Y! K, V* V2 x6 H. j' q$ Y# v        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing0 F% o* [# g" [8 z. ]
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(, j; ?. F# Z. S# |& ^" H2 a
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
9 O2 r3 c: Z8 H* W) X$ d/ g# G" k% n& m9 x; \) p6 `$ @4 j
        reportPartLoadStatus(partLoadStatus1)
- d( z; D9 r' c. R6 w+ s        partLoadStatus1.Dispose()
' I$ G. p1 L( _, {
  `: ^; |0 [# B" C8 B        theSession.Parts.LoadOptions.UsePartialLoading = option1
6 N0 l5 _+ G; H4 r4 o( u9 {. H
  ]4 N5 T& ]; B    End Sub
5 {3 i, y0 G0 B: x9 x, }1 J$ Y& v' }6 l7 r) e: I( {
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(): j7 f* q4 B- z
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList. ~4 f5 j) M& p  `- d
        Dim aChildTag As Tag = Tag.Null/ _- k7 v& j# o: A( k

( ]1 f* K( v, ?6 ^: F, F. c5 N' F/ w        Do4 c9 L1 ^& {: W
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)6 C1 `7 z6 H/ Q6 X* g: o; i
            If (aChildTag = Tag.Null) Then Exit Do" t& T2 D3 x6 O4 b+ q" @* \
/ [# a6 r0 Z2 @( `3 G) ?
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
( d# K6 W6 B: S; ]6 f- w/ i% ~3 Y0 m            theChildren.Add(aChild)8 u2 E4 G( P0 |$ J" h0 C' E' r0 G
        Loop  x! s( W) V2 u2 @  f. |4 w! U
        Return theChildren.ToArray(GetType(Assemblies.Component))
- B/ ?" B3 L9 M5 j4 H5 p: l' o/ U1 C8 U; ?8 r% x
    End Function$ V8 K  H  ]6 m6 ]. h8 j

/ s. @1 A+ ^% F/ |0 S1 N    Public Sub Main(ByVal args As String())
# q) y& Q% h; }; R7 Q; C* H6 D        If dispPart IsNot Nothing Then; r2 N3 y. ~! {
            DoIt()- l! ?% T3 x. P- T
            Return+ v3 A/ {" L4 Y/ U9 ?" I5 N! o
        End If) g, S* ~7 D( X4 n# ~

  g6 l+ X! @/ `$ ?: K2 |    End Sub
! \5 P  V  g& z2 R/ g% ~% H, {! J4 `2 a7 e
    Sub Echo(ByVal output As String)9 }0 ]" t4 |1 {  U0 ~; R
        theSession.ListingWindow.Open()* L, J4 C% R2 _& q! r! d4 b
        theSession.ListingWindow.WriteLine(output)1 J$ G/ P" a9 j0 i. c2 Y: h& ?
        theSession.LogFile.WriteLine(output)2 Q# h7 k! e5 ]; V
    End Sub) H  T( W5 X5 F9 y. ?* Q, v) g. A* t
6 h" a9 ^( L5 l
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
0 x% k1 z) ]% E+ Y# L        If load_status.NumberUnloadedParts = 0 Then0 v* y  ?& x& ]7 y' \/ r; B% P
            Return6 P. M8 _; p' ^6 f
        End If
4 G% f' r& ^/ N- ~9 w! j9 d! i$ |9 H4 u
        Echo("  Load notes:")
* ]4 a! ?0 @0 S3 }% H' F# ?
& }0 z8 _4 W% B7 d9 F        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
! D! Y% f& D! }7 q. }/ s            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
* |" K. b4 ^; G8 z/ h  L        Next
+ U$ }3 o* Y; Y) s' }    End Sub
3 Z) `  a; s2 R6 d; U) W8 i
- i+ ?! e! f4 k# X0 h( x$ V* O5 ~    Public Function GetUnloadOption(ByVal arg As String) As Integer
/ E) K+ [  v3 `. P5 }        Return Session.LibraryUnloadOption.Immediately# U) M( F% k# C1 X# Z, z/ R/ ~+ W
    End Function
* e) c+ X+ A4 p( M" n  ~2 [( g2 v7 O" L* ?7 I
End Module[/mw_shl_code]
! A( P9 E& e3 B$ ~2 z+ }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了