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

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

[复制链接]

2019-4-12 09:06:31 2489 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. E  E% t4 j' L0 s+ B3 f  ^
Imports NXOpen) _8 K  n3 ?$ i7 D
Imports NXOpen.UF
& u( B+ Q% @' V+ dImports NXOpen.Utilities
1 [5 N2 |& y8 J; E'1 n! O" \! F% N4 L  a
' The OpenComponents() parameter
: [! X0 v. }' H/ L6 r1 @5 X' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
0 q: s) Q3 s8 d' A: W9 ]: m" g, m& H' only opens unloaded components fully (see also PR-8406345)7 s3 E$ g5 h: {
' Workaround: collect and open all components individually
2 c* s/ F3 Q7 n  h* f* t5 I'
. z2 Y" I* {4 O8 H; H* JModule NXJournal
  f$ g; _( V# R2 Q. @$ r6 S    Dim theSession As Session = Session.GetSession()! z) N; K6 O- ?& C/ H
    Dim theUFSession As UFSession = UFSession.GetUFSession()
# p( h0 P4 H8 P# j, I  ~1 O    Dim dispPart As Part = theSession.Parts.Display
+ s  {4 I: w! @3 ?* s  J- z% V1 f
    Sub DoIt()
# Q& T4 y$ J& T1 B  A$ s" w8 d) B8 A/ S- i        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)- F/ H& O! Z/ S4 @
        Echo("Number of Components: " & allComps.Length.ToString)
5 g) u6 J2 l/ T  ~2 s3 a' ?        For ii As Integer = 0 To allComps.Length - 1& d7 m6 b6 M" ~; q* ]% l6 R- T! c
            Echo(allComps(ii).DisplayName)( V) V5 c/ t5 F/ ^! i* H9 g/ j
        Next
0 C. Y  V; i1 b- R8 G/ u% C- }; z# S: _0 y' \8 w1 Q
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
6 Z6 V1 c) r' r: G        theSession.Parts.LoadOptions.UsePartialLoading = False/ [  X! b' I; I$ I) w
6 ]  M9 q& X; G7 I
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
/ ]* {# p$ Z4 X, R        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing3 V' Y1 F4 E) f, ~* ^8 ^8 A
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(" C$ c4 l& d# m' y% [& T" T
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
( E5 }! J& k5 ?; w$ l) v
/ n  g& B2 |1 G- M. m. B5 b4 a) m        reportPartLoadStatus(partLoadStatus1)
  |7 E6 R/ }( r- n. X. L+ c" v  ^        partLoadStatus1.Dispose()6 \% U2 G! Z9 }/ X" M: }3 e

& e  E8 |& O3 H7 U7 k7 d! [% v        theSession.Parts.LoadOptions.UsePartialLoading = option1, C/ e/ p- G' O, X8 V- v1 I
# s& d& V( B9 Q7 Z# o5 q
    End Sub0 D, X* Y' ~* q- a3 j
  R& V+ I8 b6 N3 c- |
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()% e; c$ X1 e# k% ~; V4 q3 ^
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
; L- p5 @- ?6 j4 H2 m4 Q) W        Dim aChildTag As Tag = Tag.Null: o6 I9 q# @. ^, u
* B; {3 B6 [2 u1 A8 ~
        Do! H9 l) W( c6 h; H7 F
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
) P# L! W, M7 ?* S' S" W* v            If (aChildTag = Tag.Null) Then Exit Do
5 U9 H- {$ [; C! D3 V) p6 X# t, ]7 h# L) S9 |% c
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
' ?' q2 k; i$ X) o' D. {( N            theChildren.Add(aChild)
; o/ \8 H1 h+ \* o: I        Loop" o5 ~4 C$ h& `
        Return theChildren.ToArray(GetType(Assemblies.Component))
4 ?$ o; d4 s' c/ r' d  g; ^$ J; |5 \# k0 J- r$ N- t% R8 r3 K3 R1 S
    End Function
- b/ Y& u) ?1 V  a% q7 ~, @5 L4 \6 i( w; ~
    Public Sub Main(ByVal args As String())# X- l0 `- B, b: a' f
        If dispPart IsNot Nothing Then
0 j7 s& U) N$ s; {  G0 B            DoIt()
' L: ~/ \4 x7 D$ c3 {- A: G6 u            Return
. a% w$ }3 P4 J& U, G# ~        End If
5 `  P; t/ p  B; ^# H& F4 ~) p$ h; u# n( L, q( P
    End Sub/ Z( P  W" ^  k  J6 k* R

/ O* ^$ H2 Z, V- r$ a: c# ]/ R    Sub Echo(ByVal output As String)
. Q( ?8 ]- B" B' I* w. \        theSession.ListingWindow.Open()) [" J8 e& V- ~" }( U" s
        theSession.ListingWindow.WriteLine(output)
( {! e, O% @( {5 ~+ q. B/ u) o        theSession.LogFile.WriteLine(output)7 M' N1 K1 K% x0 W1 c2 K' u
    End Sub7 W- S7 Y. L7 y( v( |5 I

, g! X5 b  n& s# e3 L! l( H    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
0 @* c. i9 b( u$ u6 C* E% H- R: }) \        If load_status.NumberUnloadedParts = 0 Then& [# y7 f1 o) H& `9 G
            Return
% f* {) [) C' W7 s+ x: D; {        End If
+ n2 Q" C" V! E, [+ }  o
" Z4 `7 J* s( q4 N        Echo("  Load notes:")6 B$ u! ~. m1 n9 k+ m) c/ r

+ ~# n8 l# E( |6 r, n, ]6 r7 @        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
5 n- Y* J( Q" T$ [2 m9 l' ^            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))5 K6 Z) P% v: a5 {
        Next* H5 X. ^8 ]- }1 ]( D* N1 N/ X
    End Sub% f+ o! ~. e) t" X
. ~( W6 k) X. a, K  [; H
    Public Function GetUnloadOption(ByVal arg As String) As Integer  l$ v/ ]$ g% U" d: t1 Y' O, C4 x1 A
        Return Session.LibraryUnloadOption.Immediately' d, w9 C. @5 l1 r/ k  ]: D5 |
    End Function3 H' O# I' A% \! T) D/ n" d8 }

& [9 a3 d/ G3 Z7 i, XEnd Module[/mw_shl_code]
" ^& {; S: L, }. H6 x. N+ p7 G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了