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

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

[复制链接]

2019-4-12 09:06:31 2499 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' i1 L2 }6 K6 d9 l/ k
Imports NXOpen1 D8 M+ L2 C2 r. w: X- Y
Imports NXOpen.UF) L/ |8 I" k5 M' W- ?5 L7 ^
Imports NXOpen.Utilities+ L9 @, i6 e0 D8 S
'
$ q9 S- d7 M! f' The OpenComponents() parameter
/ x! |4 ]: \, [2 P' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly2 j! l; _) H8 ?% @" y
' only opens unloaded components fully (see also PR-8406345)) l/ K$ k0 C; c5 j6 d
' Workaround: collect and open all components individually, ]. _* M# C5 I7 w
'
6 h  @" P0 e2 N5 u* h+ u2 U$ E0 ?" N7 LModule NXJournal
; z- z7 M' A, ~1 ^: J* y    Dim theSession As Session = Session.GetSession()' X- B/ o- }) q1 F
    Dim theUFSession As UFSession = UFSession.GetUFSession()
' o/ D  Q, C7 O" W" z# {    Dim dispPart As Part = theSession.Parts.Display* N- B. a+ [; D7 A: \2 |
* l  z# Y* H" w6 W
    Sub DoIt()
9 w1 Y: z+ L/ ]* }0 y* |. ?8 B2 C        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)$ @, _# [5 G5 E8 V% e
        Echo("Number of Components: " & allComps.Length.ToString)5 b$ g9 h& p/ h6 M+ @8 S
        For ii As Integer = 0 To allComps.Length - 1; r9 u+ C4 W) [1 f$ @5 z% Z
            Echo(allComps(ii).DisplayName)1 ~0 T$ [: a# k( h( F. R5 ?
        Next$ g& M8 e" ^  b6 \# [  a. _

: _- W! u7 z3 ^6 V        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
" l0 a, S8 y; M6 n        theSession.Parts.LoadOptions.UsePartialLoading = False) U4 f7 j; I, a$ ]8 }
! V5 q6 f" W# y) a7 \; M, X5 i
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
2 U% v, ?- `6 l/ k1 Z9 `        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing: `9 }  ^3 P# i% \3 \# M. I7 _
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
) l2 i+ K$ G; y# c" E            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)/ D) X" y( v/ |
% }0 k/ @& G9 i. h! x7 w
        reportPartLoadStatus(partLoadStatus1)" X- v! C. m* H) J( B2 o+ y
        partLoadStatus1.Dispose()
6 k6 c8 G7 H6 z; A" v
+ U% T( p1 J& a+ k& ^        theSession.Parts.LoadOptions.UsePartialLoading = option1
6 T' F. p* A! f2 w  n6 ]4 x
- U, h3 }( E. p9 K3 T/ h' J/ z    End Sub
: n- D' l) T% u9 W, V
% q3 ^( r' c; V2 ^- s    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
- [3 e& g* e. }( e  Z        Dim theChildren As Collections.ArrayList = New Collections.ArrayList. T6 b: k' J4 O9 y1 T7 Y3 {* p
        Dim aChildTag As Tag = Tag.Null& n9 @, N& C4 q" t: B
( h* i/ u* ]2 |  g
        Do
1 X& }- R5 ?0 |  ~# b% Y            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
- G- o6 ?' c; D# F            If (aChildTag = Tag.Null) Then Exit Do. i+ r8 M# J+ {, U: V

; j% K5 p" g  A9 N( l/ u            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
8 E, E' i" J8 Y) s" F. h            theChildren.Add(aChild)- d! _: S# u  Y+ s: U
        Loop
  Z4 s9 [& E& K$ L8 P' i8 m        Return theChildren.ToArray(GetType(Assemblies.Component))" P, \% w1 ?9 ?, K) D/ U

) {/ t" n& E+ }& h3 @2 o# o7 u: o9 X    End Function
! w2 L! t0 U8 [7 y  k& b$ t5 Y3 D! P. V7 y
    Public Sub Main(ByVal args As String())& J$ B$ o) c6 A) O, E- j
        If dispPart IsNot Nothing Then4 g8 @1 o  i1 F2 D) B5 [/ T
            DoIt()
% M( c# I8 t6 W( R1 G            Return( d/ _- [5 J( ^3 o' U& @; }
        End If
$ h" E! h! T5 z  f" J! J* q
2 F" W+ w# ~- A    End Sub, L& i$ p8 ]3 l/ d$ P
0 q% \) Y1 ]2 h& ?7 Y/ I- R5 Z3 V+ a
    Sub Echo(ByVal output As String)
' v3 Z/ S. D0 m+ }        theSession.ListingWindow.Open()& M" c6 _9 S* z! c2 ~
        theSession.ListingWindow.WriteLine(output)- [7 S- D" K2 u% E# \4 m% D" H
        theSession.LogFile.WriteLine(output)# o. _; F4 N$ `! X9 i& ?
    End Sub6 M: b8 \. z) }( F- j* ~

2 }, D/ O0 Y6 G2 r3 t: o+ ~# c    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
+ s9 L$ k. n- w. T7 I        If load_status.NumberUnloadedParts = 0 Then
6 J7 [0 z! ^9 Z* u5 a- v            Return, K. V+ n) E: `) r& d4 [2 e
        End If! r2 O/ J# ?: j. s- \
0 \8 F9 r, k# x. c, n2 s
        Echo("  Load notes:")- [9 Z7 `9 k7 h: A& s/ {! K2 Y
+ k9 c% Y7 a4 k- L
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
* C# {3 y3 H) \( _6 x% C6 F            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))/ N" ?7 S# \; _. ^
        Next
+ ~; z# k' p/ [9 W5 ^4 D4 t1 q    End Sub
3 f6 N0 m4 s( y- G7 n2 n& ~' V2 Q
' h& y, E  d3 n* E    Public Function GetUnloadOption(ByVal arg As String) As Integer5 o: L, y* F7 _& C
        Return Session.LibraryUnloadOption.Immediately& H" q9 X. T" C  s9 V
    End Function; a1 Q& r! f) _, Q4 I+ C

9 X. i: ^0 r& E7 N: g2 ~5 `/ Q* m& WEnd Module[/mw_shl_code]
/ M0 \! q/ x+ f5 V7 M. l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了