PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System1 l9 y2 s" s: X% ]( W, F0 x
Imports NXOpen
( J3 x% B% P8 g& Z  hImports NXOpen.UF/ Z, h, r: {, _8 u3 v* \' @& j
Imports NXOpen.Utilities( c6 }, r  c8 z" N, r
'+ p- l0 X; J9 U" O' G9 _) U
' The OpenComponents() parameter
! k: g0 G$ N2 o# v" p% v' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
5 a5 S8 S5 g+ r. g3 o3 Y- j% j' only opens unloaded components fully (see also PR-8406345)( z0 G! R8 y  V+ z) L
' Workaround: collect and open all components individually. l  n' D1 s. S5 y) C. ~$ S8 y
'% Z. M, e$ ~  m/ w0 p" u, ^
Module NXJournal
  V! M% O$ u6 R5 @2 Y    Dim theSession As Session = Session.GetSession()
: [9 a# v! [) T$ [1 ]    Dim theUFSession As UFSession = UFSession.GetUFSession()3 m( ?/ `" t! X+ _% Q1 t; m- D
    Dim dispPart As Part = theSession.Parts.Display
" t7 S' k% ]$ h! _
5 p+ g0 f7 K: E  I    Sub DoIt()
( [7 q7 _% |+ Y  a! n        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)8 `9 s% o" L9 ^: K7 s( Z+ U/ G
        Echo("Number of Components: " & allComps.Length.ToString)* Q7 H. \" N( {" n8 o9 b- h
        For ii As Integer = 0 To allComps.Length - 1
5 i% d0 Y  k/ r, G6 h            Echo(allComps(ii).DisplayName)2 n# K) O4 A7 M9 J* y2 o
        Next
# @$ {# @# f  G: ?) P1 a: ^6 e6 f) E1 C, r0 n3 E: P# T$ Z
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
  T$ \2 W! _0 p( C; Q' H% r; N) H4 ^        theSession.Parts.LoadOptions.UsePartialLoading = False, H: m+ O+ V. p

+ p. q! d3 t7 e$ \        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus/ j* o+ U7 e1 J
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing1 G6 l4 u" b5 M: ?2 _) S
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
( k: ~3 q$ a4 D' \            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)/ s' C5 q& ?0 J5 t% W
' Z! s5 k" K' _
        reportPartLoadStatus(partLoadStatus1). m! C- E8 c: _% O' Y  f
        partLoadStatus1.Dispose()
' p; C) q, K( W  ~$ E! F+ \$ U1 Q9 O. g& u5 R1 E6 h
        theSession.Parts.LoadOptions.UsePartialLoading = option1
' N/ b6 e7 c4 D" r) B+ Y1 Z
; p: V4 x# X  G$ n    End Sub
9 E$ U: t* a8 O2 O* U, w9 P5 w2 M5 ~+ x  _$ }  N! O/ g
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()- [0 `# u+ Q/ _1 W" l
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList+ N7 f+ O: }$ K: V% V
        Dim aChildTag As Tag = Tag.Null+ z5 |2 j  {, ]; D& R  d
: K* @7 ^, n! S: ~( a
        Do( ?% _! a  O9 U2 B$ O( i
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
9 k, V3 o+ u% c  @2 E9 j            If (aChildTag = Tag.Null) Then Exit Do
2 R- K( ^/ u; `( o4 Q
4 [% i: Q' A0 Y. h7 w            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)& h. u5 a( g8 l% C% c
            theChildren.Add(aChild)
& u. f. K/ z& h& c2 N$ K        Loop& {- ~2 [7 \8 ?. x( W
        Return theChildren.ToArray(GetType(Assemblies.Component))
% R1 T/ q* W; ^: ]! Q- C$ h" E, s$ L; |' m* \
    End Function& k5 ~  d) u: m: Y; C4 B! Q

7 ?4 R5 @" n1 K- B8 g$ I    Public Sub Main(ByVal args As String())
" H! D9 K2 \. f2 P3 _        If dispPart IsNot Nothing Then. q5 S, Z9 F& [% `6 j2 x8 m
            DoIt()
6 M5 b; f) t) A9 o1 z            Return% W' H- l8 f0 u( o
        End If8 y$ ?% v3 R* l
# k5 Q5 H1 z' _& _' P3 w
    End Sub
$ Y: e  L  Z7 n5 N# g( C
9 p" i4 Y/ K: s3 [1 M    Sub Echo(ByVal output As String)
7 P0 a. V( n7 `# t# D        theSession.ListingWindow.Open()
! d% c' {3 G* b2 f, I        theSession.ListingWindow.WriteLine(output)% m$ t' ~4 H9 T* M! F7 g2 X8 o
        theSession.LogFile.WriteLine(output)- `$ [- Q  d9 H' s: L0 s
    End Sub  [% |# D: r7 M

" A+ e, t# j6 L    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
/ K( j+ M/ b- |* }# n        If load_status.NumberUnloadedParts = 0 Then2 J( K" u, M& Y
            Return
* P5 H3 A8 J& _        End If, {' V4 a6 P# d- k8 t' A$ ]9 c" T
- p1 o, L* R2 m- t1 ]6 c  ^
        Echo("  Load notes:"), t) z$ L: h" X) \

! v% D) ^* ]' s; G8 ^        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1. }3 m8 b8 @" u( Q: q
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))$ ]8 A# m2 z, A7 i
        Next
% d; B+ y, D0 f8 V. Q    End Sub$ W  `4 w) s1 ~% Z7 L1 W3 w% t* S
6 ]8 G2 {! U, ]3 W4 k) d- N' I! |
    Public Function GetUnloadOption(ByVal arg As String) As Integer2 v" l$ B5 t: V% t5 D9 |* v1 p
        Return Session.LibraryUnloadOption.Immediately
7 \+ R6 a, Z" l    End Function; W9 [% I% I" D+ @+ M8 V7 a
6 D& h8 P% ]3 G. Y! {) [0 [+ J
End Module[/mw_shl_code]
+ |; [/ ~0 a8 r+ H6 T* 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二次开发专题模块培训报名开始啦

    我知道了