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

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

[复制链接]

2019-4-12 09:06:31 2471 0

admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
[mw_shl_code=csharp,true]Imports System1 I1 j+ S# H! E; @4 m
Imports NXOpen
. L# V8 p- W/ B/ B: AImports NXOpen.UF) i; ?& Y7 i1 N/ J
Imports NXOpen.Utilities& s! g5 z) A3 z7 M* o
'2 s; R/ K8 C5 e  w; G) ]
' The OpenComponents() parameter
! Z+ \, \/ J6 H3 W: D1 l' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly/ Q; z6 @8 Y: J/ u8 w9 ~
' only opens unloaded components fully (see also PR-8406345)
" o7 y* V( @; Y' Workaround: collect and open all components individually1 e; @3 Q, ]1 d% a2 ?/ |+ s
'* G; r. V3 ^; N
Module NXJournal2 J2 T- g: @7 a
    Dim theSession As Session = Session.GetSession()
8 g5 L* k0 f5 _5 K5 P" C7 ?' ]    Dim theUFSession As UFSession = UFSession.GetUFSession()
' r! o' V# G  Z5 }5 k9 _    Dim dispPart As Part = theSession.Parts.Display1 y) U# g6 R# h( h
- T, v: s2 L/ p/ A" p' Q& C+ T
    Sub DoIt()
# P" h  J  f/ P! y- Q# L0 K        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
9 }7 l: a+ S" B, w% V; m9 w        Echo("Number of Components: " & allComps.Length.ToString)
8 b& A  T4 q+ g) K4 d' h1 u        For ii As Integer = 0 To allComps.Length - 1$ \+ t( C# @1 `
            Echo(allComps(ii).DisplayName)
4 U+ d- H) l- y% _" z6 ]3 U, w        Next; T4 I( I  o+ e3 s
, ?, U# m$ X* {# ]
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
% ?* ^/ x. I4 d0 a4 {/ G- N! L        theSession.Parts.LoadOptions.UsePartialLoading = False
2 r2 }3 ^! r3 Q2 S+ k4 \5 Z4 O# h1 u% t$ s! R8 {. o
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
6 D" j" I  g, C. u        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing# _( }, k0 u$ S5 u
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(- m+ {7 @1 M9 c9 d! I
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)" {/ N' W- E) F+ U9 O. c/ {5 m

( G. x6 G' N8 E3 |7 r% x" p        reportPartLoadStatus(partLoadStatus1)( K6 n0 c7 m, w$ ?
        partLoadStatus1.Dispose()
& s* Z; O3 [* Y
. K" b) [2 Z  b8 B/ A1 h        theSession.Parts.LoadOptions.UsePartialLoading = option14 R2 o8 v6 D+ }2 {; d
8 |( O% m6 C7 H
    End Sub3 @7 }( \" G3 C3 k# m, }

6 K6 x  R: ^) @# Q5 X; k4 o4 {8 b    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(), [$ p5 B3 W- I7 \
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList0 m( k) b+ v  x, s  r! _
        Dim aChildTag As Tag = Tag.Null
7 r  @) L% S$ d8 ^2 [
5 ]: H) |- f) A1 U1 c3 C        Do
. `$ d- Q7 A" h            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)& \. O2 L) ^! J: t4 ?, O( W
            If (aChildTag = Tag.Null) Then Exit Do
' p( J8 ?) H3 W  `; K( b0 e
3 y6 g* w" I: Q7 x* j" b8 z$ @            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
& N# [1 L7 |1 c- F1 e            theChildren.Add(aChild)
/ j$ l8 e; l, J        Loop
/ E& b' x- W/ q2 w6 M. z        Return theChildren.ToArray(GetType(Assemblies.Component))
" h0 S. b' I, B
4 i4 n- a1 o4 b& t; F9 W0 H    End Function
* q3 p5 u; d6 L3 H; t; @- h9 N9 J) ^& I7 p2 O% U# L
    Public Sub Main(ByVal args As String())
0 I1 G- n/ Q4 U- v3 x: u        If dispPart IsNot Nothing Then
5 ^3 g6 k& h* m& B$ R+ h1 b: q6 w            DoIt()
4 Q! Y3 L1 P* ^* T7 T! p* j7 F            Return- p! H% h) r; W7 _. A
        End If
0 c& h2 V* i% S% I3 G- F
* @3 d/ p$ _, Z2 T6 E! `    End Sub
1 M8 _3 M6 e0 h) D7 s% y& O/ \1 h% Y3 p" i
    Sub Echo(ByVal output As String)
$ Q) @! D% P* ~5 u) n6 J. ~; @        theSession.ListingWindow.Open()* k' p4 b" O0 X  ~2 M7 k# x
        theSession.ListingWindow.WriteLine(output)3 j) }" t* z& E8 R, |4 _& }
        theSession.LogFile.WriteLine(output)
9 m5 J" T8 X5 e- [, M# [1 k% j    End Sub( f$ j# X% f6 p/ @  l) ]+ f

+ ~+ F5 W- F! f" v$ n    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
. i0 ]  ^8 Z+ U1 n. O        If load_status.NumberUnloadedParts = 0 Then5 b" x+ e% M) e+ y* S2 E
            Return8 q5 t  Z( M) [' v9 u) T3 v  i# }: [
        End If
* r4 W) y; I, F7 b: l/ i# J6 Q0 [! a" @, q3 o
        Echo("  Load notes:")
' s1 J; p! g5 r: F. U1 j; W4 O, z: L3 z2 V" V6 z
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 15 `0 }) L+ t- x3 z" }
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))7 V- A/ @. L' K
        Next( Q2 ~& p: S7 S9 ~; ^/ d
    End Sub1 x6 A. P/ f& g3 F! J6 N

4 H8 Z0 d7 I% T1 T    Public Function GetUnloadOption(ByVal arg As String) As Integer
/ e6 W% n% R1 G2 x        Return Session.LibraryUnloadOption.Immediately9 s+ j/ x; w3 v/ e2 v& [; r+ ?
    End Function# K, X% {, T' {- _2 g; D

: f6 r% R7 p- g  _. a8 S! PEnd Module[/mw_shl_code]4 J- w* _4 V- N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了