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

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

[复制链接]

2019-4-12 09:06:31 2433 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) T4 j& g2 e: |2 O
Imports NXOpen8 Q6 z' s# h9 Y$ |
Imports NXOpen.UF4 G& w8 ^- |+ {% S  [
Imports NXOpen.Utilities) [8 Z! g6 f2 j/ \" E" y5 e3 ~
'8 q( c: G' `6 n0 T0 V. `
' The OpenComponents() parameter
  P; i9 }6 n  @$ T. Y' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly7 `/ X4 T$ s# M( _
' only opens unloaded components fully (see also PR-8406345)9 U; \! a. w9 y0 k% D3 J7 `( x, D
' Workaround: collect and open all components individually
& b0 K. Z/ U# C& K+ K'
# }& z* t/ h. Q% u9 B" }( wModule NXJournal' @1 q4 r: z5 j+ o* N6 t
    Dim theSession As Session = Session.GetSession()
# f5 z" P% @+ O; R" Z    Dim theUFSession As UFSession = UFSession.GetUFSession()
( N3 ]1 N3 O8 f! S    Dim dispPart As Part = theSession.Parts.Display
/ q9 ^1 x0 O8 S( |4 I; t/ I* H
! ^5 G) }( W6 B4 `5 ~& i8 J    Sub DoIt()
* A0 q% \) Z8 N( K7 f        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
1 r. m" M$ [4 m" r( ?6 Y        Echo("Number of Components: " & allComps.Length.ToString): ?- R4 W" I7 u* n; {- ^6 l; f
        For ii As Integer = 0 To allComps.Length - 1
* i. x/ U# @* a- n0 ~  b) H$ @1 j            Echo(allComps(ii).DisplayName)
7 S7 l5 z* Z: n7 G        Next7 q; z2 y6 m" k% l* `
, Q1 t8 B9 u: h+ R5 x
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading3 L) D+ A! S; n& c
        theSession.Parts.LoadOptions.UsePartialLoading = False
/ N6 t9 n9 F( \/ c- Z6 u! h" D' U) ]
6 s' j2 X4 p" f1 I        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
' }9 ?$ N6 `* d! l        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
1 X; Y- x' d3 F( k% O; y        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
9 s' n% H6 w) e- ]            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)& z0 F, }& U* L; y9 t3 M' Q1 g3 z

& h* o) ?! H" a  d        reportPartLoadStatus(partLoadStatus1)
* B& }& H4 e5 Z1 l1 N: ?        partLoadStatus1.Dispose()
& m7 q7 E* \6 P: e& d1 |) C; {( |8 {
        theSession.Parts.LoadOptions.UsePartialLoading = option18 g: w  T6 i7 g  Q$ w8 c

- }1 R* ^. b$ [4 X3 M7 o, m    End Sub2 @. Y) `! Y( }, Z

/ M& y7 E- l) ?7 {    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()" a3 _: I1 s& e7 V$ j3 V
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
9 r* M% h1 B4 I3 Q0 s# t        Dim aChildTag As Tag = Tag.Null; G( Y, S; q, R0 _3 U4 [6 r
& {) u8 i* i' d( c2 W% v
        Do
) ^4 O' m: P+ W7 m            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)0 j6 [: a- D( w9 g1 e1 m
            If (aChildTag = Tag.Null) Then Exit Do( b7 b; L, N1 o! T/ ]7 `( n. B
) g$ J9 N7 m3 g
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag); o! ^( R& }7 P, S2 Z* m
            theChildren.Add(aChild)
  U" p$ j( b1 L7 v        Loop" {# Q% ]& h0 h! u% @
        Return theChildren.ToArray(GetType(Assemblies.Component))
1 T. }# q- u5 X: t  ]# \* h9 O4 \: L* [: L9 |
    End Function
# e" ~7 o. t8 D7 D; k
. p( d- n+ C9 M9 ^% }! ~    Public Sub Main(ByVal args As String())
; P* G# o" f9 ~, [* m1 E        If dispPart IsNot Nothing Then
' K2 `" l0 u. j6 f; [7 \            DoIt()7 R$ ^* _! I5 b* m, s: o+ T3 g
            Return
& W6 Q9 O; K  |3 Y        End If
6 l) B2 [* E" h: y0 f! y4 }1 i+ Y7 h& i9 K8 R
    End Sub* q5 a0 G7 m4 j. A. Q. v, ]

3 R* k1 |3 p3 W' [2 }& r    Sub Echo(ByVal output As String)
3 h7 X" z% U' H  j# G" L        theSession.ListingWindow.Open()
. F: J3 w+ |0 i, u" q+ ~        theSession.ListingWindow.WriteLine(output)
1 L+ E8 \% l" x# i+ @% u0 o        theSession.LogFile.WriteLine(output)
, {( i# R# ^2 w7 Z    End Sub6 G+ ]/ M, j7 c$ n! L
, r, y7 ^3 E. w! m- G7 D
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)! }( b& c2 j7 J
        If load_status.NumberUnloadedParts = 0 Then: m% C+ d" h: |0 F8 M# C
            Return% h9 p6 m( ?0 r, E
        End If
  v- w0 @4 y6 W" `6 G& t" |0 o; N8 q1 r# F5 x
        Echo("  Load notes:")
# Z% X* x+ b7 N! O7 C& P$ W
$ _% d5 u) C: ~% E4 Q        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1. I) l8 p' k5 T8 s
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
' d0 o8 M0 d& B        Next, l" V- ~% Q. a" [- q
    End Sub
0 g5 M  ]& G; X& @5 A5 c; l3 l9 C) k" d/ W9 N4 ]) p: [
    Public Function GetUnloadOption(ByVal arg As String) As Integer' j% {: m0 A! Z: E# C
        Return Session.LibraryUnloadOption.Immediately
7 m! }+ g: E' a) o, [7 b1 U0 D    End Function
3 f7 B: D& O% x$ O; v. i  m; c0 S: E! y$ ?! ]
End Module[/mw_shl_code]5 ~/ x1 V4 M! e* j* f1 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二次开发专题模块培训报名开始啦

    我知道了