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

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

[复制链接]

2019-4-12 09:06:31 2477 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' b7 v/ o1 b& U2 }8 ?
Imports NXOpen( z) |' ~! E1 z/ }  m0 `& W
Imports NXOpen.UF( S! E3 T2 k' E, Y/ W
Imports NXOpen.Utilities7 ~. w4 |0 y' S( e' k
'
, F' r6 T$ b: u+ b- M' The OpenComponents() parameter
2 K  S3 S2 K; \& R: e' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly& i5 l4 S# T& \8 X9 y, E# N4 f
' only opens unloaded components fully (see also PR-8406345)2 r( S0 I% q# f1 [1 [+ X  U, |
' Workaround: collect and open all components individually
1 C1 p2 t" W& y, A6 `, E; Q'- h* M( S+ c6 x  A. l
Module NXJournal& x$ j7 i' a1 S& u1 S
    Dim theSession As Session = Session.GetSession(): J6 c7 w3 `: z2 x4 X# ]8 w) A; i
    Dim theUFSession As UFSession = UFSession.GetUFSession(): e# k2 l' L# B
    Dim dispPart As Part = theSession.Parts.Display# T- u- r! d9 O+ ?! F1 s
- x: A& ?( W9 n7 R& r& L- F" Z' ?
    Sub DoIt()% y# M& [  y. k$ h! p9 k
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
; U9 U: z" O# u, V% l, H6 v        Echo("Number of Components: " & allComps.Length.ToString)/ c/ \3 q8 N) x/ C
        For ii As Integer = 0 To allComps.Length - 1
7 P7 a+ o8 M9 P. D            Echo(allComps(ii).DisplayName)
, e% T/ M5 I: I2 ?% q$ K        Next
, q$ c9 [. B4 K0 L
  B/ X2 K/ L- }) z8 }( n        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
0 }2 e% a. e& _- b; u3 b4 c% ^        theSession.Parts.LoadOptions.UsePartialLoading = False1 [0 G( a6 V% D; A7 K+ b

" F+ P3 S7 L# t/ m0 D( k        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus0 r+ B0 ?+ H4 M1 J* X0 D
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
/ @$ W# \. m3 u1 J6 K- h8 Z# U        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(' g- i# C! m" @( n) m0 K
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)) x  K  m8 u+ F: o

  \7 e( Z' k: C# y7 M2 t2 q        reportPartLoadStatus(partLoadStatus1)
& T3 g* l( v. t, P        partLoadStatus1.Dispose()9 P3 b7 w% n- m* R4 u5 E
7 S% S1 s0 d$ h- t$ n7 h- p
        theSession.Parts.LoadOptions.UsePartialLoading = option1
, P: N. K$ }. [% Q5 P, a) R1 R/ R' ^5 \
    End Sub
' Y, ^( N7 O2 W% N. ?1 X4 [+ v5 e
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()8 d) [* U, X* B/ d/ W) m( A
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList  c; l* F* b2 o; P& q  T+ i
        Dim aChildTag As Tag = Tag.Null
0 R9 q1 d# A: P- m1 _) O& y. E) V
, w: H1 f: Z/ \" B# W' `' X        Do
/ r: ~: V/ r4 x- n  M, A+ S            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
& r9 A* K( z! o            If (aChildTag = Tag.Null) Then Exit Do: v  T- j# t9 \3 i& J/ c; ^8 i
* X2 j, w- x; P3 {
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
& {" Y' S5 J3 c5 b$ ?, R            theChildren.Add(aChild)
) j! I0 B+ B2 H        Loop
' ?, z2 q+ f% g. X3 E3 F4 ?$ @        Return theChildren.ToArray(GetType(Assemblies.Component))
" z) _: O6 {; y0 c9 Z' F0 Z8 D! n  P  g6 y& W& j3 [6 B
    End Function( C) M! D2 @+ \  f' W/ l0 h: U2 O
( h$ X/ P1 _- T
    Public Sub Main(ByVal args As String())+ W' {+ r, T) A  w$ U
        If dispPart IsNot Nothing Then
4 g" q+ T2 P3 k* M2 K* v2 u  W: k            DoIt()
! b* H" {0 W& ^+ W$ {1 M1 [0 l            Return+ r: Y: g; @9 u' X! I9 T
        End If5 h3 @- a' w# ]( u( A. K7 }+ G) @

( F! U/ c" y9 n1 s    End Sub
3 L% R8 H3 u! K% D
( y5 W5 J/ o0 I4 c9 p% E    Sub Echo(ByVal output As String), P5 q7 _* j. M. n. U! T" a
        theSession.ListingWindow.Open()
2 Q. p& j9 o. F3 B5 L; c        theSession.ListingWindow.WriteLine(output)
+ u% D  T! y) q0 y; N) E3 ?/ D- ]        theSession.LogFile.WriteLine(output)" |3 U2 b$ L% V1 S+ \. c: _
    End Sub
5 M3 t# P$ Q! G1 P$ E3 q
1 m0 U+ Q7 [  `7 a% S  k    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
2 g% n7 F9 Q! B        If load_status.NumberUnloadedParts = 0 Then
1 ]1 x. V% T1 a6 T7 v8 f            Return
4 P; _2 X3 a8 M6 d! K7 G        End If/ K# M9 [9 R: Q
: `1 s$ A) y$ O+ a; C
        Echo("  Load notes:")
% K( r0 Y! `* }( K" @. \/ e8 L1 p0 G/ w3 n8 f2 e; c
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1. B, d1 t* [8 X: X: Y" A; [6 o+ v7 j
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
, z+ u) q+ T; A! x        Next1 B8 w$ H0 f/ P* V. v: Z
    End Sub8 q7 W; Z6 ^! y( a) l, \9 G5 v
! r. F6 _! ~" B  z6 q( e" ]
    Public Function GetUnloadOption(ByVal arg As String) As Integer; j& o% I2 u1 i0 D2 ]" E
        Return Session.LibraryUnloadOption.Immediately
/ x# |1 L' ^) E+ S9 i  y5 A7 K. n! ~    End Function3 U! a. C5 q1 m$ a3 \  w

! Y' Q/ I3 j/ e; g" a: Q5 r5 p; FEnd Module[/mw_shl_code]) m( b0 T+ a! ~3 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二次开发专题模块培训报名开始啦

    我知道了