PLM之家PLMHome-工业软件践行者

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

[复制链接]

2019-4-12 09:06:31 2362 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
+ M5 [- p8 O4 m5 y, [2 OImports NXOpen
/ ~: I% e$ f- \) V6 H( N3 oImports NXOpen.UF; T0 @  {, u4 X4 Q. f2 u5 s
Imports NXOpen.Utilities  t, L/ Y. S$ E+ g5 `9 E* [5 [
') }. p+ }+ P) \9 j9 X
' The OpenComponents() parameter
- f2 d- h* B' X' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly6 L  [6 u8 O* s
' only opens unloaded components fully (see also PR-8406345)
. P0 H1 f7 `) `: s' Workaround: collect and open all components individually' c/ V$ f5 o4 Y2 c5 Y: ^; u) I/ W3 g
'
( ?8 w3 g* j% ~+ ^/ y, F. RModule NXJournal1 |) ]/ M4 i* C9 C, Z
    Dim theSession As Session = Session.GetSession()) N7 i/ ]* J( X  H- k/ N9 P3 k
    Dim theUFSession As UFSession = UFSession.GetUFSession()) j0 `" [, ]3 C  }6 g
    Dim dispPart As Part = theSession.Parts.Display( U% P3 ~8 D; g5 a/ m  T& c" F

& @, Q5 j, _# c  y; I1 @    Sub DoIt()
& F3 B2 \6 }# i1 T/ \        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)! q) Z' a1 b1 r  Z1 l" ~
        Echo("Number of Components: " & allComps.Length.ToString)/ _$ j. h5 A' Y2 V, I5 ?% H  P
        For ii As Integer = 0 To allComps.Length - 12 H' f* }- r$ T+ N0 p
            Echo(allComps(ii).DisplayName)
+ r. L2 b+ f" A$ v7 ~- K4 Q- i, A        Next
: e% v+ z+ I6 K6 C8 N# v
! M+ d/ u/ {! d        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading0 q5 E( n. T7 i
        theSession.Parts.LoadOptions.UsePartialLoading = False
+ F3 }: P. u, T) D+ f% e7 K  e; e
, z/ M$ L" W& Q4 E4 {' s$ q) p% ~        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
+ U( a& p& J1 q3 g        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing( _# K& o/ R! v. d# e
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
8 J  f0 P1 p0 W$ E" G' S. f2 X            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)" f+ \% f  c/ d; b
1 W% w& B* u/ [/ E# D/ o0 ^
        reportPartLoadStatus(partLoadStatus1)3 o: C0 Q: D; X, e% k5 u
        partLoadStatus1.Dispose()
8 W, @. [" W, J" O# w
% f' }" Q7 e- j$ T8 n  l  M, d        theSession.Parts.LoadOptions.UsePartialLoading = option1
! N8 Z! I* ?# x! y
. i8 J4 E* e( _- E8 K! I    End Sub$ P3 M' k& }" {6 {

3 \( v. S1 T9 T6 B1 d2 Z/ S    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
; D4 q! `( d: e' e7 {. w        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
8 v; V" k, u5 p. l7 a- ~        Dim aChildTag As Tag = Tag.Null
& m# d  U! B, |' l3 |/ y4 K3 j2 _3 s* k" J+ \1 R/ V. r1 t
        Do
  a3 t7 ]/ k# n            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
  G) t" b: p9 n& x            If (aChildTag = Tag.Null) Then Exit Do* B5 {3 Y, Z* ?7 p7 v, E2 @
% o, N: m  Y+ b! \8 y1 ~. H, e% D
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)$ e/ I/ J/ X% O) b9 _) C
            theChildren.Add(aChild)6 m$ }5 V! X1 S2 w
        Loop
& ?' j  ]/ L# A4 D' z; a- C  Z        Return theChildren.ToArray(GetType(Assemblies.Component))
( `3 ?" X4 V: d2 C
2 @4 p$ W- _  R; B7 b1 ?! a    End Function, ]# P6 m0 y& }; t$ l* [' d" j, w+ h

2 P5 D. i1 \8 i8 n/ Y    Public Sub Main(ByVal args As String())
' A* I2 l/ ]2 \/ R; o- `! w8 l        If dispPart IsNot Nothing Then- v+ L$ A0 i- _, [. F
            DoIt()
% Y6 P9 B+ g- R1 Y: t) ]            Return4 ?* D  _- o1 _5 y( Y0 \
        End If
* u; A4 e& T# A9 K) A/ Y0 e# t: H& ?; {$ [
    End Sub5 Y& b1 A9 m: e$ C

8 \4 u% \; f" C* N3 _* T7 q$ u* x    Sub Echo(ByVal output As String)
! H2 w) J; t) S* |/ ?" \( l, y        theSession.ListingWindow.Open()8 C& s$ h8 v* R2 @6 s. {8 L
        theSession.ListingWindow.WriteLine(output), }, e# _6 u6 }8 o  |5 q: K
        theSession.LogFile.WriteLine(output)
! ]8 B3 p  }, M& a( `9 V+ I    End Sub7 A5 D& }+ R( \, _* m
& D8 c9 |* K3 V" i
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
4 Q7 f, I" `9 o        If load_status.NumberUnloadedParts = 0 Then9 p# W/ \6 }2 B, }& f: L: D: Y! W; \
            Return, T2 x' q2 f& ]( w, @
        End If
% _9 ^+ Q& N. f. y5 I: V! X) e9 J% y' H* R. n
        Echo("  Load notes:")
4 W9 A1 A" w! @. S
* L+ A1 {! s* h2 X( E! B        For ii As Integer = 0 To load_status.NumberUnloadedParts - 18 p) N. s  {5 [1 I) `9 b
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
9 Z1 H, \* t% p        Next
- A& H+ n7 x2 ^$ a3 G4 @    End Sub
+ g( A( i# m% z7 B: o; k- Y$ R# j0 |+ D
    Public Function GetUnloadOption(ByVal arg As String) As Integer
7 N$ D5 ]' ?7 l( _        Return Session.LibraryUnloadOption.Immediately% O! L  v  D8 L2 J: H# o
    End Function  F- g! X2 N4 w* p% g1 l

/ F& F: s- E* O) v# ^4 g$ d( x4 pEnd Module[/mw_shl_code]
4 ^3 [, }( W+ i& S
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了