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

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

[复制链接]

2019-4-12 09:06:31 2404 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 g3 B+ _- @$ ~7 v% A8 U, m
Imports NXOpen/ B( l% F# {/ Z) e# i
Imports NXOpen.UF
& b6 C$ [2 ~) N& Z/ ]Imports NXOpen.Utilities
/ c/ @4 O# C( Z9 c: u'! C" X( v7 P1 v" u
' The OpenComponents() parameter! c& `* ~; a( M0 h/ Z  D9 [9 e. R
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly. t- p* @# F- \# v, Z1 Y* {* t
' only opens unloaded components fully (see also PR-8406345)
, b' M+ D6 d4 }5 q' Workaround: collect and open all components individually
- q5 `! ?* c$ _'
  d+ N1 G: p" T9 }- N/ w1 y9 y* J7 tModule NXJournal
3 w) p" a1 A3 v. _    Dim theSession As Session = Session.GetSession()
" O  c. k9 ?- `- ]- d    Dim theUFSession As UFSession = UFSession.GetUFSession()0 n; U6 ?/ l0 _) Y5 Y
    Dim dispPart As Part = theSession.Parts.Display9 ]8 L+ z0 J) X3 V

, H8 U0 j: ^5 N0 E) ?    Sub DoIt()
% @4 C  J$ c7 F6 O* ]$ Y5 }4 p! G# f! B        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
& h4 x0 h- m; ^7 z3 I: _" ]: r" b        Echo("Number of Components: " & allComps.Length.ToString)
# W: N( a: d) G        For ii As Integer = 0 To allComps.Length - 1
8 H0 U( f, V8 f            Echo(allComps(ii).DisplayName)
4 p( n- b+ A  K9 b        Next; e2 s" K0 l7 y# d2 C! d) H

  n* O3 x+ i) I3 ?2 R        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading/ \& K/ h! l9 Y- \# x  S
        theSession.Parts.LoadOptions.UsePartialLoading = False
4 |! b7 F0 E. K! X: _0 s
: ]) M. g: r& B5 B/ X        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
* K. u8 v  L/ X/ Q( X        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing9 O  i# S& C3 @- a3 H* O1 a; k
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
+ U4 O" R( d, h            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)7 B4 T8 c$ }8 }: v
7 m+ _6 H* a- J" V$ X; l* ]$ L' R
        reportPartLoadStatus(partLoadStatus1)4 T) U/ i4 `- Y; x5 s2 g, s
        partLoadStatus1.Dispose()1 L3 W/ m) V. m! Y
( {$ [* o5 O# O! V% i4 t
        theSession.Parts.LoadOptions.UsePartialLoading = option1
0 M" G4 v; n# ^7 p* y1 q" ]
) O4 h$ X' A  p( I8 F; k% Z    End Sub
% ]  k3 I, h& F" |+ C$ o* E" d7 N6 `6 ~- Q  `# r; H/ z
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
% O* r! U; q' K/ y& f. Y        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
. ~7 j# G: B" c# U7 F: G        Dim aChildTag As Tag = Tag.Null6 `- Z/ H* C( @! F! W$ Q& A: z4 T

0 @* d4 l2 A7 M1 d1 c        Do7 m( s9 O1 m7 c# S7 }- V
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
) @! {8 A% R# A9 g0 G: t            If (aChildTag = Tag.Null) Then Exit Do
) {" r8 X0 j$ p8 z7 W  q, z8 }3 I: k
* h: H) ?$ h. `; K            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag): F% f' y7 s5 N  U
            theChildren.Add(aChild)) v$ P6 W5 l7 R9 O6 l
        Loop
  v, `, h% F& M3 t7 u        Return theChildren.ToArray(GetType(Assemblies.Component))' o6 ~- H2 B4 ~; v: G2 g, A
1 ]6 R% H6 H( u6 a$ j, N7 y
    End Function
5 B& M  V6 P# P
- [) E: F% s1 V: v" J    Public Sub Main(ByVal args As String())' ?4 e; s+ I: V
        If dispPart IsNot Nothing Then" e, P9 n8 I( d4 K9 w/ L; @
            DoIt()
3 t  ~6 Z5 }* Z            Return# r1 _1 m( B4 @4 d/ g5 c" ]  H
        End If% _( n1 o8 E4 \! V% \' c1 i

+ {% e# v! B# f- S% n$ e    End Sub
& x, l& h# R2 p" M! `; a& j& X+ w) \
    Sub Echo(ByVal output As String)+ U& @, l) n/ V" c' Y
        theSession.ListingWindow.Open(): m; N& V* A- @2 ^* m- I1 U
        theSession.ListingWindow.WriteLine(output)# I2 P' T- K$ d2 [' {
        theSession.LogFile.WriteLine(output)2 O- K1 ^+ {% t: }6 x
    End Sub* B8 {9 `( K: [% K: D. _

% s* W9 Y0 T; l! _+ H    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
3 b3 ^2 Q% S9 Z% ?        If load_status.NumberUnloadedParts = 0 Then/ t4 s1 ~- c, ~2 Y
            Return1 ~2 x! _" ~$ N! m3 Y9 r
        End If
- @) M6 [! L7 i# m+ ^' H; Q* q7 t* m. C6 m
        Echo("  Load notes:")" u/ ^$ j) B, _7 k& n- Y

3 p3 u) t  G, P, ?        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
! T, M6 Y! H" ~0 o2 I! _            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
; R. y0 B7 |$ _        Next" P* Y- I( L* E/ Z8 \3 ~4 v7 p
    End Sub& X2 q: g; b: |$ |! C
/ }: l) |% |. U" n2 a- Z, ]
    Public Function GetUnloadOption(ByVal arg As String) As Integer4 O8 A. h3 B9 k; [7 K3 |  d+ I
        Return Session.LibraryUnloadOption.Immediately9 ]: `& Y% a8 d% r1 k0 \
    End Function
+ h# F( Z/ r! e5 D) X: d
* C9 N+ s7 X1 j) @! }End Module[/mw_shl_code]
! I) N& A1 J2 D# z* ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了