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

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

[复制链接]

2019-4-12 09:06:31 2484 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
( C3 L5 x  M, ^- W2 A8 dImports NXOpen- I7 }0 L) M9 V* L
Imports NXOpen.UF6 H, J9 V* h% M! W6 R- A, {& ]; D: i
Imports NXOpen.Utilities2 n2 Z- k( z" L! M. a
'( d3 V3 o. E  ]5 O* r. J# N1 C1 @
' The OpenComponents() parameter
6 h: \: S" @1 A# b' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly6 W% i( R+ q0 u! r& x1 u
' only opens unloaded components fully (see also PR-8406345)
# w* O" z' o4 I" E/ e, W- q' Workaround: collect and open all components individually
# C7 J# k" V1 D' s4 l'
" U0 |; y' |: ~6 l/ XModule NXJournal
+ ?, M& ^  b5 _; Y) R- |! C: B    Dim theSession As Session = Session.GetSession()9 W6 H5 {# N/ W  p/ `
    Dim theUFSession As UFSession = UFSession.GetUFSession()
7 y6 ]- ^3 a) `$ S. ], u    Dim dispPart As Part = theSession.Parts.Display( M: }1 t7 d# b6 h. P
' D0 ?  ~% I$ e2 ^( D) i' I6 \
    Sub DoIt()
( j9 n: y; ^8 g        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)7 A9 |) e  v1 x# i6 p7 ]' r6 I) a
        Echo("Number of Components: " & allComps.Length.ToString)% i5 C+ b' N# [' S
        For ii As Integer = 0 To allComps.Length - 1
# M# k7 C: e' @  m            Echo(allComps(ii).DisplayName)) Z( f" ]8 F7 ~! K8 N# ]
        Next* _& B: h2 p7 X. T
5 W9 Q: i9 o$ Y& n9 _* n. E
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading7 R" A3 Z( `! I" Z  D+ e! a
        theSession.Parts.LoadOptions.UsePartialLoading = False
4 G  A$ T: I5 b, N1 ?! w0 V  t* V& N
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus" }& K" K0 x9 k
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing; Y7 d2 F3 O" B9 B
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
, J0 c5 `9 @$ }3 R: M% h0 S            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
6 v- K0 [4 }! h, s! w$ y  c+ P- _1 W6 t. X# Q' x( l9 o- A
        reportPartLoadStatus(partLoadStatus1)
: C$ u) A( E' |" r" c        partLoadStatus1.Dispose()! o2 F1 \- K% B& M& H
% g3 l' m* Z& \) ]
        theSession.Parts.LoadOptions.UsePartialLoading = option1
1 w$ n! ^9 [% L: h$ n0 M5 R
$ g- ~# Z3 w6 V    End Sub$ b8 i. n+ n7 L1 i" @
$ O: p( k* a# s
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()$ D9 c  T5 v8 J: B8 o) E2 G% t: J  b
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList0 [' ?1 A6 @) J: z0 f
        Dim aChildTag As Tag = Tag.Null. A6 S" k0 p1 [6 x4 O3 @" H. I

7 ~& P6 q: V, N  P        Do
# C  c( m6 M) R0 p/ T: e7 ]' Z            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
# j- p) q) h0 j5 x0 j, b  g            If (aChildTag = Tag.Null) Then Exit Do
* `9 t' @* U) Q; f: ?/ U5 \
" S4 _4 J2 e4 L% X  m! m$ p            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)1 q9 M  v( m0 M- L% N5 J
            theChildren.Add(aChild)
. a. S! ]5 L, ^) i) D% x        Loop
6 T9 s6 g" c) O/ z" _4 k        Return theChildren.ToArray(GetType(Assemblies.Component))
2 ~3 U% M1 l* u$ B
3 `$ m6 I3 E, [# m+ k$ g+ g: q    End Function
3 g6 {- K' U& e! I( G4 |7 c8 f- j$ b2 e" j; ~' v
    Public Sub Main(ByVal args As String())# w& G( o' Q4 E, g1 B: l) r# O, |
        If dispPart IsNot Nothing Then
7 E, s$ Y6 \" b: S# m            DoIt(). A; x/ K5 V: I; A4 u
            Return
+ o2 \( }  C8 k. f. @8 q        End If
* U9 M# t" k2 l1 A4 ^, n% V' C! s, H% J0 J% H. P0 Y
    End Sub$ ^* S7 f- D. i  \! _
& q' A, D& }8 x1 c
    Sub Echo(ByVal output As String)
" I4 T/ U+ C# L" e        theSession.ListingWindow.Open()
- \5 B' K7 u- W2 K" e' T% I        theSession.ListingWindow.WriteLine(output)4 @4 U- C3 u& X5 ?
        theSession.LogFile.WriteLine(output), E) o8 N9 g5 q$ I/ L  S5 l
    End Sub
* t* m3 ~1 s1 k$ S' p7 t! q7 Z$ |+ e/ i
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus): G9 x# s! y# O* \- `& w
        If load_status.NumberUnloadedParts = 0 Then' V1 @) ]& [" Y; X0 I
            Return+ v' _) r5 l; Y3 D5 U0 e
        End If( B, Z, e" p/ k# y) b- f, E" @
9 x1 {. C8 i) i
        Echo("  Load notes:")' h7 A0 A  F# m2 N
. \* t! v$ C1 M( A
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1% L# p3 ^  C/ q" }
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
4 [5 U' y& n5 O8 _  N' k        Next0 e0 V9 I1 w3 v' x
    End Sub- h! P; o& Y- U/ g+ f  e! |% [
* ?/ Q2 ^0 v, J: R$ C" u
    Public Function GetUnloadOption(ByVal arg As String) As Integer* V7 ~3 U: V: b- i) B  t
        Return Session.LibraryUnloadOption.Immediately
( U. Y! ]  F+ H    End Function$ |) f( q, ^5 v( s0 Z+ D

# c9 i: U# p  S* ^5 K6 _  nEnd Module[/mw_shl_code]
( l9 w. w: K& o) k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了