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

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

[复制链接]

2019-4-12 09:06:31 2428 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
) ]# N1 c, Q% OImports NXOpen7 r3 v0 R* Z* W$ B: K
Imports NXOpen.UF
5 `* ]) B0 |+ ]2 l' G2 M- WImports NXOpen.Utilities
, h& @& g# @! b7 m3 O'
6 v8 J: N  _5 q4 ]' The OpenComponents() parameter
9 g% _- p* _7 M7 q( h% {* D' W' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly% o3 ^/ m8 C  K' }" P
' only opens unloaded components fully (see also PR-8406345)
0 M9 N6 D; D9 f6 h' Workaround: collect and open all components individually) c1 \5 i/ r3 ~7 H7 v; U
'/ i* F" N% x8 T; h  w
Module NXJournal
/ \  z. F" Y4 G9 e+ G; y* d    Dim theSession As Session = Session.GetSession()
2 W& a% l4 e5 z, u9 q$ U0 w    Dim theUFSession As UFSession = UFSession.GetUFSession(): \7 @8 c9 r$ O. S2 h) I
    Dim dispPart As Part = theSession.Parts.Display
; j9 j& m6 l/ \9 S, V- {% E0 h- L% y. Y6 w( K
    Sub DoIt()0 ?7 B0 \% B' s8 y3 \0 K) z
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
* A! c% e& M/ N0 Y4 Q) h        Echo("Number of Components: " & allComps.Length.ToString)
, v+ L! W. `0 ?& m  D        For ii As Integer = 0 To allComps.Length - 1
: e0 U1 F  a1 c* `' U2 S$ u- X            Echo(allComps(ii).DisplayName)
2 p$ m: [) g3 ]& ~        Next
% G' f; P* B9 v3 N
2 A3 N4 D$ i0 ]( X* F        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
3 D6 \0 t5 N# f; X        theSession.Parts.LoadOptions.UsePartialLoading = False, |& @. U3 n- p+ q3 E3 c/ H

3 |/ A6 Z- C+ o' O        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
/ d9 \  T# J4 r+ A8 s- Z. N9 X        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
0 w3 v( m& D, l% X* Y- u        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents() |; J& T: b* f: |8 `5 P
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)1 M( S2 \0 C2 v/ |* N# Y: p! N$ d* g
" r! e6 ?' G% M
        reportPartLoadStatus(partLoadStatus1)$ h0 g7 k, q8 u( c+ q
        partLoadStatus1.Dispose()
4 g. E: W. c$ ^' g8 a0 e
$ K0 N, L. X$ l6 O/ h3 S        theSession.Parts.LoadOptions.UsePartialLoading = option10 s+ n3 |. a$ |9 ?% s1 \
8 ], ^) t. L& R+ R: s/ ]: N& r
    End Sub3 t- G) g5 z" U& C3 H+ Z" b

5 u3 A' a/ ^9 Y: J% U    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
- ~( ~2 F& @7 T        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
5 A) y  E1 N5 v        Dim aChildTag As Tag = Tag.Null- F# \2 l' V# S( J0 O% ~! Z5 R
+ j" @! d' K9 n9 e  D
        Do
. _4 b. K' U: T' @! ~7 E- ~5 a            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
0 t: {$ @" g- e            If (aChildTag = Tag.Null) Then Exit Do8 L( o4 [: D( Y4 I# k: G- {

' l# q5 I% w9 Y! y            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
' ?& G8 {/ Z5 ~" J" r/ }0 ?- ^            theChildren.Add(aChild)% W) }1 y* R* K
        Loop
. o/ M. o- h6 @( x        Return theChildren.ToArray(GetType(Assemblies.Component))
$ V  t2 g7 P& o4 L6 k# C& N  K+ b$ S6 P! c% t, ~
    End Function
( p* f% Q2 }9 D/ t9 u8 y/ w. t6 \$ }. E: u* w6 H9 N; d; t1 t
    Public Sub Main(ByVal args As String())
# X" N; Y7 ^# L6 m+ i        If dispPart IsNot Nothing Then
( d2 ]+ G# h0 n" @5 M+ ]            DoIt()& t- Q( ~- R% `1 }3 K' L
            Return
! N- u2 F$ V5 Z6 ^5 T        End If4 |8 R5 F8 V! j; c( a) h

+ i9 j: e: l% G9 I/ q    End Sub
/ X+ C2 k( i5 D7 x
3 M3 B2 i# M  H% [    Sub Echo(ByVal output As String)
8 h3 t4 Y- I8 j; k/ U: c8 c        theSession.ListingWindow.Open()7 O8 P3 V) ?2 |, G& m! {
        theSession.ListingWindow.WriteLine(output)
2 e3 R" p5 h& p$ F5 H        theSession.LogFile.WriteLine(output)) \0 k3 }: D! b" w7 U# C  ^" d
    End Sub0 Y; P( L% N9 \. `+ ^

) ?4 S/ u6 G9 J- ]: J6 [    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus). ^0 M4 i2 D$ t5 H# A. r: J0 ?( D
        If load_status.NumberUnloadedParts = 0 Then
3 L+ x: |8 C$ c4 C$ ~# U            Return$ H  c/ j9 K) n8 h. V5 `
        End If
  @: _) S+ B9 Y+ Z. k  B4 f' `# \& i
        Echo("  Load notes:")4 ~' O" b6 ]; k+ M1 K
9 C/ }- I* ^' i. P- J( H
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1& j1 p) f9 B$ \/ E0 k
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))5 ~- L: O& |/ Z: w* X
        Next2 M* Z9 K5 ?9 i: a" @3 M6 j' ]
    End Sub9 S0 t& d2 a- Q( u% K- T/ R8 C1 K% S6 a6 x
' e' j4 g! H- I5 l2 a* G% K
    Public Function GetUnloadOption(ByVal arg As String) As Integer
2 @% ~1 J' k. M- R0 F1 g        Return Session.LibraryUnloadOption.Immediately. I% P* b0 v, s3 u# d
    End Function1 q. w- t) Y" S

6 I. k, a1 s! g$ X) l2 P3 J) H4 cEnd Module[/mw_shl_code]
: w! r7 P5 o6 |( Z( 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二次开发专题模块培训报名开始啦

    我知道了