PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2019-4-12 09:06:31 | 显示全部楼层 |阅读模式

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

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

x
[mw_shl_code=csharp,true]Imports System8 j: q8 U. ?; Z4 @. Z# B; ~3 C
Imports NXOpen
. h  `9 j7 R! Y- u/ f& o: kImports NXOpen.UF
* v  L, ~, J$ n" AImports NXOpen.Utilities
# |* o) i: m$ t2 H' \9 L'* F4 R1 z0 R% A; O4 x3 J
' The OpenComponents() parameter: b! d. m! Z6 S- Y0 `3 |" s
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly  |% b4 p, o# a' @4 i# ^5 [; q
' only opens unloaded components fully (see also PR-8406345)
0 A8 U2 p. S2 S3 i% c' Workaround: collect and open all components individually
  l  c$ L; b* n$ t') b6 I( H& @9 m4 B, O0 U+ Z
Module NXJournal: l9 H/ q$ l- i/ ^5 h$ [! f% L4 \; N
    Dim theSession As Session = Session.GetSession()
% O0 Q6 _, ]& M1 L7 h3 S5 Y    Dim theUFSession As UFSession = UFSession.GetUFSession()  F! w/ F$ Z7 D( u/ e) ~( q0 K" o( O2 j
    Dim dispPart As Part = theSession.Parts.Display+ p& J7 {# {# {+ l6 _5 t

3 g+ |( e; L1 U2 J$ k- Z  f* C    Sub DoIt()1 f* D( `/ [( b: P8 b) ]
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
2 {, ?2 ]$ t6 Q1 N) K! h6 f9 e        Echo("Number of Components: " & allComps.Length.ToString)# {7 A% Q3 z4 B1 B
        For ii As Integer = 0 To allComps.Length - 1
6 M) q" L' W+ Z6 [9 n9 e; u' k            Echo(allComps(ii).DisplayName)
- F" @3 f9 A1 [; d7 Y        Next
$ O8 F/ {. |; Y: c) N& ~: q$ ~
( a% L5 m& J. N        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
( ]2 q& [1 I1 b/ e        theSession.Parts.LoadOptions.UsePartialLoading = False
: L* i% a' k$ r" R  \
+ R7 B$ f$ N" ?$ x$ J! C, e3 ?        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
) ~, s/ c1 p0 ~- D& W3 K8 H' Q        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing1 p) B  j  ]: G6 b' e) M/ `+ h" O
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(! b2 n  M2 y8 {0 q4 G/ |8 E5 d7 F
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)" J+ R) i. p& l! [/ R! |7 X

" f/ j9 G/ C2 |        reportPartLoadStatus(partLoadStatus1)' |9 ~' a- `/ t$ Q7 c
        partLoadStatus1.Dispose()
9 G/ [0 l* ?) s7 P  X8 k6 w  V7 o9 v  n  o5 P
        theSession.Parts.LoadOptions.UsePartialLoading = option1. W! H: |4 @" T2 [

! B5 E7 T- G0 }. [0 z: |    End Sub
9 b1 O$ }" a; v7 F8 B) J, C
/ d3 _( v) o) s/ n    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()! O1 ^6 a! K! _7 C' h! Q8 [  ]
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList  q* C! J; `" D$ u3 @- C" t% D7 J
        Dim aChildTag As Tag = Tag.Null
9 T2 ]& t4 `2 g4 {' S; z: I  U7 ~6 B7 B
        Do
1 ?$ p! P0 f4 R3 q            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)7 P: ^# h9 |" L3 y* G
            If (aChildTag = Tag.Null) Then Exit Do
, V3 s/ d! k- |9 \  U8 f" f) ~4 S* |* U9 ]( t
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
7 ~; ^- f- R; F; }5 ^& S/ }, C            theChildren.Add(aChild)7 D7 F7 I2 y% {0 Z6 \" u
        Loop
: j7 a8 l5 e* D6 q  O        Return theChildren.ToArray(GetType(Assemblies.Component))$ l# Q0 U6 q+ A4 p- j
" B$ H0 J  @& Z' U% K
    End Function' _8 L& F3 m( M" W5 u
1 [4 g" D8 y6 m2 w
    Public Sub Main(ByVal args As String())
  R7 B" p1 }' \; I        If dispPart IsNot Nothing Then
  ^; u! G7 f- e7 R            DoIt()
4 Q2 j& a! c7 u# Z3 P. L            Return* a7 Z9 N7 u+ e
        End If
8 K' Z' R- `/ {; x& k6 L( H" f2 [( Z5 ]* p$ |) q2 H
    End Sub
' }1 j% P; S3 d3 f1 X- h& I  E' L) W; c/ L
    Sub Echo(ByVal output As String)) }  o7 c6 E6 y  q+ C  W* M8 a
        theSession.ListingWindow.Open(): @: s3 @# m+ a# u& w
        theSession.ListingWindow.WriteLine(output)- z3 Y/ Q7 y2 \
        theSession.LogFile.WriteLine(output)
- i4 f+ J' A  W4 L    End Sub
; `- U2 j% I' r
2 A7 E* ~& R& f# b    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
' ], B8 C/ t7 B3 l! c        If load_status.NumberUnloadedParts = 0 Then
+ K; y; a* `% {. D            Return
& r! T1 u5 g$ Y% q. f1 P1 E( t        End If
) H: M/ ^, k  E) C( b( z6 q! Z0 p2 x8 u. N& k
        Echo("  Load notes:")) h% \# |# H+ q6 i; p

! j: G. C0 X, X% b6 J        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1) H1 W% [% g% S: K
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
+ J. ^& m6 v; q# P5 X. X        Next4 C4 S3 r- W0 X) U3 _" J
    End Sub
! y5 d+ v  G. s6 B* A2 Z
; p: x' ]0 g$ ]1 F* E    Public Function GetUnloadOption(ByVal arg As String) As Integer
7 }. M1 M5 ^' b        Return Session.LibraryUnloadOption.Immediately
4 x3 s5 I8 S, r: B    End Function' {8 e, x9 h1 W* R
2 R. v: T" [/ K/ e) [
End Module[/mw_shl_code]9 }: T1 w: J- s5 K; U  R) d
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了