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

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

[复制链接]

2019-4-12 09:06:31 2511 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
8 O9 g$ o+ R0 vImports NXOpen
+ o( M7 g6 b9 X4 o* ]" _" ?Imports NXOpen.UF, o8 r: E0 j9 o* j4 {) \
Imports NXOpen.Utilities1 r4 ?! Q  F" U" l: w
'
3 P+ A; T. a2 A" {3 R7 n# I% `' The OpenComponents() parameter
( f8 o( E* n& W) v' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
4 G5 B3 p/ l% b' only opens unloaded components fully (see also PR-8406345)
2 D$ v1 W8 L3 a  V' Workaround: collect and open all components individually
& F4 e' `& f5 A" @( a( f'' S- D7 K& k, G) O. i
Module NXJournal' P5 t6 z  G+ X1 Z, Q: j" v6 X
    Dim theSession As Session = Session.GetSession()2 _! V; N! l# X3 i  V7 e
    Dim theUFSession As UFSession = UFSession.GetUFSession()
9 t. D& c/ |' Q5 ~" }! `    Dim dispPart As Part = theSession.Parts.Display$ I+ n. R2 Y8 K0 ~

- P8 P5 }3 }3 i. A    Sub DoIt()! L' {% z9 D$ L; r0 G
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)# k. I+ w% Z  K: \1 z1 ]
        Echo("Number of Components: " & allComps.Length.ToString)
; Z# m7 F& _& S- B0 @        For ii As Integer = 0 To allComps.Length - 15 R5 o+ h5 j0 X* h- Q3 C1 G8 q5 p
            Echo(allComps(ii).DisplayName)( b# e9 j$ C5 M5 _$ P0 E
        Next: U: {3 G1 c' C# ~* Q& L- W

- u1 s$ |- E' y. }( r. w4 G        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
' @' u& f7 A9 ?* b        theSession.Parts.LoadOptions.UsePartialLoading = False
% @  `- m: _% P1 P* x' _# x( y. f4 H( X
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus3 k; X' [2 h! ?
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
6 c1 [: B9 _& B, W        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(& s" `( ]$ d5 z; l# _& D0 S
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1). N- G2 n" |" \& {7 C; g

( T' B% X" r6 l        reportPartLoadStatus(partLoadStatus1). \9 R! m' Q/ _6 i* o
        partLoadStatus1.Dispose()  ~  u- X1 v3 w8 P4 G5 ^/ J; \
6 w" m' o6 }) }: A7 ~
        theSession.Parts.LoadOptions.UsePartialLoading = option1$ @1 J" W" N  E' S* @
0 ?, r# o4 d$ ?  N; ?! B( b4 k
    End Sub0 p! G4 b. A( i( `- k0 z" z

: C+ T  m3 t: f# `7 W    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()/ P: a+ p+ G( t3 a
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList2 Z7 y3 Z( _3 b. y, l/ J
        Dim aChildTag As Tag = Tag.Null! z7 k9 [# o# l4 H: m3 @; E& ?

4 s; _2 @- o0 f( y! d4 D0 N, b" f- t        Do+ y0 D% K- c# t1 `' S
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)& ^# t( `5 ?3 ]* c& M" Z* n
            If (aChildTag = Tag.Null) Then Exit Do7 {4 }5 A$ N7 I
, {$ z5 o+ z- k- x( k5 U
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)$ T1 N& E% }# k  [& B( i" s
            theChildren.Add(aChild)5 i' c; h0 O. \& f0 t
        Loop
+ f' o( |6 a  f1 N+ }' z        Return theChildren.ToArray(GetType(Assemblies.Component))
! e) B) j( W6 t2 s0 K6 E2 x3 `) n7 Y8 a3 `& W, {1 d! W6 }
    End Function
+ J( t1 H. r" C! V6 t8 ~7 @+ e% S/ \2 G6 K3 k) G2 I$ U' }
    Public Sub Main(ByVal args As String())
2 r2 Z: v4 `( h  ~2 E4 h        If dispPart IsNot Nothing Then  Q. \7 g" }6 c5 [3 W; z
            DoIt()3 d' |! B9 W/ c5 t% q4 a$ @
            Return
4 J" P: T' T# p( p3 @        End If* s* A8 F7 R1 T- Z

; R( L5 P  }! Z( l    End Sub
0 W" L* q  Z, y- g: ~1 Z" P; I- F; f6 E
, C( Z# ~& N; j5 j. H' g; G( |    Sub Echo(ByVal output As String)
% D- U; \, |5 d7 D        theSession.ListingWindow.Open()
8 n1 P7 T- O! k. F9 `5 i7 F6 w        theSession.ListingWindow.WriteLine(output)
5 n  V% ]9 N# ~) D- _$ O! E. O, |$ `        theSession.LogFile.WriteLine(output)
/ Y; _, o+ ?8 t& w- v+ B/ D% w    End Sub) Z0 r. }/ @! `, ]' k. [
/ Q2 }" B: O) C" @3 [/ e! T
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)) v0 D- g3 J7 [! A/ f- x9 |
        If load_status.NumberUnloadedParts = 0 Then
( p1 y( `/ N9 X& P" d! z  t            Return
0 Y; c( A* B* X! O- i        End If
+ @8 i- s1 F& C8 G* W
0 y4 q4 z& H! M% O4 ~  I! {        Echo("  Load notes:")
" O0 h1 d  S+ Y$ [1 e4 D
% `8 `  c$ w9 }! c& m. I! _        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1, t1 j" m  t# M. k: q" I! s
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))7 W7 R8 M( M1 ~* o6 X# t5 S. M
        Next" B7 h9 V! X* w( I$ n, O: }. S1 T
    End Sub4 N& y& @, N( H: Y8 `  l' e
- F& C0 {+ l5 r) o  I% o1 S
    Public Function GetUnloadOption(ByVal arg As String) As Integer
8 p5 P# v9 r9 L* K        Return Session.LibraryUnloadOption.Immediately
# N2 R$ J* {( b' ^3 ]: b    End Function
* q) \0 j' I5 K7 T1 h! |' x8 x
; X7 w: x6 M* ~- i' PEnd Module[/mw_shl_code]+ [+ o- g. m3 b, o' 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二次开发专题模块培训报名开始啦

    我知道了