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

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

[复制链接]

2019-4-12 09:06:31 2453 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
9 b2 q; o! Z4 x; e3 k7 xImports NXOpen
) r4 d& c" @2 k5 K. VImports NXOpen.UF1 n3 E7 X5 Q& d* U- Y
Imports NXOpen.Utilities
& o) o5 [% R$ ['
# p& {" B- F- N0 z! S" J8 U; S3 M' The OpenComponents() parameter, o4 H# ^3 K. o! ]! ~+ q7 ]
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
; _6 C% d* i: o1 f* u$ y4 Z7 i' only opens unloaded components fully (see also PR-8406345)' o( ~8 L8 f$ q) |2 [5 T6 C
' Workaround: collect and open all components individually
/ O- t4 i1 u( \'
% }  N- H- M- p5 D4 |+ C$ oModule NXJournal
. o0 o  d, Y2 O3 E/ q- M8 ~    Dim theSession As Session = Session.GetSession()
- ~; h2 z, b$ _4 m! y% J( H, {4 m: B    Dim theUFSession As UFSession = UFSession.GetUFSession()5 t2 T& L+ K9 ]% r+ {5 x
    Dim dispPart As Part = theSession.Parts.Display
4 a, W" s' O6 o! l# G  i
4 r' ^* B: _$ [    Sub DoIt()
( s9 V1 \! V0 f8 u# f2 U/ M        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
' |1 Y0 I  V8 x2 w        Echo("Number of Components: " & allComps.Length.ToString)
! j" C: _& [  s; k1 e        For ii As Integer = 0 To allComps.Length - 1
6 S; |9 Z- U8 y9 L! ^9 q$ m            Echo(allComps(ii).DisplayName)
3 y, m& J% s. S+ R' n" K6 P1 ^        Next1 ^& |2 J& o+ v9 y
# T3 N9 S( w9 `8 a* \9 A. p* h
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
. m* D' Y. C1 b( {        theSession.Parts.LoadOptions.UsePartialLoading = False
# y& D& N5 f$ }, ^. o% ?& v/ s1 p! p6 e
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus6 ?9 h0 F8 w7 y$ T3 ]5 M1 F3 v  i
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
0 g  ?8 M7 B) o7 K: p: q% @        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
$ v1 d* e- X' u' ^            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1); W$ ^6 E) b4 E( I/ R' T8 r

/ h( p( W' c8 d  e8 _/ I        reportPartLoadStatus(partLoadStatus1)
7 ?& S) e4 Z) d1 n. e, `7 A1 \        partLoadStatus1.Dispose(); t7 T+ |' y0 ^6 ?
& O, I) Y* |) Q- n4 x  x# [
        theSession.Parts.LoadOptions.UsePartialLoading = option1
( s# s& X. H: j& p2 d' q7 [
8 R/ n; y% ?4 M, Q9 S3 {0 q+ {    End Sub3 M+ h) @0 T. u$ y: t1 Y
+ t, G3 c6 w$ o2 V
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(): _. {6 Y/ g) S5 X
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
, {/ J8 _& `/ O" u+ q        Dim aChildTag As Tag = Tag.Null" {$ c! s  ^/ ]- t
2 x! o$ O% ^( _) V
        Do
" p6 q! l+ e7 K8 V3 s# R8 h" p  x            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)9 j  y, N6 d+ W& K4 m
            If (aChildTag = Tag.Null) Then Exit Do
8 u4 b! p9 w8 _+ n1 }
8 u6 Y5 D) H- T# P  x            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
& N" l$ ^( N8 Z8 a, W            theChildren.Add(aChild)2 y* K) g/ Y7 K- [" W" p2 p
        Loop, t: w- r& ^; k8 c
        Return theChildren.ToArray(GetType(Assemblies.Component))6 ?) C; W* U; T0 @2 a. f, B/ D

" n( |# y& s4 C# W8 D5 j: C    End Function5 p# L" w7 s5 N5 s) s2 {

( u5 B/ u  g' F' n1 p  X3 `    Public Sub Main(ByVal args As String())
9 {7 [" l( t; m- @& m7 E6 U        If dispPart IsNot Nothing Then. F" [& l/ S1 Z) s: d' ~2 G
            DoIt(): m7 \5 ^# f/ n' l9 }. W
            Return, H' e& b. v& d  |+ P
        End If
4 S2 p! }: e8 k; ~$ s4 Q4 L, G# }' ~* B+ s% u# k
    End Sub
! v! n0 U5 A' `( G) i8 U
0 i7 J. M# _% u/ E+ j2 J& d  k    Sub Echo(ByVal output As String)7 z& E3 D' r  i0 E% D2 ~1 X6 u
        theSession.ListingWindow.Open()
1 C  _, ]( w: }* w/ e( d: }& [        theSession.ListingWindow.WriteLine(output)
% Y  y- k$ F5 ]0 g! ~0 a        theSession.LogFile.WriteLine(output)( Q% Z0 K( r4 y) ?7 S/ \( n
    End Sub6 y  r& H: l3 _, P. B
" X: y  J5 U) X" o0 p
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
% e! l1 O1 ~  u  W8 U7 G& Z; A5 ?        If load_status.NumberUnloadedParts = 0 Then
9 Q& Y2 _4 ~: f6 @- d            Return
' d9 ~% H1 U/ r+ _        End If1 F4 d. e# {2 |3 Z4 t4 y
" G' ~" X) \+ R2 x2 z
        Echo("  Load notes:")
/ [! B' I. C6 I$ M0 f5 u3 |1 R7 Q1 y: n9 B* u! E
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
5 f* C3 e5 U& F. A) q7 _            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))" s! S6 d. l3 s/ ~7 K
        Next: I& i8 ?0 G- A' ]! U
    End Sub
6 b( {7 j  \" s5 J4 I% O6 B
4 V5 H+ }6 a) P7 l    Public Function GetUnloadOption(ByVal arg As String) As Integer
7 p: ?" a* R" s. N. ^, }: K        Return Session.LibraryUnloadOption.Immediately$ O0 O- L0 e4 }/ q, C/ l
    End Function: b5 X2 H" Q+ `" v% B
7 X" c4 ]4 N1 x+ a7 I7 I
End Module[/mw_shl_code]
4 y# [' ], b  @' ?; U+ F  F$ p! f) 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二次开发专题模块培训报名开始啦

    我知道了