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

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

[复制链接]

2019-4-12 09:06:31 2408 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
5 B( a3 k1 f: E1 {: c* \3 [% mImports NXOpen: V. p* }3 g7 [, g0 d
Imports NXOpen.UF
7 X& @& _/ s8 I; pImports NXOpen.Utilities
2 |; L5 Q, L( K- y'9 T9 P3 _/ p8 Q6 ?' e0 I1 S( o8 I5 L
' The OpenComponents() parameter
/ ?: m. k* S1 a' H7 t2 P, r9 N( V' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
! l- |# T, k& Q$ T( I+ R1 y1 Z/ M' only opens unloaded components fully (see also PR-8406345)
8 D6 Q- N4 E& e3 R$ e+ L; D' Workaround: collect and open all components individually0 {4 q6 Q) y; E; i; h7 y: J
'3 |/ r! T) ]9 e5 @/ b% r
Module NXJournal
8 ]8 p, |+ |% E8 Y1 A: l! Z, B% l    Dim theSession As Session = Session.GetSession()
/ K# }1 ]/ t5 _) U2 @9 C    Dim theUFSession As UFSession = UFSession.GetUFSession()
0 w* r  f, N3 V* R  r  q' L    Dim dispPart As Part = theSession.Parts.Display1 L, l; h' k- v

& l/ j( H9 e# W; X  c6 v( d9 L9 R    Sub DoIt()
8 d- W" F7 x2 j6 v. E        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
* f$ z7 a3 s# y% P        Echo("Number of Components: " & allComps.Length.ToString)8 l! M: Z" E4 e: @
        For ii As Integer = 0 To allComps.Length - 1
- d( I5 Z, H( s! b            Echo(allComps(ii).DisplayName)* W7 Y: Q% G/ ?* k& K! o
        Next
9 M/ b5 P3 k7 }; E" Z
; k+ }' X- F, |2 ~8 n# f        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading: E. o( C$ n# T( c! Q' L# l! O
        theSession.Parts.LoadOptions.UsePartialLoading = False
) r  S7 l& o5 k; Q$ G1 V7 P; _2 \6 O. l% K) U0 o
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
4 I/ v0 k, ^' V0 J# @& ~2 c6 b        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
) g2 P8 u* w" d4 X4 ^        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
3 o: g: |- O$ C7 t- F7 T# W# S            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
' O# v" E& e) [2 f. Y  B# D: o4 z$ M1 w9 |3 t8 L
        reportPartLoadStatus(partLoadStatus1)
% D( \5 D/ H- V& X4 d* i3 g        partLoadStatus1.Dispose()
* K3 E' U0 s2 ?$ r7 K
. Z5 N6 l2 t  O9 {: f        theSession.Parts.LoadOptions.UsePartialLoading = option1
7 C' j* g$ o, ~/ Y. @3 H8 N/ J& k- L  K* s, Y/ H: b. X
    End Sub# c& ~; u9 G+ Z- ?: X  }+ H
8 }5 y- j9 ~! O+ d* c
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()* K( j. D. F9 L7 [3 w
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList  P/ d  o8 f( m, `+ M& V
        Dim aChildTag As Tag = Tag.Null) O" `3 |* b& W  e4 A% t

% g: P% n6 E% e9 j8 t; _        Do
2 T* B5 w" i" C! `" l" }6 X            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
  `9 ^$ f# \+ C4 j# _. G  O            If (aChildTag = Tag.Null) Then Exit Do* u2 T" W9 S9 Y1 m0 N3 I) c# z
, E4 |" M9 m" I
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
2 c) [9 t7 `  Y* t. P8 F            theChildren.Add(aChild)
2 J' G: }( Y5 h* v        Loop
! _. y9 s6 d0 Z2 }: E+ Q        Return theChildren.ToArray(GetType(Assemblies.Component))5 v/ k. y. o  r

8 d& a6 p9 L9 N1 Z    End Function1 N( I" J2 w/ F8 O# E; r

8 X( N/ h6 Q' m$ H    Public Sub Main(ByVal args As String())
# [# a2 Q5 |6 ^4 k4 N        If dispPart IsNot Nothing Then
0 L' D7 M- k& y, e  d1 c( v- ]            DoIt()
7 P3 e9 i8 r6 B2 f, \9 a% n            Return1 F1 ]7 }7 u  `) c/ I
        End If4 ~% r8 Y+ f0 E6 v* i$ o/ ?
3 I5 O7 e+ e& H* M3 j5 a( V- Y
    End Sub
- A9 ~+ {8 Q5 f3 N8 D* y7 H
0 @+ A  w& e6 _- Q7 T    Sub Echo(ByVal output As String)$ ~, i: J* C# P" r' A
        theSession.ListingWindow.Open()
+ F+ E0 n$ Q. f* E7 m! d        theSession.ListingWindow.WriteLine(output)
4 ^( z3 @8 Q; T4 s3 u: C        theSession.LogFile.WriteLine(output)9 Q1 p3 \  C# k7 \) M
    End Sub
( v: k' W0 U8 k
( r8 O: u) ?5 T+ J    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus): Y% z3 V5 m7 I0 g. B6 S; k+ Z( s, A
        If load_status.NumberUnloadedParts = 0 Then
1 T) Y7 v- y* `) U) \' _            Return
$ i4 @( P0 U' B        End If- R% g+ |7 F) z, H2 r( i
! [4 e4 c! }1 y- ]- ]
        Echo("  Load notes:")( I% g# s8 j/ r6 x7 @- @* f

3 w* Z1 m% A% ?7 I2 V7 U" E8 H; t        For ii As Integer = 0 To load_status.NumberUnloadedParts - 10 t: d, @* }5 ~- f. W5 E
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
2 Z4 B+ `: Q  B* u5 M& w        Next
5 H3 i+ |* \( h/ ?0 n, ^    End Sub) v- A. d" G! W. ^3 F/ d  t

; L2 Y2 c8 p( y: h    Public Function GetUnloadOption(ByVal arg As String) As Integer
. i, i  o# {# Y5 Y% r1 d7 U/ E        Return Session.LibraryUnloadOption.Immediately
# f/ y+ x- R6 }5 f7 j7 z& ?    End Function
0 x  w, R  l7 ~) O& q
- `3 a7 I/ G( H4 J2 q! V1 o% V/ LEnd Module[/mw_shl_code]
* B, @4 ]/ ~2 j* i6 ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了