PLM之家PLMHome-工业软件践行者

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

[复制链接]

2019-4-12 09:06:31 2369 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
: }. W; f( b8 jImports NXOpen
6 c) V0 g7 U# p6 wImports NXOpen.UF: R0 R5 w: L) D7 h$ W  j$ m4 p
Imports NXOpen.Utilities
9 t1 X$ b& d8 e2 s) x'
5 k' W: ?, _5 g, O' The OpenComponents() parameter
2 O+ N6 G; o6 y, ?0 ^' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly& M: y' e$ s" @
' only opens unloaded components fully (see also PR-8406345)3 S% F+ y% i: r$ Y1 t* z8 f
' Workaround: collect and open all components individually9 a) n* ~* R3 s  ?2 y. {- g
'7 ]  Q  i% a5 V" ?* \# h3 r# i
Module NXJournal& o  i5 K/ ]3 r! P' G% U) p
    Dim theSession As Session = Session.GetSession()
1 A2 d  Q( {) |7 ?9 D    Dim theUFSession As UFSession = UFSession.GetUFSession()( Q9 E/ Q9 s, b0 I) p+ V4 m0 s
    Dim dispPart As Part = theSession.Parts.Display- S( [* R9 D% ~# s/ t' M' [' Y

0 b* R; _4 K2 T: ^# X4 U+ o    Sub DoIt()
7 S" [) A( C' m' V5 L        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
) R, ~0 u, j, Q: S* X        Echo("Number of Components: " & allComps.Length.ToString)
, ^( D1 K* I9 v, J# I% X        For ii As Integer = 0 To allComps.Length - 1
5 Z; q1 T5 w% C            Echo(allComps(ii).DisplayName)3 F. V9 S4 T* |% n" P  j- [
        Next
( {4 [+ z; b9 G5 |5 ]4 b+ L/ |9 z3 n2 I2 c2 f
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
! ^# f0 u/ S: w. G. O% K        theSession.Parts.LoadOptions.UsePartialLoading = False
3 Q0 M/ M  w) C3 W, I; A% {
% Y6 W1 l0 P6 K" O        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus" v: O9 e8 Y) F* P3 R
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing- e# v0 a2 l% @( l6 l
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(( h1 _, G3 d& A- O
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)( K- l: H4 P8 v4 d; m* w/ g* Y% l  L

( o' M5 |8 Q" C7 V1 u$ R- [4 O1 B        reportPartLoadStatus(partLoadStatus1)
- a; x, i5 l6 l8 k; @) Y+ J# s' \        partLoadStatus1.Dispose()3 R; N, ^8 B$ @0 d9 N2 M4 ~

: P" n0 T5 G% ~) x1 Q        theSession.Parts.LoadOptions.UsePartialLoading = option12 G" l6 h) {, A8 I
( B$ l# F  S/ l* C( v
    End Sub
; D* J3 ^* ^& Y# |: w0 S, ~: Q  j# W7 d" {. t  e4 Y* g
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(), I+ Z; Q3 R2 m# I" J( ]" t( d: R& v
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
2 O+ y! H/ _! q        Dim aChildTag As Tag = Tag.Null$ Q: y, h6 ]; N7 U; b) D

7 S1 E+ ]: B9 f        Do
& o. S$ l# X: B8 I# k            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)0 \+ b7 @5 q: N' r* Q
            If (aChildTag = Tag.Null) Then Exit Do' M: ^# r& L2 e$ ~' d( y

6 j8 B; x; m' ^6 ]7 M$ ]! [            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)8 i7 u; @1 M4 `  Q7 O4 ]" `) ^- C
            theChildren.Add(aChild)
" m7 }& O9 g) l1 W" e        Loop
) w8 U; r' \6 M7 Z        Return theChildren.ToArray(GetType(Assemblies.Component))# E! f# i) @' t& h. \' q3 V3 |
0 I0 }/ Q6 J9 D( p/ [
    End Function
' R( u1 P8 M, z/ [0 ]1 ^* l
  b9 X! a1 Z# s. g1 e+ I6 L    Public Sub Main(ByVal args As String())/ ~( v( J: M: [! z9 t% N! L7 B
        If dispPart IsNot Nothing Then
) E1 P& x$ [6 N: G. I, [            DoIt()2 \" t) p5 R% H, I' W
            Return6 Y; @. q% A& Y) l- ~
        End If& G) {: s0 W  e* l

7 x3 L' s5 y1 \; y  l    End Sub
% L) k  g# |2 `' v+ l6 Q" k
8 |" z7 b, J4 t% b    Sub Echo(ByVal output As String)" |3 @+ p' [$ c, i6 E' h: i( k
        theSession.ListingWindow.Open()8 k7 o  I- H1 G6 e  F% K
        theSession.ListingWindow.WriteLine(output): \2 n5 K( {7 ~6 W, p
        theSession.LogFile.WriteLine(output)8 n, X2 Q6 s& |
    End Sub
% C* d  T( |" w& Y% n
6 x/ w( J6 u$ m8 J: M( g$ |    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)" @, X* O  d6 ^' z  G
        If load_status.NumberUnloadedParts = 0 Then
3 ?. y. \3 w6 p1 V            Return
  r  a! U9 B* f& g        End If
* K/ y  s. X  z7 f8 g
& O# k, m5 S* [- o. V! `  a        Echo("  Load notes:")! b" I6 q& e. H5 F# ?( x+ e

) u1 Z* e0 O) F$ z1 m* D1 s        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
$ w6 `) t, V0 J            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
7 k% B2 e5 ~; R' a" O, V        Next5 D, s6 y7 ~6 \: x- q4 C
    End Sub
9 |6 e. Y* S5 T( U, g2 k
& M  `4 M# L% {& [6 j" L$ I    Public Function GetUnloadOption(ByVal arg As String) As Integer
1 r" T% |: k0 e' R0 C& S        Return Session.LibraryUnloadOption.Immediately6 b* [: o) Y, a( j! y
    End Function
' ?5 a7 ]; A1 M
% P2 @7 X7 w1 q' d6 l) MEnd Module[/mw_shl_code]
5 A# V; q4 `9 _4 j( R2 D8 F
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了