PLM之家PLMHome-国产软件践行者

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

[复制链接]

2019-4-12 09:06:31 2280 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
4 u- @5 r+ z0 t$ y8 [Imports NXOpen4 ^. ^% b( y' i' _* n4 \! P
Imports NXOpen.UF! N1 L- f  n2 Z& r2 T( Y) y
Imports NXOpen.Utilities
* @3 U* l8 Z3 ~+ T6 ]$ @'
4 P4 _- d' |# Q- R6 T) v4 }2 m6 G' B" R' The OpenComponents() parameter. G9 [% I( F: w" m1 Y2 n6 A- q* A# g
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly: G0 }; ^$ u2 h3 m. O* h- W
' only opens unloaded components fully (see also PR-8406345)
+ X8 x# m' }5 W8 v! h" q. H% s. S' Workaround: collect and open all components individually2 \- E9 \4 i- x# B% \
'  J# n5 ?; p3 P6 `3 o5 j; H
Module NXJournal
4 s+ l$ J" g2 T9 }6 Q, X    Dim theSession As Session = Session.GetSession()
  y, d7 S+ i& C2 _; p' m. P    Dim theUFSession As UFSession = UFSession.GetUFSession()
* Y8 ~# P5 Z3 f# O4 G    Dim dispPart As Part = theSession.Parts.Display
! }7 }  a$ P: \! u& F8 O7 t7 g( r- U, m0 }
    Sub DoIt()" I) o, p8 t  N$ _9 F
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
; ?  m* V+ q; a; v& t' L7 x" @        Echo("Number of Components: " & allComps.Length.ToString)
- ]- W* g* w/ s, K! X% l        For ii As Integer = 0 To allComps.Length - 1
9 L4 r% X. y! M            Echo(allComps(ii).DisplayName)
* \+ m& w' P( G3 j' x" E        Next% C3 ^7 G, |( z1 R: j) Y4 P2 D& D
$ Y7 Y# m- ], ]/ [6 R' w/ o% `
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
4 A. ^6 N: T- m+ f2 R0 F9 ~        theSession.Parts.LoadOptions.UsePartialLoading = False
) W: L  y& c7 O" q# y9 S$ ~8 q( ]7 p' H( \5 n7 R1 j: J
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
+ y& v' V0 `9 ]8 _& B" x2 X* F        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing+ o7 t# a8 q6 g& `7 Z; r+ Z5 T, j9 P: D
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(- D. p6 S1 L! d& J# S  _( b# ]
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
; w' `7 Y+ l1 x+ C& b
9 F: u+ x$ G( |* c        reportPartLoadStatus(partLoadStatus1)
, _7 {" A4 Z) i1 N6 t% `" u) j        partLoadStatus1.Dispose()2 |$ O2 x# f) Y  i4 y

, i6 Q: l4 u8 u7 n. g5 t4 F! A        theSession.Parts.LoadOptions.UsePartialLoading = option1
* E* {/ E! O/ X
) ?! W! `& Y' W1 B    End Sub
& D4 {: R0 g' E0 H- U6 D7 H" n4 U3 Z! ]5 P
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
7 @+ c# u3 M! d8 _- \' d        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
3 y2 A, [( a; ^. n. d# H        Dim aChildTag As Tag = Tag.Null4 Z* [; P1 G" [# K- L
4 F8 p3 ?9 }: o
        Do8 u  n1 l  [+ O3 [0 j7 l2 W! L
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
  o) i# b! s# G- _4 l9 u            If (aChildTag = Tag.Null) Then Exit Do
, l+ l2 s0 }& l6 Z# s
6 M$ D5 H5 @$ d: D8 @% c6 S            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)" r/ q3 S7 [7 l) X% ]
            theChildren.Add(aChild)6 |7 d, E# T  P4 S/ d* k" o
        Loop9 G) u* C( s0 v6 S3 K% ]
        Return theChildren.ToArray(GetType(Assemblies.Component))
4 p# H2 J) B) u  P' j
# k+ Q" R( f& E4 Z2 {& n  B" r    End Function% K) }' X8 {- x  @& |5 F/ K: i7 h
' K+ A# e- K4 @: I  S, K1 o
    Public Sub Main(ByVal args As String())3 \! A  t9 [! w- E
        If dispPart IsNot Nothing Then
0 M1 ^5 D  |# H# s7 }; t            DoIt()6 ~; f$ [+ ?& C6 V
            Return
- V- ?' p" {0 }6 I/ L        End If: J' N& D' C" p$ O$ D# G

2 U! m$ y0 i/ s3 i+ S. O& B/ f/ R4 \    End Sub
" l9 T! q" }' i8 k$ x$ e/ m4 z) f- _
3 p+ U" N/ f0 z. ^7 l    Sub Echo(ByVal output As String)) J/ Y5 B! a/ O8 u0 o
        theSession.ListingWindow.Open()
! \) C0 H8 L4 ?6 R' ~        theSession.ListingWindow.WriteLine(output)5 x8 g$ I7 g' @2 J' v* P
        theSession.LogFile.WriteLine(output)
0 C1 P, [" ?8 ]    End Sub5 v5 p# u+ w3 B# h/ ~8 m

& n( ~4 d: R: `    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
3 T0 Z) ~$ B& q0 T4 h* y        If load_status.NumberUnloadedParts = 0 Then" S' o* j8 C) I( @% Y1 ~8 @3 F2 g
            Return% a; G3 ]1 `9 G* e
        End If
$ x; L7 Z0 m! c7 m# E3 {8 S0 f; j4 g) ^4 T4 q1 h+ _6 ?! k* J$ V
        Echo("  Load notes:")
* Z1 }: Q0 o: X- e3 K
+ ], G  r' ^: {0 E        For ii As Integer = 0 To load_status.NumberUnloadedParts - 17 m2 M: n; j7 F- ~  x7 S1 z3 K, G
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
2 L& ]% s6 K$ v7 F. N" S2 o; y! l. I        Next5 g# e5 J  I& y, R0 ?; T
    End Sub7 q3 \% ]/ v. d$ c* b/ h7 E

0 e' ~4 g, V0 P* z9 x5 P  I. W  p" l* T    Public Function GetUnloadOption(ByVal arg As String) As Integer+ i8 S' \: l" e, U5 }8 Z5 H( Y5 E
        Return Session.LibraryUnloadOption.Immediately
. Z0 K; d. i* J1 E    End Function
! h5 M. R9 t0 @" ?) ~  k5 W" ]  g8 I2 k& T4 u- M+ L& Y  j
End Module[/mw_shl_code]
3 A& M, v* B$ D6 w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了