PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2019-4-12 09:06:31 | 显示全部楼层 |阅读模式

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

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

x
[mw_shl_code=csharp,true]Imports System
6 V( Y7 f* G6 u1 E3 q8 zImports NXOpen% p* Y4 A4 u* h/ I
Imports NXOpen.UF0 E) }, {/ W' I' Q! }
Imports NXOpen.Utilities
4 m( I; l- W! ]; N'
6 S: t" ~5 @; G4 N& H& ~- d' The OpenComponents() parameter7 a4 ^% V( ^3 u) G. Y: D$ }
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly2 D) a) Y5 L' ^; G- g5 |; M/ d
' only opens unloaded components fully (see also PR-8406345)
% i7 l7 B- C/ p2 d6 `' Workaround: collect and open all components individually
1 V- f* K( v: x+ S8 h7 z( G. C'. V% t% B9 C$ O, J' _4 J# {- f
Module NXJournal& e2 s. i+ \" v. b' V6 P" f; T7 T
    Dim theSession As Session = Session.GetSession()+ P8 f. P. j5 G/ k: T& T
    Dim theUFSession As UFSession = UFSession.GetUFSession()
% u) l5 k# T4 \- J" E& X- P& u    Dim dispPart As Part = theSession.Parts.Display" v( F8 n) m$ D6 v6 y
& [) W9 K. m6 a" w  |# V
    Sub DoIt(), D( ~- k6 j8 }1 ^
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart): M0 r* d: x5 j( t7 R: }
        Echo("Number of Components: " & allComps.Length.ToString)
4 N0 F+ C: L5 S& ]' m0 i$ n        For ii As Integer = 0 To allComps.Length - 1
0 N( f. M% U, b            Echo(allComps(ii).DisplayName)6 v# }, p! \$ A; M* `% i
        Next
( z( k: Y. T) w. m4 J) [  v
2 m8 z' Y& a, R        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading' B7 f; [; g& T
        theSession.Parts.LoadOptions.UsePartialLoading = False2 [0 ]4 v% W) U# C

- a# E- C( R# ~. W6 @& @        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
5 ~. U0 R+ u+ e0 [5 t3 M/ R( x        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
# V, _) v. R  f2 }  w, N( x        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(# c" N' _/ a! ?' K3 a. r) g. }8 i
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)' A& J- k) U2 C% `
6 b) t, ]/ l& ^) W" n& q% {5 c. O
        reportPartLoadStatus(partLoadStatus1)* e7 y- t1 Z. k/ t% j
        partLoadStatus1.Dispose(). T& H) m- {3 F9 K  p

( J/ L9 \6 H/ j0 X        theSession.Parts.LoadOptions.UsePartialLoading = option1" J/ x+ j/ V7 J1 [3 S

9 M; \" Q5 o6 |/ L$ t: O( I    End Sub
' z. @) c- g% h3 @+ g- D
  S' C& q- \9 U    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
& @5 Y8 Y( x, S0 [3 {# O3 o8 w. X        Dim theChildren As Collections.ArrayList = New Collections.ArrayList8 |; i0 o9 y" {# u1 [% b' h" }4 B1 @
        Dim aChildTag As Tag = Tag.Null; Q! L( U% L; \- r2 U
- o6 E* n8 p6 N
        Do
4 Q9 C- o' \* S% n6 y3 \1 M% R            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag); ^! A7 C; X# V6 W
            If (aChildTag = Tag.Null) Then Exit Do
' F; y! Y" ]) a6 F9 i" ^2 S. Q
8 [3 o$ ^8 c( T2 [4 b% k$ s            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
+ \+ x* J9 f  C, q4 J& \            theChildren.Add(aChild)4 [. E9 S) C: O/ R0 L* @  l
        Loop% R0 L# \% u3 V9 B) h5 W9 C
        Return theChildren.ToArray(GetType(Assemblies.Component))
3 l0 ], K2 S# j; K; V2 j
8 u+ {# D% j  t& ^0 H0 C& A1 P    End Function
5 c% v4 h$ A9 T. Z' i' Z4 ^$ ?+ \( V1 l0 D3 j7 a% }: @9 k* X; G
    Public Sub Main(ByVal args As String())
% D" T7 }0 l) J4 H        If dispPart IsNot Nothing Then$ H2 g9 Z+ [% o
            DoIt()  j5 ^0 i1 k/ f
            Return
8 }& R! C  F' O8 i6 U0 |        End If
3 z$ w* E1 R. V2 ?9 a3 c! {: A+ |2 e" ]: e
    End Sub1 P# r2 U2 P+ l6 ?% q3 g: n
5 d; y7 H8 w2 H, H7 l6 P4 L
    Sub Echo(ByVal output As String)/ M, x7 A2 P+ o( Z
        theSession.ListingWindow.Open()6 p7 i+ i0 J7 ^1 X* j$ B
        theSession.ListingWindow.WriteLine(output)
% K8 G* Y' w! g  K' H# \/ @        theSession.LogFile.WriteLine(output)
! F; s" n8 N9 V% W, @/ F7 K+ A+ Q    End Sub
; v- ?5 m4 w- [! r2 m' S1 ^; M# C, k( P2 c0 b6 G0 z
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)+ d2 t% m! V& s# r8 R
        If load_status.NumberUnloadedParts = 0 Then5 W9 m: p5 S! W- r2 @
            Return
7 u! U: Z7 r% v* ~% _        End If
7 Z5 [4 i$ k" N; H. X; E' x+ C$ n
        Echo("  Load notes:")
- w7 J4 W# K" ~/ ^+ {% c9 a" w% J4 R* i3 z4 V. x+ x
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 19 |  @5 w4 H, {9 q! ]7 A7 t
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
/ j& z; ]- m' G/ T) ^8 m0 T        Next# d6 {# B* o' V
    End Sub( L$ r, @& p3 D7 {
1 ?8 I0 l! ^1 t' o
    Public Function GetUnloadOption(ByVal arg As String) As Integer: B! W9 p+ S1 z
        Return Session.LibraryUnloadOption.Immediately
2 G  ]- P: y; Q+ t6 `    End Function0 @0 @) \8 q- D0 F& W/ Z+ _# H) B
# }2 j* B2 h4 a6 z
End Module[/mw_shl_code]
; \2 p# Z+ U: f4 \% N( y5 k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了