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

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

[复制链接]

2019-4-12 09:06:31 2463 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* k( N2 x) I9 o* `
Imports NXOpen
+ x6 m4 N, D+ @7 aImports NXOpen.UF
5 w( O/ f* N$ |! [$ x; T& cImports NXOpen.Utilities
5 b, E$ t1 C$ l0 w5 S) ]'
) U# r, m, L- f! K6 V' The OpenComponents() parameter8 g1 c) b' y- e  e2 N+ w' ]
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly/ N8 P9 {1 Z7 C- ?# b- j
' only opens unloaded components fully (see also PR-8406345)) A- l; e! E" Z: {" W! M
' Workaround: collect and open all components individually: l* R' d" d& F3 W+ s5 g
'
+ ^# O! R. H5 |) F' ZModule NXJournal' o; K* V* `) f; s" a: U1 {3 ^
    Dim theSession As Session = Session.GetSession()
9 C4 |# _5 W/ l6 r8 s    Dim theUFSession As UFSession = UFSession.GetUFSession()
: T% ]' x" M; E. c    Dim dispPart As Part = theSession.Parts.Display
- F7 V' ?  D8 S2 B, x5 u. E
, ]2 G: S# T5 g1 t7 @+ ?  X9 @! H9 n4 _    Sub DoIt()0 j' k/ U: ?$ [1 k/ ]% t
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
$ M- f8 h( H( m        Echo("Number of Components: " & allComps.Length.ToString)
/ W# U( F+ @; G: `$ l* q! _; f        For ii As Integer = 0 To allComps.Length - 1
- M4 `2 v0 x2 ?+ H# e, `# R; N            Echo(allComps(ii).DisplayName)# S" V5 q8 ]! z; ?: \) b
        Next
$ l2 ^; b# ?; K3 _
# C2 j0 w* e2 d: i) Q: g* Q+ |. R        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading) \& Z, h! @( D  z
        theSession.Parts.LoadOptions.UsePartialLoading = False
" N" v  N% Z0 G8 ~) T1 d" o
4 ^7 W5 ^% c8 r        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
8 o/ O( S; L5 E) D4 P        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
, t  ?) G/ P7 M" ?. g! Q. a        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(& B. }& B* I+ M2 X( @# \
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)) w5 h3 d4 ]! C. u/ V
& I" K5 g* ]4 |) G8 r: x/ c3 U% J
        reportPartLoadStatus(partLoadStatus1)9 p0 \8 A* _$ U* q2 j5 A: Q9 ~/ J
        partLoadStatus1.Dispose()
8 K9 H: p7 s% |8 a* ^9 I
( {& F; S9 l1 S* g$ W        theSession.Parts.LoadOptions.UsePartialLoading = option1
3 o( `: N% l8 ]) h
) h- w: U! S" X4 J: z/ E2 N    End Sub
) p- f% @; y) U
5 i6 m' n) S- g$ W$ L4 W% V" _! g5 X" X    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()* T/ Z# }: b4 _4 h& K: I
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList: O, M( F  ~8 k: D' |8 I
        Dim aChildTag As Tag = Tag.Null
$ @9 y1 G/ U3 b( f+ |# K
* l4 V) a* }, y4 M        Do7 e$ O: s# z+ P: R4 [% k
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
7 B1 y/ r2 E% ~            If (aChildTag = Tag.Null) Then Exit Do' g, x8 _1 n2 f0 P
* x  ^# G* v- b
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)# x, p6 s5 Q+ `. ~, j0 {- [6 L
            theChildren.Add(aChild)5 s! f! M8 J2 j  `  m
        Loop
2 Z, J0 s# n, y3 _4 f  \% v        Return theChildren.ToArray(GetType(Assemblies.Component))7 v3 H& X) q1 R2 }& s8 a
1 O% ^3 \/ x- c! g6 f1 C
    End Function0 m6 `5 N. q9 ^6 R. F5 H8 W

3 c6 d( h! g5 J1 \    Public Sub Main(ByVal args As String())
) ^% |$ w# C  i* X, D' a1 L        If dispPart IsNot Nothing Then3 P4 L% \: `& P) y4 F* t% {% `& C
            DoIt()
' K, M6 t% I" _% q1 \8 ~9 n            Return% o5 f( L! H2 }
        End If
! F5 B6 @/ g8 z& P( K" d0 p8 r: ?& l
    End Sub" E. a( g6 y" A$ X* p

9 B& e6 X) \  A$ Q) {    Sub Echo(ByVal output As String)9 A; c/ Y' d2 d& A* I
        theSession.ListingWindow.Open(), R' D* U4 w  [: Q/ J, o* q
        theSession.ListingWindow.WriteLine(output)* d; r0 a* B: D! b0 E: r! s7 g
        theSession.LogFile.WriteLine(output)! l- G( {4 R( k2 A
    End Sub
( W  A. h1 y# x. H: Q: j7 |( n; L9 q2 ^  `/ G) t
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
  S2 c4 f" K( n5 W8 S( Z7 t8 g        If load_status.NumberUnloadedParts = 0 Then5 _( m3 x1 _$ d
            Return1 x: c+ @, K5 }0 q/ i' b9 r' z
        End If
! ]6 c( a' A) Z1 }( |  M( o  j6 Y& O( z: U. L6 k: o
        Echo("  Load notes:")
) ?1 O% H' `( Z; D( m* M9 N) Z; ?0 l' R/ R9 Y/ M
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
% X/ V5 |* ~* ]4 j            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))2 D! d4 T" x: Y; j+ g" t
        Next% b( }3 w) i3 B$ [
    End Sub
8 u9 ~. `* r2 y2 O- r. b) Q! x* w
1 y( t3 D: ^5 S& r% |, j    Public Function GetUnloadOption(ByVal arg As String) As Integer9 U* W4 W9 w3 q2 H$ k
        Return Session.LibraryUnloadOption.Immediately
- z) ^) D* Q) r3 y7 v0 c    End Function
4 \$ s9 S9 }* w6 Q: L9 I, {5 }  \) r
End Module[/mw_shl_code]& c! h/ G6 F! p$ Z  H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了