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

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

[复制链接]

2019-4-12 09:06:31 2402 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% h1 l3 S# p( \1 e
Imports NXOpen+ x- j$ `4 z5 Q' Q4 i3 `! P% D
Imports NXOpen.UF
2 h) @7 w4 e# _( J  f  hImports NXOpen.Utilities6 V, l' W6 ]* R" i& H
'
; z& ~5 F% d4 H5 T' The OpenComponents() parameter/ S: t! \$ [1 B$ v
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly, f) `# z) ?. K( K& [$ h8 y5 l
' only opens unloaded components fully (see also PR-8406345)# n' p, d4 \# w3 N# n; E5 B
' Workaround: collect and open all components individually" P# m4 Q1 L+ v
'
+ H* ^8 h& p# j2 h0 ]2 Q& [Module NXJournal1 P' [% c& t7 f
    Dim theSession As Session = Session.GetSession()  n$ d# P$ u% W) o) D
    Dim theUFSession As UFSession = UFSession.GetUFSession()9 l& F( x9 S* Z" e$ [
    Dim dispPart As Part = theSession.Parts.Display
/ j+ E& k4 f& I: u/ Y* w3 `* p) b; d/ P& g
    Sub DoIt()
- _. ]$ T1 D8 S' s        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
; \, B3 C- G, j1 `        Echo("Number of Components: " & allComps.Length.ToString)( f9 j) K/ T0 C7 t0 M. o: }2 P7 e1 d
        For ii As Integer = 0 To allComps.Length - 1
' x  p( T9 Z6 t9 A0 X6 O            Echo(allComps(ii).DisplayName)
' P& i, Q9 f2 y        Next: z) d6 y# m6 M1 Q: P

$ C6 q( W+ m/ ~        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading) _7 e; q/ Z7 c3 p
        theSession.Parts.LoadOptions.UsePartialLoading = False
, B/ c# G# a" M9 x- u/ k& M6 j- U1 n0 _% N  c2 V' `- q: p; q
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus( q! u  c4 S( |
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing% Q8 J- H' r  ^+ v
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(; i8 V+ [0 |, {% i' O5 W! n
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
+ G6 q: N; D# T% T( t5 X1 \  z
: j9 L8 z+ v; |        reportPartLoadStatus(partLoadStatus1)$ o- A' [* @! e7 ?# H
        partLoadStatus1.Dispose()* M! f  }2 Z- F, k- f& _
. k5 s9 r; t5 t5 m7 ~- H
        theSession.Parts.LoadOptions.UsePartialLoading = option1
" B+ m- Q/ s: l1 [* v+ B( N  F, p  l/ c1 o& W# x7 m
    End Sub, H# D6 e4 `3 K6 Q

, Q: d6 e# v/ l4 P  I: o- J    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()3 I; O( ]* i9 q# J2 M/ E
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList; D  p* V: @, Z( j0 f. P
        Dim aChildTag As Tag = Tag.Null( ~. b, f) q+ M; k/ [, e4 I
( N' n8 t5 T, v7 q+ P6 N2 f; c: a$ A5 X
        Do
+ E2 M  O' D4 V3 O) q0 S. p            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
* X/ ^- m6 D. q7 Q" O            If (aChildTag = Tag.Null) Then Exit Do
% p: Z% X" Q; H6 }
, O% \# F  Q' x8 Y6 w6 T; D            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
! C0 O( |/ c4 ?5 I0 X; b            theChildren.Add(aChild)3 Y( j: K2 V. k) [1 h! z9 a
        Loop! |! w! ]; I$ p* c6 i, u0 g) Z
        Return theChildren.ToArray(GetType(Assemblies.Component))
) p, J5 `* A4 o4 t
* J% Q# v/ O8 ]& I    End Function
% ]3 h2 ~, L9 j7 d5 Y7 q! Q& A. D3 k- z3 \1 b) u
    Public Sub Main(ByVal args As String())) S" S4 z1 q' R% o4 s  f
        If dispPart IsNot Nothing Then" Z9 [: d& U# T% u
            DoIt()+ m7 n! ]: J2 A$ t' }
            Return
- x% S+ f0 ~4 Y. I1 C9 ^2 r% \        End If  {; G5 Y% ]6 @1 \( ]
9 T, }$ d, D' e* H: C  R" |
    End Sub; t% s' Z( U+ F: Q

6 G$ M2 D& W" _. L/ A( E    Sub Echo(ByVal output As String)0 N4 g( L  t: ]2 ~7 }( g
        theSession.ListingWindow.Open()
, q- U5 ]6 M" O1 \( r: @+ ?. Q        theSession.ListingWindow.WriteLine(output)
: D  k+ l- A- W# A+ @) Q        theSession.LogFile.WriteLine(output)
- B9 m$ e' l$ f9 I    End Sub
4 {1 ?; _( o3 W/ v, J& u2 g6 e" F0 e* w
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
0 C& l4 T$ n: V' a8 z" K        If load_status.NumberUnloadedParts = 0 Then
0 @& f# _- k/ Y( q% @* y            Return
# u" O' u% ^  ]1 z        End If
( I6 I& X5 `" O7 i* @" P& `! |: C4 q; H; L) |5 d; m' O
        Echo("  Load notes:"), ~/ m  O# x" i2 Q. e# h
5 e5 e7 J1 C% ~. V- t1 e
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
6 l, N# c( \( k& `" d9 r) b; V            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))# c" L! b! H5 V* w6 b9 p, _
        Next0 |: R; q( S  ?: Z
    End Sub% f" U8 D, `# B
/ Y' Y) P( d* }) A9 E, Q: \6 j" b
    Public Function GetUnloadOption(ByVal arg As String) As Integer$ p6 \. E. L$ x& J  u, z
        Return Session.LibraryUnloadOption.Immediately
4 m# O3 C) J, ~+ F9 p    End Function( q/ x& j, x6 S1 k% ~

: M! a9 H2 F9 t: tEnd Module[/mw_shl_code]( q5 S' G/ \! h' k4 W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了