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

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

[复制链接]

2019-4-12 09:06:31 2478 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! I/ [4 k2 f( d2 l
Imports NXOpen
: Z- X3 N' G, Q7 y! O, lImports NXOpen.UF
- {& k  U) {0 d/ H0 _' CImports NXOpen.Utilities
8 G7 w! m9 Y2 h! i0 n'
4 \7 u5 T6 U9 p- _3 y' The OpenComponents() parameter" J# u- j' S- C) ?: R) u
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
4 I) a1 W7 R8 v/ p4 S! [' only opens unloaded components fully (see also PR-8406345)7 ~4 {0 h0 O. S& e* p( d
' Workaround: collect and open all components individually
6 A; ?- I4 S# M'1 _0 }8 [9 I( o! C0 ]+ E
Module NXJournal: |2 @! L( Q  l( E7 d. U7 i0 S
    Dim theSession As Session = Session.GetSession()
; j! O0 ^) C' n& ]    Dim theUFSession As UFSession = UFSession.GetUFSession()
  h9 k; Q. x8 n6 `; z    Dim dispPart As Part = theSession.Parts.Display+ [: r  U; w7 a( M# c4 K

; L# Y2 [# x8 V+ O) P3 ~    Sub DoIt()
- o( G5 F0 l3 {2 Y; f3 [7 ~        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
2 [; o! d1 t5 w5 q, s+ E  h        Echo("Number of Components: " & allComps.Length.ToString)% P) Q6 J7 X" _' K6 @# b3 v
        For ii As Integer = 0 To allComps.Length - 1
/ \, T% Y/ G  g2 ]) ]& m5 a( I/ U            Echo(allComps(ii).DisplayName)
* k4 R, ^. D: h6 [5 u9 k        Next
0 V9 ^" _! w$ F9 x# }
$ z0 U7 e3 s. l: Z        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
4 U3 b& i) w, ?% u, I5 `) Q        theSession.Parts.LoadOptions.UsePartialLoading = False0 Q8 V% u" ~- ~

) ^/ U4 m$ f" x$ l' g% q7 j        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
8 E2 u; Z" X" e' y        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing# [2 L9 k, L: u/ v9 r1 o
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
* J4 @6 Y& Z9 ?6 u+ |/ i            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1); `" Y$ s1 a- N: y

- M9 R% D$ b& {9 h0 `' ]/ }) d2 E        reportPartLoadStatus(partLoadStatus1)
  L5 P, Y/ e% k1 v6 f        partLoadStatus1.Dispose()
6 Z  {: [9 Y) B- M8 F4 |/ Z
' r! o* d& y' y8 n5 |& E! c& R5 {: V        theSession.Parts.LoadOptions.UsePartialLoading = option1
% m) x9 {( b. A7 r5 B2 R% C& ~% V, K& j6 N
    End Sub5 I$ m# X. r& ^& ^% `* k2 _

5 d% L0 V3 q4 c# r    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
4 b2 ^8 n8 O: L8 ~9 d8 B        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
0 w; L& l* \1 M( [$ y        Dim aChildTag As Tag = Tag.Null/ E8 E5 e% E4 T& T6 U& P+ l
( r5 c0 ]. e8 l( f( H
        Do9 G8 F9 d0 w8 N6 d4 k
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
/ }4 S+ Z9 X6 g) b0 G            If (aChildTag = Tag.Null) Then Exit Do
7 {" w4 K; X# g6 j, K! H
2 |! K5 U$ {7 @7 s4 b& D1 f% N            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)" ^7 c4 @1 W' k. H% c. n9 B
            theChildren.Add(aChild)0 C, ]  k3 d7 }1 R' `4 O6 X: y, [8 f
        Loop
$ C: _2 W( d2 u6 d/ C  x        Return theChildren.ToArray(GetType(Assemblies.Component))0 F1 H$ O% T1 ]5 z  e0 ~5 H1 U
" V* Q! Z) q# Q  f9 E# B
    End Function
% m# M1 J$ V4 q  d- h9 k: ]& t- N9 z4 M( Z! ]" [
    Public Sub Main(ByVal args As String())
' w* }# i$ t& n        If dispPart IsNot Nothing Then
2 z2 w0 G2 Q/ Y. X( ^& z" ~, w            DoIt()$ b1 }4 {4 p6 n6 j& ^- A! n$ `
            Return
' c- M8 }$ [6 H  C* \: u" H+ W. S        End If
" j, f% v* h* q" `* x2 [. e) I5 a
" l7 I& G' {6 l* D& v$ l    End Sub
- b4 D! x( ~& x  @( ]. J& B$ a; {9 y4 d* _4 m3 o
    Sub Echo(ByVal output As String)
) X* Q2 L: ~' w! E7 q0 S  Y5 S        theSession.ListingWindow.Open()' Q" t) ~0 P2 {* r
        theSession.ListingWindow.WriteLine(output)
+ F/ `3 Q& l1 X8 v! E  b        theSession.LogFile.WriteLine(output)! B: f" I* T8 R4 [$ `; z
    End Sub; P$ o; B& X  o1 U! Z; W; s
) l) }- X2 T+ U0 _
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
% E9 y: f7 k, Q        If load_status.NumberUnloadedParts = 0 Then7 h6 {/ X4 e0 p/ f8 p
            Return
& c- x& n: h1 }+ s8 @3 |        End If
# W4 W" }  B) b$ f0 `' i
" z5 M$ ^7 Q8 c" j% u" e        Echo("  Load notes:")
. O' ]) P6 w! \, a  Q# Z& m5 ?7 _0 N
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
5 |! h/ }- X3 F+ ^" I9 r            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))6 I( z0 r4 |' X  W. \' d
        Next8 d' m& h/ D  |
    End Sub
; @0 j  K5 R5 X/ C8 T- Y
  D/ _- J% ^+ R: O5 u    Public Function GetUnloadOption(ByVal arg As String) As Integer
6 M9 C5 o2 j1 ]* i  f* e$ S* N        Return Session.LibraryUnloadOption.Immediately
/ t6 q: G, I) o- k! a" c, t    End Function0 d- b1 z/ S( @. |
* f$ l% \8 `+ Z( {
End Module[/mw_shl_code]
1 A1 C& O$ B: O$ L' o2 k4 G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了