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

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

[复制链接]

2019-4-12 09:06:31 2460 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
' {2 w) e9 E9 L+ tImports NXOpen
$ c, ?) M6 D5 mImports NXOpen.UF6 x  t- `$ y1 [8 X: t
Imports NXOpen.Utilities. h+ ]  j  Y- b5 S6 h' }
'
: I" k6 W2 c2 V" \) S6 e' The OpenComponents() parameter
* @5 K5 O( ?* ?% r' g' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly. E  p+ |( g% o3 m* [' D
' only opens unloaded components fully (see also PR-8406345)+ I% S3 D2 c7 ?( Q! R9 I
' Workaround: collect and open all components individually1 K3 U" Q! j- I' D7 @
'
- t7 y& v6 ^; a5 e. N) m$ }Module NXJournal
3 u5 H2 H' f' v, y2 J    Dim theSession As Session = Session.GetSession()
$ j" z+ K7 j# d. c1 R    Dim theUFSession As UFSession = UFSession.GetUFSession()
& {, E, H' @' b( @6 {! x    Dim dispPart As Part = theSession.Parts.Display5 o9 G, F+ I' v( w
( c; C8 h, X0 Z
    Sub DoIt()8 [4 b  ^7 I, j! S8 O# c
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
0 v/ B% z. p; _3 k        Echo("Number of Components: " & allComps.Length.ToString)
- N, A' {" T; U, Z* I  W$ D5 T9 R        For ii As Integer = 0 To allComps.Length - 1
+ C( _; z, t! M- S            Echo(allComps(ii).DisplayName)
& n4 j3 g; x' ?" Z, m6 v* a7 u+ H        Next
; ^6 o# E. l, _5 ]7 Q
% a" Y, \' ~  ?7 U8 P        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
( k" n& }; J5 ]+ J        theSession.Parts.LoadOptions.UsePartialLoading = False" |: d" R3 _+ k( L5 @% Y" d

6 I0 d% m3 n( W9 [/ i1 d" L        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
- u5 `+ p1 p2 z! y; L2 g        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
) i$ l8 ]. K( j: _        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(5 X$ [# m' q1 l- n
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)1 H$ _4 _+ J7 S: Z, w0 F
% _7 `$ M# {  x# t5 g
        reportPartLoadStatus(partLoadStatus1)' }* h9 P" [" \% M6 K' K, N
        partLoadStatus1.Dispose()
7 R6 \* w+ I/ F8 u$ Z) U$ @
4 R9 a& P) ~" r5 v  R        theSession.Parts.LoadOptions.UsePartialLoading = option1: e: _' M8 p& ~- H! n, R" a
  I3 [. I0 k8 ~7 N4 _  e7 @+ K1 e, G
    End Sub
5 N  F$ |; Y. o0 B7 b$ G4 o3 r5 r) R6 l' b
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
) n, s$ D2 a& {8 ^& `' U: G        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
! X  V! v6 E0 t+ Z2 I' m        Dim aChildTag As Tag = Tag.Null9 ?8 x  t5 E7 R
. f  W& X: Y1 \( h" J2 n- m& M( m
        Do  m9 E/ O$ U/ h5 r3 U, D7 A. {+ _
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag). s' G; s! a& L, f0 t
            If (aChildTag = Tag.Null) Then Exit Do
& W# Q( s- I" b1 D
5 |# J& w, s$ r( K            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
) \8 C% r, }( ?8 {, f5 l            theChildren.Add(aChild)
$ f1 K1 U1 q( w$ f+ n6 G$ |& n$ n# v        Loop
- a3 b. O  }7 ]5 x8 Q        Return theChildren.ToArray(GetType(Assemblies.Component))8 i4 O1 b2 ], t0 I* B9 e/ L# o
9 [) h1 g* a' b
    End Function& ]# H$ j# o* z7 H9 |5 l4 G- @9 o

4 V9 a9 ?3 k6 \) D3 E5 R    Public Sub Main(ByVal args As String())
7 ]5 `3 ~& L- z# G% P1 D1 H+ F        If dispPart IsNot Nothing Then
( _6 G$ H# \. R6 N% x3 j; _3 `            DoIt()5 R# @; {' s; a  Y+ o3 a
            Return
2 I7 g7 Y' D2 x( Z/ M        End If% a2 g2 ~# G/ g3 m
( m8 Y2 r. J+ `; X$ \( w
    End Sub
& p! c) o  }5 Y# z2 ^/ |" D' k# q0 Q
# Y/ M8 f3 \, Q; m$ X- {    Sub Echo(ByVal output As String)
0 |  e; G. D- x" [( [        theSession.ListingWindow.Open()( f3 j) h2 N- J* F" n) Y' q' n+ d
        theSession.ListingWindow.WriteLine(output)2 D& |6 A6 [  w6 C
        theSession.LogFile.WriteLine(output)6 ?, W. Y1 p# v! K( C1 F
    End Sub6 n; a( E2 S' F& _/ b
3 ]5 w' x. i9 d- o- _0 }
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
6 C. t( h1 [  R/ j        If load_status.NumberUnloadedParts = 0 Then
- W8 |" V! t0 W& i; K  k' W            Return
8 Q; h( k1 K. I* z" ^4 v        End If
* ?( d1 N! @" [9 k$ k/ }
* R$ L3 M' E- K; J5 C        Echo("  Load notes:")! t: K2 W' r$ }; u

3 ]. q5 `" l! q        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
9 Q( C  F. N8 h            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))2 G. O5 t0 S3 O2 j5 ^
        Next
5 p, [2 ^3 Z" U- F* Q  p: O    End Sub- \$ X! ?: X% t8 E3 J: V" ]
+ Z: K" }1 W1 i2 Q0 j6 W
    Public Function GetUnloadOption(ByVal arg As String) As Integer3 ~3 T: V/ R' H. j
        Return Session.LibraryUnloadOption.Immediately
  q/ c$ ]3 k# ^  O    End Function
' F9 R2 K& i6 R  a8 u  g* z" n
5 g' Z* [$ U7 w3 aEnd Module[/mw_shl_code]. E: S# ~& Q$ E, g& ?3 r. ~- v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了