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

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

[复制链接]

2019-4-12 09:06:31 2409 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
4 I8 s+ t! w" k9 `1 kImports NXOpen( j" @5 ~+ R4 L' o- k% y( }
Imports NXOpen.UF- N4 u4 Z. o( o4 G8 j) o
Imports NXOpen.Utilities3 H5 G  T6 L  g
'$ M! E+ d- j. g, E
' The OpenComponents() parameter7 o9 v( ]" P, C9 M' v- D
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly6 C# d* H1 Q4 c! Z7 }
' only opens unloaded components fully (see also PR-8406345); K. w: K; k% }: `
' Workaround: collect and open all components individually
; T/ {: x& _& u1 R" }! O" r; W$ g6 ^'; `. b" l* \+ M" C3 B
Module NXJournal: }9 o* J6 ~& Y2 M( ]
    Dim theSession As Session = Session.GetSession(), ?, y$ T7 [3 Z( s) f) m( M
    Dim theUFSession As UFSession = UFSession.GetUFSession()
& U6 t. l3 ^9 b" [    Dim dispPart As Part = theSession.Parts.Display
0 b, ?% f+ y: n* H# ?% I! d1 g3 o. k% G
    Sub DoIt()& q- o7 a1 h( V2 L7 A
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
( z9 V' s; o8 a: |  K+ S        Echo("Number of Components: " & allComps.Length.ToString)5 r1 ~6 F: [& h: s/ a- A! H
        For ii As Integer = 0 To allComps.Length - 1
+ R+ Z0 ?# G* k$ {/ m* L' j            Echo(allComps(ii).DisplayName)4 p, T2 S) A- ?5 m% I# v
        Next
4 J! r' W+ i) T" Z4 ~1 y) {9 k( O7 b! E7 R% s. m% j. T
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading) Q( K5 Y+ H0 L" c$ }2 l. q+ f
        theSession.Parts.LoadOptions.UsePartialLoading = False+ I9 k) O8 L, I* v% i4 j
* R. w# J) d2 p  |' G- F; `* h
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus& ]( V& C+ ]) }  X0 E0 |
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
7 O. r8 L8 B+ b        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
  h. |! M! W* m2 U# `8 z/ D) c" p            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
+ ^& S" Q$ X' e& r7 L, E$ ]0 U& Q$ K
        reportPartLoadStatus(partLoadStatus1)
6 A' Q, _% g3 d4 r3 P* G, V( d        partLoadStatus1.Dispose()
" [2 U4 u2 |" N0 T. q2 v2 |1 Q# U, \6 c  T7 {
        theSession.Parts.LoadOptions.UsePartialLoading = option1
! d3 c' m# g6 _5 v$ }( l& W8 `- N
    End Sub
; F4 M( v" C% F5 u6 ~' o
4 f1 A0 m7 r+ m7 t# Q    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
+ @, G, ?2 ~# [' l        Dim theChildren As Collections.ArrayList = New Collections.ArrayList! x  x: ^2 O% t' Q3 S
        Dim aChildTag As Tag = Tag.Null5 {# [5 J8 k" b4 k4 e' {

3 K6 G  N% v! T) }4 ?1 ~6 ^7 |* N        Do
; k6 n" q3 O& P# H$ o  Q* b            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)3 u% L$ k% `- U5 V1 B3 h, }7 j
            If (aChildTag = Tag.Null) Then Exit Do
: f9 W% L0 b" S( R% m  ?/ s8 r
* ~' C: j3 d4 Y            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag): I8 G8 \9 d  y5 a+ b  Y
            theChildren.Add(aChild)! E, M( I0 y$ T4 u! w+ ]& y% c
        Loop/ B: i, {/ C" X4 K
        Return theChildren.ToArray(GetType(Assemblies.Component))
9 y8 i4 h% c. U5 i. j
+ S; [, _  z  R# a" j    End Function  B% s5 I1 l8 {0 X+ m, J7 o$ o
( Q, Y% ~1 F; j& k6 J/ u9 E
    Public Sub Main(ByVal args As String())* B+ h2 C& \6 @" ~. }% _8 j
        If dispPart IsNot Nothing Then9 W2 O, \) `8 S# ^3 C
            DoIt()! Q" J0 {, j3 M* P8 B3 {
            Return
6 h  ?$ r" x: L$ v        End If1 a. w8 _5 ^- j4 i$ p5 T$ T

& s9 i4 ~! X7 [. V    End Sub
* L* i8 j# b0 N6 \/ x" }. |5 C) R# X/ n2 v, S- c! p' M6 S
    Sub Echo(ByVal output As String)8 C/ a1 L" s' p3 B) K( a' u
        theSession.ListingWindow.Open(). X& ^* ^5 J; J8 R  l0 \
        theSession.ListingWindow.WriteLine(output)& e+ Z; g; w3 y
        theSession.LogFile.WriteLine(output)
4 Z; z: Z9 a, \; D0 D. ~    End Sub
6 F7 r5 P% d: ^& R
2 h! e5 a' v& I' g* s3 ]; F    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
2 l9 c1 R: o8 N% U+ J        If load_status.NumberUnloadedParts = 0 Then! m, p! ~: z0 F2 _
            Return
1 f) u8 W3 Z% U, _        End If5 M' Z" G: ]* A2 q- m$ P% G
8 c, `- h( b" [
        Echo("  Load notes:")
: b* v( n+ _6 Z$ P1 x2 R
9 S  P1 f! ^& F        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1/ O2 x0 O) j; y- i" D
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))* r. }6 y3 Z+ _6 \8 m
        Next& [4 M& X; D9 ^" X
    End Sub
: ~, r5 d% ~! I' b- W& H9 I: S( F! A0 b) _' u, r8 w
    Public Function GetUnloadOption(ByVal arg As String) As Integer$ B' C6 G( @7 `" P2 l4 m9 Q" ~0 b6 a5 p  U
        Return Session.LibraryUnloadOption.Immediately( ]3 u8 @' u- r; D. E+ K
    End Function
' D& ~8 F0 ]" |( [" Y- B3 M% ?# i- m, N7 V2 Y- D  H% H) @( {6 |3 j
End Module[/mw_shl_code]
( S4 |" b4 _( H: M' 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二次开发专题模块培训报名开始啦

    我知道了