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

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

[复制链接]

2019-4-12 09:06:31 2457 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' B+ ^7 x; }9 s. }0 S1 S" n
Imports NXOpen, C* r# B, ^; K" _5 l; V/ B5 U
Imports NXOpen.UF/ Y# K0 v% p& I9 _
Imports NXOpen.Utilities7 g+ k8 q: _8 l: ~1 |# e
'
: i! b0 {8 u# O5 c' The OpenComponents() parameter
% E; ~  |# [% W  s- R8 @' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly# h  G6 ?+ r8 Z* L7 }' C
' only opens unloaded components fully (see also PR-8406345)
9 o3 y* x6 C; r' O" o' Workaround: collect and open all components individually
+ g, L' S3 E7 v4 |- h'
  z1 g1 x6 Y7 A: B$ J) ~2 ?: DModule NXJournal1 _$ L! ~, F; ^, a8 G# b3 ]4 c& H
    Dim theSession As Session = Session.GetSession()$ _" [" }1 F" o
    Dim theUFSession As UFSession = UFSession.GetUFSession()7 h2 a$ D& H; R. n: }
    Dim dispPart As Part = theSession.Parts.Display
* i8 u& D" j! ^1 e$ J- ~# w  M4 ^: `
    Sub DoIt(), I% Q7 Q0 A  n/ t) p5 ^
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
* V5 J, S; x2 U) T) p6 Z        Echo("Number of Components: " & allComps.Length.ToString)! c- m% |$ ]6 B% ~
        For ii As Integer = 0 To allComps.Length - 1' R+ }8 ]( r- K8 z9 B3 A2 E* b
            Echo(allComps(ii).DisplayName)
9 m  ~) E8 |! ^        Next) }1 l$ F% ~. ?% `
. y# R4 l: P3 Z% B* X
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
2 ]! {1 M+ j6 y, \3 z6 l% `" ]        theSession.Parts.LoadOptions.UsePartialLoading = False3 p  e1 n% ^6 A4 N* j

: H; S7 P* I; c- j$ S        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
4 k# p% P) H* U" B' K        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
3 K* k, S3 f- z2 W2 t  j$ l        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(4 v0 q% _% u5 j  Q2 t- o
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)  i6 |6 g/ X# m( B+ e, Y
, z8 e5 k! i/ a/ e  ^5 C' v6 O
        reportPartLoadStatus(partLoadStatus1)% k& L$ ~* n7 d4 Q+ n# `/ w
        partLoadStatus1.Dispose()
1 D3 v3 S0 \) s/ R" d: a: @5 b
# g4 S, y8 _. S" K4 N% N; F        theSession.Parts.LoadOptions.UsePartialLoading = option1
6 M7 q: }5 m, W- k( m! A' W. G
+ X* }* _% v& U" r! A1 k    End Sub  X0 }9 M3 ~+ x3 F% V% g5 |5 S

: j& B3 j( d  @- c' ?, g, f    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
) u+ b% s, d, W1 p        Dim theChildren As Collections.ArrayList = New Collections.ArrayList* F; j) q; r7 a2 z
        Dim aChildTag As Tag = Tag.Null) g- h( d; P# ^% n! F8 e. E

- b" b  ]. {6 B0 \8 |9 I0 i: }+ W        Do+ Q0 }4 [0 H+ q  z, P( p) n
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)+ u* l3 w) ~6 ^8 D8 g1 k+ h8 O
            If (aChildTag = Tag.Null) Then Exit Do
/ n2 f! H! L$ B; w5 ]
& o6 [- G; Q3 V+ V            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
% {: y$ ]) Q- q( T2 A' s, E" f0 T            theChildren.Add(aChild)2 K( K7 E7 K; o1 @: m& x% D
        Loop
* ?- o- z4 E. ~9 [: ]$ G* v6 W9 z& n        Return theChildren.ToArray(GetType(Assemblies.Component))! g6 B5 z' p1 c2 d0 |8 _! U
% B' L' r( g3 Y9 ~; m
    End Function% v  b4 a) P6 h- l. U3 q( b

" H8 F3 m6 ?2 a    Public Sub Main(ByVal args As String())
* V& P4 t  Y; ^: d. E# @) P        If dispPart IsNot Nothing Then3 Q% G7 I) O( h: {; {, h
            DoIt()
8 R1 G; |$ P, e6 {7 _2 Z9 _6 q            Return! B1 s. w7 t* I8 U9 M9 t0 s  R
        End If
: ?  i0 `8 o* o
% g  \% Q" y, _9 G% i, }$ z    End Sub
8 E! b" k: m; ?& L( ^- p$ d7 l0 K' Y
    Sub Echo(ByVal output As String): l8 O5 j/ u9 {& d/ @; j
        theSession.ListingWindow.Open()5 |3 S* q; s: M* `+ E
        theSession.ListingWindow.WriteLine(output)
9 n$ R/ s5 M1 C4 c7 {        theSession.LogFile.WriteLine(output)
- e4 e! k- A3 A4 [5 t: D& W    End Sub
- g1 ^# i4 v  J1 X/ s) ?& e+ t' m4 S7 S# `
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
, o) \4 ~) k6 x- j1 E6 G        If load_status.NumberUnloadedParts = 0 Then! {1 ^! _( _' m( W- ~( S' v* T
            Return* _1 u" y3 q# m: Q& J. O. m5 S
        End If
% A2 H* v* P8 q* b2 M! O) ?* K2 o$ f9 i8 Y2 A' j
        Echo("  Load notes:")
8 |" o; c& j3 G( ^8 w+ h8 M
* ]% z* k, P) m0 i9 B        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
+ D2 b# {% I) a9 ?# L( K            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))% L' N. F* G7 K4 y
        Next* U# d2 [) D2 @) C" a3 W
    End Sub
. ?; y0 s8 p0 G& K' K/ @  p; \3 |2 ^. x5 U- e6 M
    Public Function GetUnloadOption(ByVal arg As String) As Integer% h; f) Y' Z6 o8 W6 T( f  D/ r
        Return Session.LibraryUnloadOption.Immediately
1 w$ {. O. X6 ?9 D# P1 S2 K    End Function
% v$ t3 A7 Y; r2 T
( \4 h7 N$ I0 IEnd Module[/mw_shl_code]
. u) ?+ L& t8 F7 O% g) Y; ]
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了