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

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

[复制链接]

2019-4-12 09:06:31 2393 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
3 r2 h$ h( r2 v7 r7 ]# Y* v0 x9 RImports NXOpen
, O' L! L( }0 |Imports NXOpen.UF
4 ~( k* v( y2 O4 u; }8 M- l1 {4 AImports NXOpen.Utilities
- M. _7 m+ b9 O4 Y'
& q' u: u# w+ J% L  [' The OpenComponents() parameter
- u* ^4 v! Y/ p+ O9 E/ G- s' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
9 l7 L- R' |8 g4 k( b3 l8 J' only opens unloaded components fully (see also PR-8406345)
5 n- g. j( H: S  Q  @' Workaround: collect and open all components individually
$ ]) _, Q" z0 u+ y  D% X" C% I8 T. J'
6 C1 u2 Q8 q2 q6 y9 YModule NXJournal
5 i- l3 y) ]* R  P    Dim theSession As Session = Session.GetSession()
& a* ~# Y' z# ~# S2 E  D: A: j, @    Dim theUFSession As UFSession = UFSession.GetUFSession()3 e% T% Y6 C' U3 H. r- Q4 N
    Dim dispPart As Part = theSession.Parts.Display
/ Q' y: I& y) _) e0 v! [- H1 ]' |5 w/ ?! m% ~! _; A
    Sub DoIt()  B. e1 F5 }& r; F& W5 |
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
; B6 M4 g( s* R3 S8 }        Echo("Number of Components: " & allComps.Length.ToString), u1 W9 _: @' A0 u4 N
        For ii As Integer = 0 To allComps.Length - 1
, \' B& M# Q# g' Y3 U4 v0 b, q" |            Echo(allComps(ii).DisplayName)
+ H; q" G4 F  I) F5 Y& @        Next: q) e+ Z* K* m& o1 V+ i
3 [. R5 Q$ e, F; f# U6 r& r( D4 g
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading. g6 O3 P7 N# {2 `
        theSession.Parts.LoadOptions.UsePartialLoading = False
( N+ L, a! T8 C$ F5 s: {. i& F4 S  H( B6 N  z2 k
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus6 l, e6 h. T* a) a2 i
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
0 V# X' {' z/ h! L8 u3 }7 p- @        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
7 H& x+ X3 i3 W2 T5 w* G            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
9 j2 }3 p/ q; d$ @4 u) X) Y6 }/ D  a# T" K* _
        reportPartLoadStatus(partLoadStatus1)) Z) _( U8 _( t5 }. j0 K
        partLoadStatus1.Dispose()
- o$ n; A! z& W/ y1 K/ n2 A# N( G
4 O* d* B1 T7 f1 ]( Z! V/ J        theSession.Parts.LoadOptions.UsePartialLoading = option1
8 |9 [0 p" N6 f$ U2 ]/ J& R
: q- d. S5 v! b. L7 d' w  `! z% C    End Sub% C1 q7 T* S: Z

5 g- ~) }% C9 T    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(). P$ q* g4 s7 e) N
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList9 c$ c6 s% F7 S# t1 ?
        Dim aChildTag As Tag = Tag.Null  r; ]/ E9 g: T- D
! a9 H, T8 H8 H* T
        Do2 @8 u/ F" V6 D% ]0 C% Z1 I& x
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
* L. ?- D' l0 j. }1 S            If (aChildTag = Tag.Null) Then Exit Do( Z6 y2 ?: \' S; S( u/ f

9 J* B9 a. Z* a6 W& X$ l8 @            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)& I9 `9 p5 L, H
            theChildren.Add(aChild)
9 p& n. i$ W& u& y2 G        Loop
" c  H8 E- V, v! c, {7 R& O        Return theChildren.ToArray(GetType(Assemblies.Component))2 Z# z1 V# Y, z# f0 j/ |# Q

* c% d0 s3 h% `& A    End Function
; m1 p6 P% o5 C* e( p
; P, u; m& Y, `5 M    Public Sub Main(ByVal args As String())* u) @5 c& h; P' a- Z8 ^
        If dispPart IsNot Nothing Then" _. e% A+ {6 [" ?, I
            DoIt()
; b- S6 ~, l& i3 _! V. L% T            Return
) l: E' {( j! ^6 P% Y0 x        End If
4 ]6 K1 s3 h" y/ x
4 M9 s( y  x. x! F% R1 Z8 {/ I1 Q7 a    End Sub# \2 E! U* m3 E3 S0 P# N6 ~

" S* _" \7 }- Q- H    Sub Echo(ByVal output As String)
  `& \9 O1 l/ g3 ?( g$ p        theSession.ListingWindow.Open(), Z, P$ |; Z( _9 j
        theSession.ListingWindow.WriteLine(output)/ C7 M3 ]' c7 o' e8 E9 [1 O7 B6 c
        theSession.LogFile.WriteLine(output)
% q0 r8 t0 J9 d) @    End Sub
# {/ W; `( Y( [4 s( z) ?( J* V
  s% r0 y% C# }) k+ R    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)) I0 J& S  V) y: ~% c, Y3 L
        If load_status.NumberUnloadedParts = 0 Then5 i4 l8 `8 _' V4 |- _
            Return/ _; r+ J7 l1 C  v# _4 I5 Y' t% u
        End If0 l  U: e0 B% N$ b# [4 R
8 r3 d! C9 S. B+ E3 H1 J6 m8 _- D, |
        Echo("  Load notes:")1 k3 t7 o+ e0 s( `: E
$ D. Z2 K/ T* `) `8 N
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
. y* Z8 n3 ]( ~# j! Z            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))* M3 |  j% l6 w
        Next7 L) v" r0 D/ ]& ^+ V  ^% r$ Q
    End Sub
( a5 G2 V+ ]/ }4 G. N' s* z! ?4 W5 G0 z! A- m8 F! E5 w
    Public Function GetUnloadOption(ByVal arg As String) As Integer) A% y  {# j$ w/ P
        Return Session.LibraryUnloadOption.Immediately
* g$ [! o! E! H' b/ j# n    End Function( R9 F" C5 z. I: r6 H  _' ~
5 L1 w% p' M4 i/ @5 `
End Module[/mw_shl_code]
8 q, |7 t  c' R' a$ P9 A7 _& [
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了