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

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

[复制链接]

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

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

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System6 @, r# n( W; S
Imports NXOpen4 {4 R" c: k- _' [- v
Imports NXOpen.UF; N1 c1 R& s5 ^- y
Imports NXOpen.Utilities
* R9 N5 a/ J- p0 i1 _. j1 {0 k% V'
! T) o; r7 E- w0 y$ x, b' The OpenComponents() parameter
5 R/ Y3 S( O+ P& i) C! Y: v' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly/ B' H9 z* X% y! B4 r$ R
' only opens unloaded components fully (see also PR-8406345)
5 U, z" u: l+ y, l8 K' Workaround: collect and open all components individually# n( _" B5 w1 S$ M- _
'
7 c7 d' e) t. C8 i& H6 JModule NXJournal" C. P* {- ?# y2 m& {3 {: m  P
    Dim theSession As Session = Session.GetSession()
! a, }2 F2 x/ x* p    Dim theUFSession As UFSession = UFSession.GetUFSession()
9 z8 x: B/ V) E7 L! ^    Dim dispPart As Part = theSession.Parts.Display
0 j, Y3 S, {8 \; L) v3 ?! s3 L2 j' D6 u9 b# s
    Sub DoIt()
) q: p7 T. r8 Z# e4 _% S        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
3 _# T6 D! y' s) Y) i% m4 J1 [        Echo("Number of Components: " & allComps.Length.ToString)
  n" p) g' t. w) Y7 O: H        For ii As Integer = 0 To allComps.Length - 1
0 [( a( @5 [. H# ]: P* w            Echo(allComps(ii).DisplayName)) I) Z* k/ Q+ o
        Next# V3 W/ J* q) ]2 C3 z
1 e- G% V& ?/ ]' X, r
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading1 K" C0 r3 D5 [: B, r$ s0 L
        theSession.Parts.LoadOptions.UsePartialLoading = False
4 x8 }" P0 ~$ `- ]
% }/ E: [' ^' o! h" J' R* f: {        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus& |2 H2 x  ^" _
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
' C( T; u- ~, D  f/ ^% i2 `2 F        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
8 f! Y9 W' [' a- a  Q  S            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
0 }4 `( e5 I- p7 }; ~) |3 M% {$ W5 n, Z0 k
        reportPartLoadStatus(partLoadStatus1)5 B& O# V- v- O! m/ c
        partLoadStatus1.Dispose()
' A" F' g$ @: v
; V( O, G# `: @- g% p. ]& H        theSession.Parts.LoadOptions.UsePartialLoading = option1
! X& Y7 Y) L, }) ^
7 U1 K- I9 T) p* W' e4 X. `" i    End Sub, B/ ?  n" P5 [7 Q/ I  W) y
8 g: l$ F9 t% ^# t/ A, Y& M
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()# j: c& }: X4 R5 @3 D5 z" x6 A) ~
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
2 y) r8 e& E; j6 z        Dim aChildTag As Tag = Tag.Null
7 I1 f( t* O6 j( }8 ]* T* n
% ~2 O; W0 c1 Z; R2 O- r/ `        Do
/ e# K1 ?- n5 B$ z; m            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag); Y9 s) s3 |6 K2 L( O9 e
            If (aChildTag = Tag.Null) Then Exit Do; z: i2 F" \& m

" t( d: [6 {" t& V/ a1 i. A$ N! p6 A            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)- x8 v& V: d7 n: W" ]5 y0 w
            theChildren.Add(aChild)1 @4 a# P* b9 }' M3 j  m
        Loop
) f' P/ a2 Q# A- H& H! G2 M( V        Return theChildren.ToArray(GetType(Assemblies.Component))
# j! w# w) y8 C+ |8 w  w
- H+ J6 G! S' _6 m8 f! k" z+ X4 v    End Function
6 ^- R% _" ]9 ]4 J+ e$ j4 v; G: U0 [% ~
    Public Sub Main(ByVal args As String())
9 Y- w* J) l8 k* a, G        If dispPart IsNot Nothing Then
$ i8 I* {& c  n( R* N            DoIt()" o  Q1 d6 N5 t+ K% O0 r5 H+ [+ m# y
            Return
! [, V0 g( _, b) q        End If4 ^: Z% M% s' i2 i5 L) H7 E. w, k1 i0 o

; _- O. z( I. _* E4 S' t    End Sub
8 n& S1 V  H. j; a: ~2 A) r- x) f4 q6 a
    Sub Echo(ByVal output As String)
5 N. ]8 D" b3 l; t2 w/ w9 {) P  x$ C        theSession.ListingWindow.Open()
3 G% P  u% D7 W- D+ ?        theSession.ListingWindow.WriteLine(output). h5 O$ h- A  N0 Z# F4 U0 U# K
        theSession.LogFile.WriteLine(output)
/ Q8 ?& i; z6 A9 B/ Z+ z    End Sub" g2 H4 E+ b2 r+ i8 t) j
" g- V4 `6 K$ c9 x4 B0 F' x
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
1 l, d8 s( M! Z9 ?% _7 h        If load_status.NumberUnloadedParts = 0 Then
$ \5 @$ _5 l1 p5 L7 G7 ?            Return3 c- L- g, A* o  C- U
        End If
' `3 N* T& \: U$ L, Z
" R; j4 b7 K& ]& x0 q5 @        Echo("  Load notes:")7 V: @. ?8 N3 |  S3 v
& e" z* N/ }0 q9 C+ F8 O! T0 X! h- q
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 17 t. {3 o% T4 v8 [5 Y! A. o2 D
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
2 B* m# s' v/ Z1 e: N5 E        Next
8 |5 [5 e3 G6 Z* H    End Sub
3 \8 C9 S7 T! l' v) e/ q9 C
0 H$ x! d& u3 F7 y6 g0 S3 \    Public Function GetUnloadOption(ByVal arg As String) As Integer
  o7 q% P) z4 C/ M8 e1 {# C        Return Session.LibraryUnloadOption.Immediately
8 I6 ^+ n1 G  ~0 F  f1 H: i0 F3 M8 q    End Function. U, B- _  F+ F' V

6 V2 Z& |; P' b8 P: O7 yEnd Module[/mw_shl_code]( a3 ?; m2 x7 `8 B: B; `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了