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

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

[复制链接]

2019-4-12 09:06:31 2435 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
+ u2 ]: V' M. E$ Z7 l! u0 i/ w5 O* uImports NXOpen/ t: o9 _4 H7 `8 I( N
Imports NXOpen.UF
7 X" i% L% g0 L, ^) b4 ?Imports NXOpen.Utilities
1 E# u, A# y( \  w'% |5 c) }  Z# I& |
' The OpenComponents() parameter8 W5 H( j* K0 U0 Q
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly% o( W5 i% t1 z* [$ S
' only opens unloaded components fully (see also PR-8406345)2 H! T  C  s2 \& k' f) p( a
' Workaround: collect and open all components individually
* }$ o: p8 v, o* Y. ]'
8 [7 b7 Z; [" _8 k+ kModule NXJournal
+ ]' X; L$ _) S. X    Dim theSession As Session = Session.GetSession(), j' r" B( U& O9 p" H- F
    Dim theUFSession As UFSession = UFSession.GetUFSession()/ ?+ [. P" L* F3 R
    Dim dispPart As Part = theSession.Parts.Display
1 v8 m: Y% A, R5 P
0 j5 ^( G8 D7 V5 M7 s7 g6 }3 J% q5 d    Sub DoIt()
) o( B5 ?8 W) ~9 J3 v        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)( i  W+ `! _8 b' `5 G! z
        Echo("Number of Components: " & allComps.Length.ToString)0 _9 ?7 S" {8 t! R4 F" G$ P/ [; ?
        For ii As Integer = 0 To allComps.Length - 1) O8 n+ H% v5 L: K+ x
            Echo(allComps(ii).DisplayName)3 R/ l5 G: [/ N% Z* y6 C4 D
        Next: [9 ]2 J* D4 k% ^

  p( x/ P) E  R8 j( [        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
% Q  d$ _( s+ l3 a6 \        theSession.Parts.LoadOptions.UsePartialLoading = False
" e. \' N/ X6 E3 j6 U: I: Z2 u- l3 ^: i* C2 ^
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
2 U/ h6 k8 X2 u( u) f        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing" i0 ~# S, {& k! [9 Y
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(9 a' x& f3 e% L. N& {" Y
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
4 h! n8 k; V' Q, h
- G( s3 w" g! S3 b" L        reportPartLoadStatus(partLoadStatus1)
: o: ?+ ?5 N0 \, j  G& F, u; N        partLoadStatus1.Dispose()
9 f2 C, G+ b5 |! {+ H. r3 B7 J5 J3 u0 ^4 h5 t% v  n; v
        theSession.Parts.LoadOptions.UsePartialLoading = option1# d3 [9 A" @: v6 Y
" C, I$ T' ]" R' f# G
    End Sub
7 [$ E( b, ~" `
3 y. ^7 u+ p& D+ [+ @  Q    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
# n4 c; P# C( @7 }        Dim theChildren As Collections.ArrayList = New Collections.ArrayList* |/ Q1 l) B" }" g! [" l+ D2 F
        Dim aChildTag As Tag = Tag.Null9 y3 [* k: Y& M

) y# ]/ X. Y# O9 n        Do8 t5 ?+ @9 V" @8 C( S& U: a
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
5 E: V' S3 r, ^, P" v+ l: J( Y3 m            If (aChildTag = Tag.Null) Then Exit Do
4 W4 l0 P1 c" ^2 F. x8 b
; v; w: {6 |+ l3 {* w            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
4 C) ^& b4 S6 h: I( Q            theChildren.Add(aChild)
7 \- k, Z0 D9 M4 C        Loop
: K1 m  m/ W; v3 |5 `        Return theChildren.ToArray(GetType(Assemblies.Component))
: ~1 \: M- e, I' G$ S/ U1 c; Y) C
    End Function7 a5 p, B! q% O  Z
! \/ e) k1 }2 A7 {. m% L( O
    Public Sub Main(ByVal args As String())
% f+ K+ E5 l/ u& q3 j        If dispPart IsNot Nothing Then- B( G* R9 m' E) E6 N$ @
            DoIt()0 K8 o- s8 w/ ^/ v7 E$ M
            Return
5 j3 O2 d% p' ?/ Y. q        End If
) e2 }' H9 q  g, l' V
0 J6 }, U# w4 b( y3 [$ e    End Sub
$ Z% u  Q; [: ]5 c% j7 v# p, |3 D- t; v/ c1 Q% p
    Sub Echo(ByVal output As String): q1 m$ E) U0 D2 [" L- M* p5 [
        theSession.ListingWindow.Open(). x$ ^. x4 r/ e. `$ R2 h0 p
        theSession.ListingWindow.WriteLine(output)! ~7 Q, c* H# Z1 Z- c
        theSession.LogFile.WriteLine(output)
! v. t: [- \9 L% n    End Sub" }- Y0 U% P6 A6 C+ b0 [3 N
2 h5 N* ?# f! m+ {
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)" k! w6 u4 e: [% T# `
        If load_status.NumberUnloadedParts = 0 Then
" Y+ k0 l% o: C! B1 X4 F+ ]            Return
! r$ S) \) Q0 p0 s7 o# o5 ^        End If& w- O& A1 m1 N' L8 q/ B
5 k) N! ?  {: ^
        Echo("  Load notes:")/ v& c; z) r$ y+ v( m9 v/ @

$ N+ `1 l: f) q0 ~$ D        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
; _6 K3 p' o- C" D            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))! m  R' G, d7 a
        Next6 `+ }9 f# T* V( e+ w8 ~* v
    End Sub5 f7 `- y; N+ `# r2 Q! K
4 Q8 U- l6 [8 l5 f. z
    Public Function GetUnloadOption(ByVal arg As String) As Integer
- V/ u2 `, j5 ]5 s% a. w        Return Session.LibraryUnloadOption.Immediately* a' m- C" n$ J' P# ~
    End Function
6 f  T  c1 Q' m, b* O
! N2 @' H; h, H4 l  r6 W- OEnd Module[/mw_shl_code]
/ h- V4 `: x7 Q9 K! |* H+ D
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了