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

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

[复制链接]

2019-4-12 09:06:31 2427 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 j; e4 a4 c* E' W8 [4 y
Imports NXOpen
4 l) T3 y  L) Z  E% PImports NXOpen.UF6 [5 e" r* L. q9 _) F( M" S- x
Imports NXOpen.Utilities
# M9 _1 a6 M8 `% m' v'
$ H$ B; W  z7 _! ~8 h( b$ X' The OpenComponents() parameter( q9 g0 o! W( Q
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly) N( T; T1 u9 q
' only opens unloaded components fully (see also PR-8406345)' O& d; T2 U/ D8 p9 P* c6 m4 s
' Workaround: collect and open all components individually% F, c2 U7 P) ]; g# j0 T% Q
'& H1 }9 J% ^0 c3 f. \' ~
Module NXJournal
# s: ^! M  n) J* o    Dim theSession As Session = Session.GetSession(); N. G' y8 q+ @# \6 q1 O' i2 c
    Dim theUFSession As UFSession = UFSession.GetUFSession()" o- e1 v0 P1 ?8 V
    Dim dispPart As Part = theSession.Parts.Display
6 `% q! z$ G3 h4 x  I! j" \% w. z1 \8 `( p- ]
    Sub DoIt()
4 H% N& N" {: A: b5 H) q        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)+ {5 t9 w8 y! O: R8 r
        Echo("Number of Components: " & allComps.Length.ToString)6 L+ v$ w+ O  \1 Z& s0 `) {: @
        For ii As Integer = 0 To allComps.Length - 1' a2 i0 W5 v* I0 ?
            Echo(allComps(ii).DisplayName)
; z0 w' r6 J) s        Next
2 J+ Q! r8 j+ r; @$ k! w6 v/ w
9 p1 ]4 Y, [' B, j' n        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading( l; j6 v& L# ^# K6 z5 I9 w( I
        theSession.Parts.LoadOptions.UsePartialLoading = False/ W$ W& @, C' m3 y

" F, K& F: _6 Q" i! D: H        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus4 C$ M. i! j/ s1 o( X! V
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing- |1 A3 ]0 A, g/ Z2 R% O. Q: \
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
1 P5 i( D8 {& `3 }; U            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)2 j' n5 S7 Q5 K2 I! o

( x( d- B( [/ n6 @7 g  B        reportPartLoadStatus(partLoadStatus1)
" H0 L) T7 @% G9 d9 g4 ]3 X" q        partLoadStatus1.Dispose()  }4 E* f" ~: @: e# G! y1 Q

+ Q+ C% L$ v4 \9 |* b        theSession.Parts.LoadOptions.UsePartialLoading = option1
4 q  `1 ~- [4 y. J: v
$ `# I7 V& |# n* b& t# X    End Sub
5 e: N7 ^5 U) W3 d$ O) m" r: j% t4 k2 S9 k
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
6 k* s! p8 i$ R$ z6 c8 v        Dim theChildren As Collections.ArrayList = New Collections.ArrayList$ @( {! I2 O& i4 s# K( p6 l
        Dim aChildTag As Tag = Tag.Null
4 S( }3 q. H' t" L, V
* |" s1 ]  i: f        Do
# B1 ]: _3 H( O            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
1 V# {, j+ g! u/ C            If (aChildTag = Tag.Null) Then Exit Do, J) s- {) K% H7 e% I3 w5 [9 C, A
. d0 P! f0 K$ r& V% {, ^
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)( m' ]& M  b# y, y: Q+ X
            theChildren.Add(aChild)0 H# U% \% b$ s; R& K
        Loop
* `/ t! g* T2 u  e) a        Return theChildren.ToArray(GetType(Assemblies.Component))8 }1 u0 w  P! F7 I$ W/ i

, X; E8 R2 Z0 }6 W5 B" T    End Function1 Q& i8 `1 q7 |( `" l0 V0 r, {* a

5 a" o3 k- d+ h9 A5 k) B5 g0 G8 ?3 e    Public Sub Main(ByVal args As String())
  m  ^0 Y2 S, Q/ Y        If dispPart IsNot Nothing Then
! A; @6 T& u" U. U* o7 l! @            DoIt()
/ \% m9 s1 d, K5 a) D! I7 f8 R/ Z            Return/ F+ n( e: U$ L; b  p$ G
        End If) m0 ~+ ^+ _$ s  S3 {1 d

8 V  C8 q4 N# l  o    End Sub! t1 F$ @+ [* c1 Y) u
1 X2 @% y1 {4 G9 @* s
    Sub Echo(ByVal output As String)
0 E/ A) |+ X: F, _        theSession.ListingWindow.Open()
1 K  l( ?) v/ M. _5 D& K& S/ S$ {        theSession.ListingWindow.WriteLine(output)
; a! G) L5 O; X: n$ L        theSession.LogFile.WriteLine(output)
5 ^" f% N* t2 w( Q1 T! j7 |9 u    End Sub
0 z7 w, x0 X* z% P! l
4 s, h6 q2 X) f5 o' C0 C    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)( e+ V6 |: c4 a$ X; X, A9 X7 Q
        If load_status.NumberUnloadedParts = 0 Then
# d( [' U- I1 I+ }% v            Return  O9 X+ r8 u/ s; N: H
        End If
2 Y; n3 e+ O- z/ o5 S8 O" U% F+ Z
, e0 L" x0 X. E8 m7 K5 B        Echo("  Load notes:")
) e9 i6 x4 j; T# h# F8 J, _( W
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
! `) _; G0 F/ V* b: a6 b            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))1 {/ G- I( r  J
        Next& T* u& `! W/ d& E& N  l3 `
    End Sub
$ e' I1 H4 r: m- m& c3 @, q' \5 m& N$ l
    Public Function GetUnloadOption(ByVal arg As String) As Integer
- u/ o! W. ?* B+ ]        Return Session.LibraryUnloadOption.Immediately
# h( O1 f, R' X! ]    End Function% d$ l' M0 H6 P+ v2 B
% z  h$ @2 _+ Q
End Module[/mw_shl_code]2 I5 s$ _) x! G: S$ P$ 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二次开发专题模块培训报名开始啦

    我知道了