PLM之家PLMHome-国产软件践行者

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

[复制链接]

2019-4-12 09:06:31 2338 0

admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
[mw_shl_code=csharp,true]Imports System3 x# y# m* c6 G  s- S. _# X
Imports NXOpen
9 K7 A8 g5 \. C7 z; ]Imports NXOpen.UF
1 t+ A3 n' R* l" k* f7 }4 y/ K1 B! wImports NXOpen.Utilities, F. m! U; x4 V. G6 B
'' l1 ^1 T4 T8 q4 C/ D1 H
' The OpenComponents() parameter2 n# I: S" a: \+ {+ Y# Y
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
1 b% N+ ~4 G8 \+ o6 j/ R" Q. M# O8 U' only opens unloaded components fully (see also PR-8406345): t% S* n: @+ p' l" U% p
' Workaround: collect and open all components individually
7 @# O, p& E/ C: c; \'$ M3 s2 X. b* I; x0 o
Module NXJournal
3 E: M( a) j; Q3 M    Dim theSession As Session = Session.GetSession()
4 n9 p  L0 X3 R4 q% w" u    Dim theUFSession As UFSession = UFSession.GetUFSession(): s8 g5 r- s- O: z( \# ^+ j
    Dim dispPart As Part = theSession.Parts.Display9 x( ?2 l9 _& w/ B% O* W
. Q" u( N' k3 k3 u1 _& m1 B) ^4 o
    Sub DoIt()6 m0 y/ N, Z; ~3 j9 H( v
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
2 O$ Q8 A; z% y& J' b/ r' \% J        Echo("Number of Components: " & allComps.Length.ToString)- v! |* [3 v- T8 h' j2 b
        For ii As Integer = 0 To allComps.Length - 1
/ |1 @- N; |& z) E            Echo(allComps(ii).DisplayName)
: L) q# o3 [4 i9 f2 s- p        Next
+ U( a. ]6 z: q9 p! M" h; t: }
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
# K+ d: {8 O" G* t7 ~  U0 n3 Q        theSession.Parts.LoadOptions.UsePartialLoading = False
# t" _0 R- ~4 |
  n! P! I$ c- q; C5 U$ e; w4 Y        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus% \, e6 Q( b0 Z! }
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing$ R( p* a9 q% D2 S/ `/ ?* J
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(2 W2 \# E2 w1 Z
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
# r7 {; M& x0 k- g2 O& Q
+ b( b+ K+ O  S: Q8 ^        reportPartLoadStatus(partLoadStatus1)- N' K( K) V; D( l* |2 Y3 `
        partLoadStatus1.Dispose()2 m! }' I9 U9 K$ P( ?: Q
4 x* _" ~1 W. E$ i0 M7 `6 r( W& h. }
        theSession.Parts.LoadOptions.UsePartialLoading = option15 J# ?5 n5 P7 [! X" Z6 B' o0 Q7 a% Q
8 ?/ D+ r3 g5 G- U8 R1 {
    End Sub
* j% w4 X) N+ A) Q" B7 z+ v) l! s% C
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
8 `; T5 R: |9 \. P* m6 c        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
6 D* v6 V" ~) f3 O2 b0 q9 a# O        Dim aChildTag As Tag = Tag.Null; v; F: x( z: S/ ~7 o* T- P. z

# O$ Y; b$ ~  T- s6 Q' Y: Q5 U/ P/ J. k+ T        Do
+ q- ?+ g' w" G( B% b- O7 O" T            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
1 t+ v' J% i+ w1 |, H4 Q            If (aChildTag = Tag.Null) Then Exit Do0 ~/ T5 a9 n3 U3 e' v" ~1 z3 d& E

( e3 R, g' o8 ]- A            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)# q% q* O& h: |3 w) B5 F' J
            theChildren.Add(aChild)+ W* U/ d# V9 }8 f' \% G
        Loop
4 X4 Z& o9 E$ x! g% n% h        Return theChildren.ToArray(GetType(Assemblies.Component))
8 J* ?/ k5 b! ^  F, V. y) W0 O! X$ v9 T" V
    End Function! C  x# c( n0 v: u% q

! p" ~9 q2 I5 {" y0 O+ M3 _: p    Public Sub Main(ByVal args As String())+ J- K& b2 B8 M( U& O
        If dispPart IsNot Nothing Then
5 l$ n# m5 I1 I& o  Z- Q            DoIt()
$ M/ O# b4 O; E! j. p+ e& Y            Return
- t. A4 x6 j$ ^$ e        End If
, a! ~, E) _3 P0 U) M5 g; a) l0 F$ k1 E" t
    End Sub
& h1 v* g, a5 }1 U
8 o; ]6 V6 y; n+ j7 ?. ?    Sub Echo(ByVal output As String)
. G2 z1 X0 u& e! z        theSession.ListingWindow.Open()
  u' b. d# j  q9 A" d6 I  e& D        theSession.ListingWindow.WriteLine(output)
% ?: U; i5 y/ O        theSession.LogFile.WriteLine(output)) \& L& c8 e: h- B* G/ ^0 Q) S9 f
    End Sub" p) @! Y+ c. `* q
* o5 O; j9 u1 p3 ^
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)( V) `0 Z' f' ]& M
        If load_status.NumberUnloadedParts = 0 Then
* D9 Z' }2 F# \4 t7 D            Return) F: }0 R' p1 T' c) g
        End If
& x2 t  Z- Y6 w! V
! R8 \3 `7 U( s3 ^7 B  i5 r$ W+ j( r        Echo("  Load notes:")
2 T. Y, f! W$ W1 _9 m
6 G! r9 d, _+ J( N2 G% r        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1$ e  i9 E7 J( f0 z
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
( }$ ^. ~" F% p6 S& A0 _5 Y: T+ j        Next8 T6 M! {0 D, W+ d' ^* O3 c9 a
    End Sub
1 Y6 S3 L6 c3 _1 U- i5 \- `/ @" o7 Y6 Y& u3 f3 _+ q+ ~. R
    Public Function GetUnloadOption(ByVal arg As String) As Integer5 u" a' P$ R2 N9 D7 b% U
        Return Session.LibraryUnloadOption.Immediately" R8 |( |1 k. C
    End Function
) s0 F! k2 e: B( P' [
6 ~& h8 k* Z7 wEnd Module[/mw_shl_code]
6 b# l% ~4 e( |  I* c8 ?! ?* @
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了