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

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

[复制链接]

2019-4-12 09:06:31 2378 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
" R) H9 Q* d9 ?, e$ wImports NXOpen
) g  y4 {$ F; q: B" T7 c% w' eImports NXOpen.UF
6 J) c( H! H* I$ e. c' U7 p% NImports NXOpen.Utilities( W; H( n( |7 Q+ y( [
'
& B. U0 ~8 _1 b2 P1 t" |( |# x' The OpenComponents() parameter
. @& N* h% m# d5 N3 v0 V- d/ N' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
) c, `: D: R. V( u  C' only opens unloaded components fully (see also PR-8406345)
# w' ^( b& p8 U; O+ I9 R, J' Workaround: collect and open all components individually
$ x) H$ n. J& X9 t* S( C, l'
- W$ L9 R  f9 ]! L3 |Module NXJournal% h: q6 B$ W9 ]6 K' J8 b1 L
    Dim theSession As Session = Session.GetSession()0 c, e, X  ~% |  t( _0 _" K6 H: V
    Dim theUFSession As UFSession = UFSession.GetUFSession()
2 b8 Y; s! F/ n, W* Q  x    Dim dispPart As Part = theSession.Parts.Display( o' v6 Q6 J' p9 G% J* b$ G! ^
0 w* Q: B, }2 _) c0 {, B$ X
    Sub DoIt(); ]6 K3 d4 J2 P
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)! _/ m& K! y* o9 h% v/ j
        Echo("Number of Components: " & allComps.Length.ToString)( n' c+ w; ^- O6 z$ E9 s. N
        For ii As Integer = 0 To allComps.Length - 1  w' z& H$ m3 d9 \1 N4 Z' Y
            Echo(allComps(ii).DisplayName)& ~; _: I3 D8 J4 L% x
        Next
8 K* o/ P3 w% I7 k- W4 b6 [! k! I" w. e0 c' G
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading: t5 a* G9 R8 r% A; `
        theSession.Parts.LoadOptions.UsePartialLoading = False
0 P' _0 T9 ~! _, p- h- L# c/ ]' p: t" U# k1 N! V  j- g- V& Y, a/ X
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
+ g4 T/ `6 F& e5 j. L2 N, Y! E  Q        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing& ?% L: c3 p! F- d
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(& C& r" X4 Z( h$ b) e
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
; O  a: g& H' a; k' n6 J" A1 `. L3 U8 _2 L8 l, ^/ f5 n
        reportPartLoadStatus(partLoadStatus1)
7 F, ~# W$ M/ z% M* x        partLoadStatus1.Dispose()1 ~: d$ k+ [. }) u; x- e) ?) n

9 g9 a9 V% ~2 L# T0 \1 c' p3 G        theSession.Parts.LoadOptions.UsePartialLoading = option1
- Q  @# y8 v4 K% L- P% a1 T# f* {% o8 U, L# ]! {" |
    End Sub- V+ U$ }1 o7 ]% {

) j6 S; }& r" w) t2 B6 f    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
$ _* b/ s  S- k; L        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
1 X  E) q- s% H1 i7 N" b6 m        Dim aChildTag As Tag = Tag.Null
& R/ E8 O) Z# a2 o! q) ?5 M: Q
        Do2 J  w- n( W3 R2 c. n- ?1 G( i& p
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)  `$ z, ?+ E2 G% U1 U1 c, o4 u+ j
            If (aChildTag = Tag.Null) Then Exit Do% J, v& P# ]; v

5 C/ Q, r- p! Z! L) I+ E& F0 \3 p+ X            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag). ?3 J8 |9 V9 [! i( O
            theChildren.Add(aChild)
3 e7 S* y) _% q! V/ Z1 J        Loop
( E' L- _# z: }( S  A9 ]' a/ w7 ^        Return theChildren.ToArray(GetType(Assemblies.Component))
$ c8 `6 k& G" z5 z$ B$ f/ b$ q. E( d2 Q1 I9 A% u5 |
    End Function( o! l- v- n2 i4 d/ n& P
  C) U  h4 }0 a) ]) R  I
    Public Sub Main(ByVal args As String())
$ o# M* i) i# Y( K: c8 B2 f        If dispPart IsNot Nothing Then
, f8 [* W& K4 X- N) Z            DoIt()
& a1 P) K) d4 {- d6 H+ s5 u            Return
, n  ~+ V/ X5 l3 D  p0 e$ _3 X+ P        End If
; F7 ^6 c1 v: y, N5 y' N
+ q* o/ m6 I, e% u# b    End Sub' ?. G. G" P) L( d, h6 ?
+ {$ {; e7 L) m0 A  q5 K; j; `
    Sub Echo(ByVal output As String)% p. o/ D6 h+ B
        theSession.ListingWindow.Open()
* y7 ?# ]% k, F. I        theSession.ListingWindow.WriteLine(output)
! p8 `6 G0 p% A' b: ~9 C) `* F        theSession.LogFile.WriteLine(output)
& ~& ~4 t6 o- q. B0 c0 Q    End Sub
5 H4 j, N. v. A* K5 f4 L8 @9 q. B8 v! E# U' ~' C
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)( ~7 a. _9 i( o4 ]
        If load_status.NumberUnloadedParts = 0 Then6 }  r' F" R% M  M: J
            Return: K3 O% T' l; J/ g
        End If
5 i0 v3 Z4 s3 L) l3 n# G+ Z  Z. ~8 A
        Echo("  Load notes:")7 l" u1 L7 Z0 q
" X# D7 {: w7 _/ V6 X, {
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 16 \; r) U# X' N0 O4 J5 L
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
1 a0 R8 H7 Q( I4 x5 I7 x        Next+ w! h) O# w* Z( e" B2 S& L  t" K0 X
    End Sub
$ P* S& z5 E  i+ h/ x/ a
7 s! `. e1 U) A: u$ p+ m* \    Public Function GetUnloadOption(ByVal arg As String) As Integer$ q3 ?/ X7 M! q+ h8 F! j# ?, G7 O
        Return Session.LibraryUnloadOption.Immediately
  |4 L) w* Y1 d8 [$ X' v# W* h, Q    End Function9 w1 r( Y  l: F* u9 q

! @1 b3 a4 e/ r9 k: J- eEnd Module[/mw_shl_code]
" M& L  L5 l: Z5 t- ^) L+ I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了