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

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

[复制链接]

2019-4-12 09:06:31 2398 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
9 k1 r& x; ~5 E% CImports NXOpen4 {  H1 E5 t) j8 R) E3 t5 I' Y
Imports NXOpen.UF5 x/ p- M7 b$ ^8 e8 x* K
Imports NXOpen.Utilities
. J; \: x7 T3 U( g) j- I$ |& K'
: y, j, |1 S/ _5 J0 r# y9 M' The OpenComponents() parameter
4 [8 C' y" `$ P- r7 Q# |' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
5 c% z+ J2 j. r" L( R' only opens unloaded components fully (see also PR-8406345)
7 J# R; u( h( i0 {; c' Workaround: collect and open all components individually) S2 x! ^5 {* @% d" @7 K; u
'
. ]: d; E9 M0 |; MModule NXJournal
1 g' C1 Z9 `/ K    Dim theSession As Session = Session.GetSession()+ x1 ~$ ^0 }( S; F& [
    Dim theUFSession As UFSession = UFSession.GetUFSession()& \3 C5 n2 j# W: {; j1 {3 |
    Dim dispPart As Part = theSession.Parts.Display# O/ [% }" E2 F, M8 c

* s3 ~: |1 ]# t8 U8 ~/ a    Sub DoIt()
' c; t# F# J: z0 i5 p5 S        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)5 Y& u  |2 j7 }# a. R1 H5 k
        Echo("Number of Components: " & allComps.Length.ToString)
( A$ Q- O( ^0 w1 w& b% ]        For ii As Integer = 0 To allComps.Length - 12 Q( W+ @. n  G
            Echo(allComps(ii).DisplayName); L, [' `) b+ p% X4 H6 D1 t; T1 X
        Next& \1 [0 q3 F  u7 Y
% f% R8 E0 i- v
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading2 A) Z& |' u7 X
        theSession.Parts.LoadOptions.UsePartialLoading = False  P4 S8 u* A$ o5 |  X& g

, J6 a9 D  I. d        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus  p4 l! O& T7 Q4 u% q; T
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing* i$ _% {  J! K2 S
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
2 W- k6 U. l) `  U3 H            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
+ h5 c0 h6 O* X
) q/ x. B+ r% F1 w" h        reportPartLoadStatus(partLoadStatus1)
2 v# L- Q, F/ u2 W( n: o9 n. m  e9 W        partLoadStatus1.Dispose()! j& A2 ^0 ?$ ~, i, e" D# `
( v  _( ]0 {- h+ _/ C
        theSession.Parts.LoadOptions.UsePartialLoading = option10 p' @0 [9 s8 g! M9 q. A

7 \$ l; M5 F9 r/ u6 q. K5 A    End Sub
1 |; Y! M* ^1 ~9 }8 M" m' _4 H1 |3 i0 r' z" s
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()/ X8 X7 ~! c: d; Y# Y% Q; ^
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList" x% g0 e& p4 T9 J
        Dim aChildTag As Tag = Tag.Null% y3 s, M& J  @

4 B$ ^  A/ W1 g6 |* b7 b% c        Do
; j/ l; }8 p9 l( v            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)0 o% ~9 Y/ d8 u7 e* L" I
            If (aChildTag = Tag.Null) Then Exit Do
1 h1 R; e/ d( {$ U) U! o2 p5 H
+ v' x' R( @; e: z$ Z6 C- z: C/ C            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)! g& v4 f/ N* k: P( a  x
            theChildren.Add(aChild)
5 a; Q6 G/ c$ T        Loop
# G1 _, v* g9 c6 }, h6 ^% W/ `8 [/ b        Return theChildren.ToArray(GetType(Assemblies.Component))
$ E1 [( L. }2 b# M/ p- F4 S+ e3 F- o5 v2 p; ~) [) T! }$ @- p
    End Function
0 T4 {5 N- ~- V
7 G, f! i! [/ q; _, T0 z    Public Sub Main(ByVal args As String())
! ]3 k0 |: d: T$ `0 h3 f' _& A        If dispPart IsNot Nothing Then
* f, K5 X# ?( n: V            DoIt()
/ V/ h1 ~# E: K% v            Return
+ s* B) C1 Z" v8 }5 i5 a( x8 f        End If
2 `2 g# T" ~7 R) W1 \# M
! R8 \+ ^% w$ S    End Sub2 F. l3 V+ h4 i
( ?" u, F5 i. b2 ~2 l
    Sub Echo(ByVal output As String)$ g6 N4 U6 F+ Q
        theSession.ListingWindow.Open()
1 |- X0 }9 w2 U$ a' q        theSession.ListingWindow.WriteLine(output)* k$ M( I  u/ m
        theSession.LogFile.WriteLine(output)  I8 M# m1 F! ?7 D/ z4 S9 C- `
    End Sub" T! e% B2 b4 h* F8 b5 M
3 u' W9 M7 e& }: Z& p
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
- Y# z$ R/ X1 |& L9 N        If load_status.NumberUnloadedParts = 0 Then
2 z1 ]8 s+ U3 Q            Return/ x; d0 S; E) K3 n* _3 g
        End If
) |- C( h* B4 Q0 L* _3 k3 t) F0 X. x5 M2 k7 d2 f
        Echo("  Load notes:")$ y/ \. Y1 e$ e8 p" g5 f+ q- M- q
- ~  V/ |0 O1 G) e8 f, f
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
3 u! v. e+ |; a' D4 _            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
/ a) ?( H8 t- x) h! q6 Z% R        Next
8 V( ~1 F# X  ~/ A    End Sub
* k1 ], O# o4 w
7 @' f% M2 D6 l0 ^  E    Public Function GetUnloadOption(ByVal arg As String) As Integer
/ a# F# y7 h" P6 ]        Return Session.LibraryUnloadOption.Immediately
( q2 q- X" R) ~( m. b. f    End Function' {1 h7 G9 Z' U+ O1 Q) a4 i

. i% O0 n  W$ a& x; TEnd Module[/mw_shl_code]( q, ~2 E7 S' i: U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了