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

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

[复制链接]

2019-4-12 09:06:31 2476 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
0 g0 ~% }- A7 P3 g. Q& h3 \Imports NXOpen* ~  ^0 ?* D$ h
Imports NXOpen.UF
/ j. H1 D! a, q9 V  vImports NXOpen.Utilities. L; x- U; D  P  A- C9 n
'
8 V+ W( K6 t% u( o( V& a" }' The OpenComponents() parameter$ E4 W# P3 W6 x/ ]- L$ ?8 y7 g* ^
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly) Y) L9 r2 X7 l
' only opens unloaded components fully (see also PR-8406345)
9 f. A$ J3 C0 V4 i' Workaround: collect and open all components individually. ]& a% l& Y4 F5 W
'" X8 k& I9 O, c( r* w
Module NXJournal' y9 ]/ F+ s. C+ W. `4 _: |1 n
    Dim theSession As Session = Session.GetSession(); x0 G" d' a' k( T" s  T
    Dim theUFSession As UFSession = UFSession.GetUFSession()
' f* S  u  V' C. n* }; _! h9 C    Dim dispPart As Part = theSession.Parts.Display5 V  v( d, P( F* v5 g
: n7 X% F; i4 p7 l' k
    Sub DoIt()- j7 {' ^+ ?  c3 d6 n" i5 Q* X0 h
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart), d; ^* c! S, n  V# T
        Echo("Number of Components: " & allComps.Length.ToString)5 S' e$ G8 L9 r5 V3 w2 n9 }
        For ii As Integer = 0 To allComps.Length - 16 _2 [" L; k0 Y8 R3 V- B- q
            Echo(allComps(ii).DisplayName)
) w# o* n3 V2 f        Next1 `& V4 C7 w( N

6 m( U4 y  z; t4 o4 [, D, v        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
, m, U8 g+ E/ @4 d% V! X, F; y        theSession.Parts.LoadOptions.UsePartialLoading = False1 A/ I, F$ N# h6 g

& v3 w; q% x" n$ f5 B: b        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus& u7 m7 j3 N& [/ O: k
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing% i/ o- T$ z6 b: \$ E. P
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
) {' E  E" j/ n# f) h5 m/ ]            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
& J$ f# z6 u+ \' k1 V
. _9 ?. u: P( u- G2 y. v        reportPartLoadStatus(partLoadStatus1)4 k4 C, Q* y4 v" p3 C/ K) E7 R& G) u
        partLoadStatus1.Dispose(). H" p) L9 G% n! u5 K# f

6 x* D% M0 `+ Q        theSession.Parts.LoadOptions.UsePartialLoading = option17 o0 r: x! d/ u! Z$ g' ?- h
4 A/ a8 S+ U/ P. P; s
    End Sub0 \% K1 g) d& D  ^5 z2 N

: D/ |$ p/ D: ^- a, S    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()$ P! U4 [, p* t1 K
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList( |/ m4 _: t5 `5 d
        Dim aChildTag As Tag = Tag.Null
6 `( l2 R7 t$ p% V% t9 H
1 |( _5 u+ E# Z! m9 }0 w        Do6 U$ |* W+ C: q. B
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
: G8 |5 \2 O4 h% B4 x( J, i& P            If (aChildTag = Tag.Null) Then Exit Do' _7 p9 w( Y1 |! }5 H3 p# i( B

+ U2 y! o$ x9 o( Q1 Z  s6 H            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)- n6 }+ i1 B, u2 Z
            theChildren.Add(aChild). j1 O* l5 L- x. j6 g7 I3 B1 |& p- T
        Loop9 o: }. Z7 f+ @  b, ]
        Return theChildren.ToArray(GetType(Assemblies.Component))  g' }3 ?9 r6 C* g8 F

7 Q, L2 ?. }- _. i5 M+ q    End Function
: f( D8 }% A5 ]) U9 y7 j1 C6 X( d3 m: h+ r+ f& t7 [* W& o, O) \
    Public Sub Main(ByVal args As String())/ ?% u# P/ q8 l0 F+ F
        If dispPart IsNot Nothing Then9 q$ J1 I4 s( O0 T' V
            DoIt(): D5 U# q4 s/ E$ V; g$ A' e
            Return( t3 u% e; N  a6 r6 `4 v6 s: |
        End If
, L! P+ J5 k+ ?) P3 c7 _: @. Q8 F' v# J4 m% {6 {2 I7 T2 K3 p# z8 t) s
    End Sub, w+ i" x% v! ~; O  @

2 \( H. {& Y0 M  J7 O    Sub Echo(ByVal output As String)
9 D' R+ z) r5 K4 q: V- |        theSession.ListingWindow.Open(). V. n! b$ U% K
        theSession.ListingWindow.WriteLine(output)( A  y9 B3 S) z& k
        theSession.LogFile.WriteLine(output)
6 r6 G9 i7 f9 O; U* D' Z    End Sub2 `: W( X% M9 I6 k1 R  I

" k- F! g# L! [    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
4 T# M2 `6 Z: p; y; o# a1 s, R, \( Z        If load_status.NumberUnloadedParts = 0 Then
9 t; ]+ Y1 N4 z' v            Return
  o) m. W( D; i        End If
( D. m: u; Y* u) e! ]1 w4 r# m1 C3 m/ T' E  ?
        Echo("  Load notes:")
* Z% e" G3 U7 L1 }. K4 d* u* J! z% A) P
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 13 V: ~5 _; N* y7 ]2 u0 L/ i
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
2 O% |: B. q! H3 P        Next9 N5 x& k" N" ?# r" C4 T! J
    End Sub
: I, y5 X2 W# x" b# o! u5 X# S& d% @0 R2 x. _8 \) L% P
    Public Function GetUnloadOption(ByVal arg As String) As Integer
- m4 o0 {$ H) ?& m. I' k# i* H3 R        Return Session.LibraryUnloadOption.Immediately3 ]5 W6 E% C) X/ {) T
    End Function" J- \; @8 ?: C" V- h1 ^

* m' h$ T8 v/ o( U% n5 vEnd Module[/mw_shl_code]  z, k9 A  |* _; Y( Y$ o  j
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了