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

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

[复制链接]

2019-4-12 09:06:31 2497 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
. T% i* U; V& s8 jImports NXOpen! v( T' n7 c8 p
Imports NXOpen.UF$ A0 j  a0 }$ R9 h
Imports NXOpen.Utilities
* G: N7 V4 f9 E; q/ G'& I0 l: ~0 I& Z$ d: B" ]
' The OpenComponents() parameter" A3 N" s- O8 I) v$ T  n6 |
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
" T/ Q, e0 A1 O. \9 ^' only opens unloaded components fully (see also PR-8406345)" V5 I+ H5 N* b- q6 H  ^
' Workaround: collect and open all components individually
+ V1 y) g* a4 Z: U5 G& l'- m! h& _) ?" f9 O% u
Module NXJournal
. z2 W$ K, x0 n, y. U+ O( k' {    Dim theSession As Session = Session.GetSession()& r0 k: I" o' c
    Dim theUFSession As UFSession = UFSession.GetUFSession()9 I0 ^3 [& F/ F$ I, ~# q
    Dim dispPart As Part = theSession.Parts.Display4 Y2 S' ]: A6 {/ Y( h
6 _& U. J) ~5 W- G' G
    Sub DoIt()
1 K# N+ d# R; J        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
7 U, ~- W& Q7 ?( D% B        Echo("Number of Components: " & allComps.Length.ToString)
& D' p$ E3 O7 W6 j        For ii As Integer = 0 To allComps.Length - 1
# V4 F" Y/ s7 o6 }9 [- q; \5 G  O8 S            Echo(allComps(ii).DisplayName); K& E4 M0 Z' _) t" T/ Z1 @
        Next/ c& {1 i( ]; p# @

# ~- U& l/ ?6 w* I0 h0 s4 X' a        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
3 g3 [6 i# m" P5 x9 q+ `        theSession.Parts.LoadOptions.UsePartialLoading = False" z$ c8 D* p; U/ T
$ w8 r8 M3 v( g, ^7 T5 d& |) O
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus7 E3 x) W! e  \  O+ [' W7 n
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing. B: |1 G' e6 f2 g
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(9 g* p1 D/ D8 I( s, R
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)  B6 U& _* e7 H; q. f

( d& H& W( E8 z2 b  d3 t        reportPartLoadStatus(partLoadStatus1)
- b5 \0 _- [1 ?$ p        partLoadStatus1.Dispose()* x6 K* k! V4 U3 g' q0 e: R: h& ^2 a0 k

( |8 ]% F6 }6 u8 S( M7 T" o, t        theSession.Parts.LoadOptions.UsePartialLoading = option1" P- e7 n2 a! c: h
" e) ~0 U8 }) }0 H0 b1 ~, A6 x
    End Sub/ I2 |* B* _2 m

% v# b( |6 V$ l7 {    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
1 i$ q6 p9 ^2 J* P9 }8 w$ I3 ?' B        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
0 K: b( Z& A/ B6 P        Dim aChildTag As Tag = Tag.Null1 c6 K2 a0 ^  c2 ?# W: z

4 m! b( h- T7 I5 V% |9 S        Do  [/ {! O  I/ m8 o3 {
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
* j" H" [, x# n, ?) q            If (aChildTag = Tag.Null) Then Exit Do
- s& P( d7 ^" I
. z  s4 O0 `. y- b1 o) U  [            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
+ f$ b8 J5 X3 ?1 w$ V( @3 L            theChildren.Add(aChild)( S9 g; r3 V  ~" W) i  x- \- K
        Loop" J* Z7 O9 c1 [9 ]$ B, p' P. ?/ B
        Return theChildren.ToArray(GetType(Assemblies.Component))9 b3 S: k) t3 n- [) \
, C1 |: k) R% e# r5 d
    End Function
+ d: [* T  s0 c. r5 E: b1 g& g. k2 v3 g+ m0 L
    Public Sub Main(ByVal args As String())$ j% ?3 N2 k. T: q2 V, l
        If dispPart IsNot Nothing Then
' T  C/ L, W) H$ g            DoIt()2 k9 C, [5 }. |) ~3 T2 Z
            Return9 M! k4 D" U; I2 F9 o) Z! s
        End If1 R" d+ `. T+ `4 n8 H

  z# q' J7 T3 ^% E6 Z7 g* [) v  k    End Sub
. _  r( H$ V( k) W& |! y6 j' X8 S; M; M4 ]/ ?7 u* K9 n, e( P8 E
    Sub Echo(ByVal output As String)
# l1 L# [2 O# c0 c6 H9 v- E# Z        theSession.ListingWindow.Open()
! e8 m# ^9 v9 X  q: v) N        theSession.ListingWindow.WriteLine(output)
* i1 e* p. u2 G, m% _% J        theSession.LogFile.WriteLine(output)
  y+ C  I, f; l9 E4 m/ C3 h4 f: o    End Sub/ c& m6 y1 Q8 U3 [

9 Z7 r4 Y6 o' e0 o    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)' @5 z8 a: I- B  x* F: u# {! q
        If load_status.NumberUnloadedParts = 0 Then
' z8 f+ i1 T( V* m1 W' w- I9 V            Return
7 U, T: s' ?6 t( }0 r        End If
4 v+ Y! L# p3 O* O, B* P+ r2 G
1 k1 V: Q$ `" Q, C' N" U, n  ~        Echo("  Load notes:")
2 y; w4 B+ S6 d5 _7 Y5 b
0 D9 w+ `3 O) }( _        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
- a1 a3 s* O; R) M; I; `            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))+ M- N# j+ F9 Q3 q0 g
        Next
. J0 c: [9 d) }) A: H8 S    End Sub
* _: P# h* l7 t2 n  k6 v& M3 S
# B) B2 t% ]$ ]7 n/ {- T! C    Public Function GetUnloadOption(ByVal arg As String) As Integer
! r' x/ A9 c; o7 q$ U6 r1 ]* n( ?        Return Session.LibraryUnloadOption.Immediately. Q1 P4 ~4 e" d& Q: p1 G1 Y
    End Function
) g. _0 X9 K2 M5 r8 L; V
4 V: A. T6 H2 KEnd Module[/mw_shl_code]. o+ Q5 b. g  k) |+ X% S& S9 `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了