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

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

[复制链接]

2019-4-12 09:06:31 2468 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
8 x8 P( P% e, R5 M4 S3 _2 K  QImports NXOpen
* S' J- I; H  l9 i. y6 H7 HImports NXOpen.UF
' C( |2 y8 u, C) M; d" ?. h! tImports NXOpen.Utilities
8 k; v: h3 F7 f4 x'& m8 X! @: l, n$ t: z6 h
' The OpenComponents() parameter
% N  k# G6 f9 g' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
2 y0 v5 l% f8 g) Q' only opens unloaded components fully (see also PR-8406345)0 C" H4 Y; N) y
' Workaround: collect and open all components individually! E, |& ^* x* I  w" n1 T4 ^
'1 u7 _. p& B/ N7 ^' d/ W
Module NXJournal6 {7 o. m0 D; V% M* N, F
    Dim theSession As Session = Session.GetSession()
7 ~! G9 Y$ n' r1 |& E$ K    Dim theUFSession As UFSession = UFSession.GetUFSession()* `% L  Y. r: F: z# Y& z
    Dim dispPart As Part = theSession.Parts.Display& O5 J8 S0 m8 B. b% Q: E8 G
3 N4 U- `' G% _" Y# X
    Sub DoIt()
, d1 I1 M" v3 H- ?        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
1 m0 D! h& i* [1 _; `8 v8 f        Echo("Number of Components: " & allComps.Length.ToString)
& c- ?" s+ y) ^; b1 f9 x        For ii As Integer = 0 To allComps.Length - 1
  m0 k( q' t6 ]6 \5 W; [8 _            Echo(allComps(ii).DisplayName)
0 B- F$ B% b% ^- q3 G) z        Next
+ h( M* X8 _4 N* \6 U! h6 ?
" v$ }0 v+ Z" N0 [        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
1 y) p/ R- V+ U* g- @        theSession.Parts.LoadOptions.UsePartialLoading = False% F* P" p) r# `; ?/ q

& b% N7 K* U! b  V& r" ^1 J8 h, R        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus3 I0 \  j9 a. _
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing! r$ a. X3 q) F' Y  T/ i
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(% f  h9 T( N' A1 G
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)6 Y- G$ l0 z3 ?1 ^# j5 C

5 A" D: M6 W/ P. F        reportPartLoadStatus(partLoadStatus1)
1 v2 ?, z! F. Z0 ]# h        partLoadStatus1.Dispose()
% D5 q3 `6 U1 ~
7 R+ L4 V* a9 Z: n) r: Z  E! U        theSession.Parts.LoadOptions.UsePartialLoading = option1! A2 z1 G" H/ H# ?+ g- U0 @

! c1 m) ]- K) \; M0 [( ?- ^    End Sub
& v% f% D: o' z. Y. ]; z5 ]# r; T: X& P) H9 l' _/ M; I( U
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(). }8 b2 V$ [, E3 p* c
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
! D6 }) }: N' }7 _8 x: v        Dim aChildTag As Tag = Tag.Null
. i' G) C; `0 A: \: d6 V  n
4 |3 a; @! x$ T        Do
2 M2 e; p% S4 G9 G3 e( N2 `) b            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
% R+ _! I( r4 g/ H: l- U  e            If (aChildTag = Tag.Null) Then Exit Do: R' l" X1 \- w5 n
# R4 J* ?6 a9 C, z( [1 w
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)1 E# N! M( _7 @& [, w
            theChildren.Add(aChild)3 l. z9 N+ Q2 C; }" b
        Loop1 \- @" E+ j$ [# @% x
        Return theChildren.ToArray(GetType(Assemblies.Component))8 ^0 ]# d; |# j6 b: c. e
# T- K  ]# J6 r1 J6 j1 n
    End Function( ?, S- o9 ~" c

6 d- f6 q1 v/ |+ P" j( n. m" Z+ n5 f( l    Public Sub Main(ByVal args As String())* D0 I: Y7 N, Z5 J( {) F
        If dispPart IsNot Nothing Then* x8 h2 T0 b# Z: ?# A/ W5 g! w' U' Y
            DoIt()+ H2 F6 M* Y7 G9 h1 D
            Return8 m& e4 u% u5 K$ q6 h& u. ]( d
        End If
' ]: c" g5 Q& F4 P; t( j
9 c/ m& I: I/ B( G    End Sub
( j3 g' P/ s# k4 y7 B* n: n# \' z' {% P( Y
    Sub Echo(ByVal output As String)
) X5 S" D$ _. y: C/ \( N        theSession.ListingWindow.Open()7 D. V% ^5 L  h$ d$ w& e6 H- x
        theSession.ListingWindow.WriteLine(output)
& l7 [5 ], `( ]# [, P" F* V& w        theSession.LogFile.WriteLine(output)
$ u  |& {% |# V4 Y( W: U    End Sub! ]* o9 M6 w1 x4 F( A

- V  F* i& Z. A9 h6 e( S  L; b- U    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
2 x/ B: O/ R" s        If load_status.NumberUnloadedParts = 0 Then7 X2 K: w2 \$ b% e5 ^& U9 N
            Return
1 T! G! J5 F- v7 A        End If
3 |$ }1 F! I- Z$ a4 A1 I- a# [/ ~. Q2 k, C; ^
        Echo("  Load notes:")1 Q: D2 H2 `& S( _2 V8 a8 Q) c
6 {0 i/ r7 N+ d% z5 W
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
! Y; N" Z$ [6 C9 J2 v            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
& ]# x) z& P& t* L8 K& M        Next- D) c; L% P6 L( {# V! Y" D
    End Sub
2 i- ?1 ~' R" D* N+ c. V
8 U; f. H" ]3 N+ S6 B    Public Function GetUnloadOption(ByVal arg As String) As Integer
8 x6 T! y  S  D, M- a, U8 z        Return Session.LibraryUnloadOption.Immediately
4 N3 Z$ H% U) u% O9 r5 a! z4 k    End Function
1 i" _4 D5 @$ E4 n* ]% Y7 M7 s# C( a+ L5 Z2 c
End Module[/mw_shl_code]+ G9 q7 D- E; ]* @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了