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

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

[复制链接]

2019-4-12 09:06:31 2440 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  ?/ r4 q* m9 t
Imports NXOpen
0 l/ n& H& e% UImports NXOpen.UF, ~# u" h! O6 F2 Y% t4 a
Imports NXOpen.Utilities
, O2 U$ M& @# }4 S'
2 Q! l; L1 l% p+ j8 l8 s; {' The OpenComponents() parameter
7 ~. ?2 y9 K) N' J' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly- K; c1 x5 U" I% [0 {8 G
' only opens unloaded components fully (see also PR-8406345)
7 |7 ~6 i2 ~6 K5 a' W0 a! S' Workaround: collect and open all components individually
5 |7 i& g( V+ z8 w6 L( F'
7 z. d0 E  r* P1 z1 [# M: i! hModule NXJournal
8 U4 t7 ?7 k$ ^) w4 F. Z  V    Dim theSession As Session = Session.GetSession()
( a( ^6 Z$ u% \& ]1 M& ^    Dim theUFSession As UFSession = UFSession.GetUFSession()
" r( q) e# N( p    Dim dispPart As Part = theSession.Parts.Display5 k5 ~6 d8 ]: v& y

9 [; G$ v  M) U' i/ _  A  b    Sub DoIt()8 |! ?- c) l7 ?; E
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
7 @! o* L  W( ^) W        Echo("Number of Components: " & allComps.Length.ToString)1 t7 x4 a: N8 S( P- r7 {& v- l
        For ii As Integer = 0 To allComps.Length - 14 a! F+ r3 p8 Y" r% H
            Echo(allComps(ii).DisplayName). E* C" V% r9 c& ~% G
        Next. _* r* `/ C4 T  k) D# ~0 T6 {

3 ?* e& ^& N  {' X) A        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
. l" p/ o4 O3 m: X5 V$ t        theSession.Parts.LoadOptions.UsePartialLoading = False
, a3 W# s2 E& a( U, h1 ]- z* T8 `- m
. O) Z  U# h/ t( i6 Z0 P) x# f        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
: I, `. r: r$ L; v/ y2 f9 ?; w        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
+ Z3 r3 p( a: r$ [        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
1 h( p2 C  n5 p' N3 Y; d            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)2 @1 d" ?8 c% j5 Q

3 z# K( c" n5 f        reportPartLoadStatus(partLoadStatus1)
+ V% K, H! G. b" e3 p        partLoadStatus1.Dispose()
; p+ ^8 J, y* H: {2 d+ J; l3 H6 A$ e5 f" K
        theSession.Parts.LoadOptions.UsePartialLoading = option1
) r# R! F  }3 {$ K8 i  U! d( J- S' C; G
) {' j$ l& k( \' o    End Sub. V% F& O/ c* S( b+ U/ W" A9 }; Q+ B

" t, S: k1 |( W. x2 H' [8 v8 s: L) Y    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
' L* N( ]3 z3 H+ r$ b, ]/ A        Dim theChildren As Collections.ArrayList = New Collections.ArrayList) S: z) U/ Y6 L- m: w, x7 {
        Dim aChildTag As Tag = Tag.Null
" k2 K& _1 u0 O5 |& }$ f+ O8 ?' E$ A& Q  V# F8 f6 u
        Do2 h% [$ D. H+ L
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)- X3 G; g: i4 [" m
            If (aChildTag = Tag.Null) Then Exit Do
7 w! _" O/ j) |: w. A& {+ X* @) [( g$ Z3 m! \
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
# M0 F6 D5 f; l! i5 B! {            theChildren.Add(aChild)
3 g3 `" L, O6 v9 f8 R        Loop6 h' s! F+ s3 Y6 Q( @
        Return theChildren.ToArray(GetType(Assemblies.Component))2 n" _9 r0 `9 a0 z' {
! i6 L) j; l6 E; b3 l  O
    End Function
3 Y2 n4 x+ D8 o& Z2 G/ ^8 O+ `* |
* o9 I1 L6 R$ ~3 V/ t9 @* ]/ E    Public Sub Main(ByVal args As String())+ V+ O6 Q9 t$ A, T& L$ Z- ]; }/ O
        If dispPart IsNot Nothing Then$ o' |* K5 _2 Y
            DoIt()
" T1 u0 m& I" |. i5 B/ y4 x            Return! q% @. G& d+ C& D, J
        End If7 a' n# i% d' C! X+ Q+ T& o

$ h" e; H* N$ E    End Sub
' l! d- G: T" d- b% K0 M$ n! ^' R9 `: L
    Sub Echo(ByVal output As String)3 p5 @8 p+ N9 ^: s
        theSession.ListingWindow.Open()* S3 e" W7 e* l( C4 c' X/ K
        theSession.ListingWindow.WriteLine(output)
; ]' O- N0 s! r* L0 T$ m# r  @        theSession.LogFile.WriteLine(output)
( a4 [, T: F4 [- v  o  x    End Sub& L& y$ Y% B- ?  ]* ^, s4 t: {. m$ M

7 l5 n6 E8 g$ g  M0 f4 R1 i    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)6 ~- d$ H" R+ q" l* a2 L
        If load_status.NumberUnloadedParts = 0 Then6 _5 X/ J& X5 N3 T) U4 b7 {5 Z
            Return  r% x; B# c8 j5 h2 @& o, X
        End If
1 F9 ^6 J- k1 z( I! p$ ~) T" v& ?
3 K/ F1 e! O- a  b6 \  j$ ^        Echo("  Load notes:")
5 @7 G8 \' X; Z$ p' S+ P" S
' T3 r  n8 w2 |9 a5 T% J        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
0 x: S# H$ F# {$ ~, b% R            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
1 t. V* T: T* j1 }        Next
$ a7 A9 o1 G( ~* V6 a% U6 ~0 {& d    End Sub
6 ^! X: F0 I2 \, c, f$ e
6 x; Q2 M+ X% @3 B# P7 r/ P    Public Function GetUnloadOption(ByVal arg As String) As Integer* j& F$ O) }  }9 K& J
        Return Session.LibraryUnloadOption.Immediately( Z) g. G1 J. P- g  K
    End Function1 ^( M0 Y6 z7 m  Y: L

, `7 Q8 D$ y% l2 w& d# @End Module[/mw_shl_code]
- E# S  x/ |/ }. k& p# Y* c: r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了