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

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

[复制链接]

2019-4-12 09:06:31 2290 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
- @; x' J! D1 b  L4 b, {Imports NXOpen
( n& W/ C! k, x- m  i& g0 uImports NXOpen.UF
; K9 R# j4 V9 D( O( p: l# SImports NXOpen.Utilities
- x" R: B+ y$ T5 j! Q: t'
: ]% z) h+ D! K" s! g8 J' The OpenComponents() parameter$ ]2 N" q' g7 c4 m' o
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly/ u) e, x! e4 P2 j1 k) ~' [
' only opens unloaded components fully (see also PR-8406345)# g# d, R# U# A. Y. Z2 M  C# }8 T
' Workaround: collect and open all components individually
  P9 e2 D4 n/ v" g3 |* f& C'; S7 T/ m# p: P1 R
Module NXJournal
3 D% _) ]/ A$ E0 x7 ?6 K% m    Dim theSession As Session = Session.GetSession()
2 {1 R, V; k! R- y' B( M/ m9 |    Dim theUFSession As UFSession = UFSession.GetUFSession(); x1 Z% V; }( v3 ^3 Z
    Dim dispPart As Part = theSession.Parts.Display
/ x/ U/ P! _5 ]5 x* i
: }$ }8 N- D% D( h/ C8 c2 V3 l    Sub DoIt()
& H7 D9 y$ `, K! x; a4 o        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
- a' h; h4 @2 b  q) P0 ~        Echo("Number of Components: " & allComps.Length.ToString)* M) H" b1 @6 T+ Q8 o# w, U
        For ii As Integer = 0 To allComps.Length - 1
% u) Z# o$ M+ w            Echo(allComps(ii).DisplayName)" @+ D7 m! s0 R( x4 U+ D6 `1 x/ s
        Next3 p( t# J+ f/ ^
* G1 r& ], w7 Y% O4 X0 x
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
  h( k" `; ~+ Y, G/ b) U        theSession.Parts.LoadOptions.UsePartialLoading = False
& s' ^; j4 }) ^9 e! [7 ~
6 M! t. }) z. C; L/ e        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
7 z( B/ {: G5 T% C- x7 T' G! P        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing2 Z. {0 i. d" V  w' Z9 _) _
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(8 ?% H& E" A/ h0 O
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
0 P" f* W$ X0 J' J! C5 S* N* \3 ], z- r) E2 B$ z5 n
        reportPartLoadStatus(partLoadStatus1)$ U- V) V+ n2 b  y3 x, ]
        partLoadStatus1.Dispose()
) o" S% Y+ {/ W
- c  J1 s( q# t. ]' l/ c        theSession.Parts.LoadOptions.UsePartialLoading = option13 p9 f! J) w3 G6 z  ]" Q$ [% I

0 x6 E/ z# A8 \/ ~1 K    End Sub0 I! T& ?1 o/ Y! A# C

& `5 K2 v) W) ^3 Z8 n0 |2 m% M    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
; {" b4 q: B# f: f2 d/ |8 A! o6 O) Y        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
. r2 r. w3 {4 p# u( Z        Dim aChildTag As Tag = Tag.Null; m8 s, a+ A9 R
$ ^2 P3 M+ o. S/ D2 W2 l9 Y
        Do8 `" |$ ]8 ?1 M, ]
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
# ^; X2 h  Y6 t: Q            If (aChildTag = Tag.Null) Then Exit Do
8 @* B/ ]4 O8 [* k
$ T  h7 i/ |0 M3 x1 [% c            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)! Y. l- {7 [$ K& S7 o& G
            theChildren.Add(aChild)
1 ]# x, I( G: U; P* O! c        Loop
+ q, p& e" K6 z        Return theChildren.ToArray(GetType(Assemblies.Component))1 [  `; B! w+ E( H) h/ k0 a! R: I# L
9 f7 K7 W+ s2 j' _
    End Function
0 G/ W2 Q, n8 f' b  e' g" c- g: v& C4 }4 A
    Public Sub Main(ByVal args As String())
! d# G6 o' `. a( \7 O        If dispPart IsNot Nothing Then
5 q1 d; C, c0 d. T+ ^2 A            DoIt()
5 x) Q+ ]0 h; E2 F: y/ m9 d2 ?, i            Return* I: @4 x4 c( r
        End If) w! a& C3 Q0 x' T1 m
: t/ A; S& u- O% b5 Q
    End Sub
9 j/ f2 U: ^0 h: Y8 ?
% q! Z6 C, j7 M7 R    Sub Echo(ByVal output As String); V: c! s) j/ p0 Q( B" e: q! \, w
        theSession.ListingWindow.Open(); L( p. ~6 b8 v: n
        theSession.ListingWindow.WriteLine(output)
) _- m2 U. A4 X. K        theSession.LogFile.WriteLine(output). |7 h9 A1 C5 l9 _: o# u
    End Sub
8 z- S4 l3 x* g* ~
& [7 I2 J! L& U" t    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)1 m6 Z* x% L1 z7 \% B: C+ f
        If load_status.NumberUnloadedParts = 0 Then4 T/ |5 i2 ?3 l( t
            Return1 E% c8 V  X9 O
        End If% u7 ]1 K2 N) ^. D+ E

( _5 p6 c" M+ y+ c9 S        Echo("  Load notes:"); K) G/ O, C9 Q4 Q5 _% a! Y

5 ~/ C5 U3 F9 ^) ~        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
7 i5 V) Z7 m+ ?' r! E0 `! R/ v            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
. U2 k) e2 r8 C6 i" u- e& }        Next- Y5 ]6 H! H  y  M
    End Sub  E' R1 A9 E2 y7 g' Z

5 {& ]1 z4 }$ ~    Public Function GetUnloadOption(ByVal arg As String) As Integer
+ e0 }9 g8 v/ f( n! S$ A; v        Return Session.LibraryUnloadOption.Immediately2 f. F  X( y& s. h  T- H
    End Function
3 _! V5 P' Q4 r. i  K# J" M2 w* V, h2 i! b
End Module[/mw_shl_code]
% A: T) l2 {7 A  u7 a/ G+ ]$ k7 I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了