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

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

[复制链接]

2019-4-12 09:06:31 2443 0

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82170
QQ
发表于 2019-4-12 09:06:31 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
[mw_shl_code=csharp,true]Imports System8 o# Z& e4 f: Y9 a& @
Imports NXOpen& Z0 x+ Y8 Z/ w6 F1 g
Imports NXOpen.UF
( H9 l" v9 v$ ~4 @8 nImports NXOpen.Utilities
5 \5 R! i8 d8 Q$ f' ?'4 j& t- A& F9 }
' The OpenComponents() parameter
& F( c- I7 D7 g' K' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly- @4 s/ t1 \7 [' s
' only opens unloaded components fully (see also PR-8406345)/ P% i  ~5 n: S3 ]7 N' E6 w
' Workaround: collect and open all components individually
0 z: t! q& C  T( ^'8 V. b) _& u# y8 {# v3 S+ [6 Q! ~. F
Module NXJournal
+ [  M: J- s/ p: _9 b    Dim theSession As Session = Session.GetSession()( u% e& A( R5 i
    Dim theUFSession As UFSession = UFSession.GetUFSession()
. W0 ^% L$ }- Z+ B    Dim dispPart As Part = theSession.Parts.Display
( C% f' a0 F+ h9 ]5 u
; E3 @! M# [: B+ d    Sub DoIt()
2 G& f! R9 O, N        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
/ t# a( w7 S- ?& C: V- K* E        Echo("Number of Components: " & allComps.Length.ToString)
0 p8 N6 E6 w' @; S: _        For ii As Integer = 0 To allComps.Length - 1
  p2 K! g2 ]& E5 w' P            Echo(allComps(ii).DisplayName)7 r' M5 q+ ], t1 U3 x& D, ^: W
        Next% ^- r8 |* {3 F6 v3 p1 ^9 l

( {, A$ H) q1 ]  Z& H3 R0 |        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading! ^2 Z. Z3 h' P- I7 v) u8 F
        theSession.Parts.LoadOptions.UsePartialLoading = False& t/ J1 x, M7 d& s9 ]  W& H
1 v+ ~* ]( O+ R5 R+ C* W' L& X* S
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
" n: {$ ]& Y: K  e% `1 H$ ?        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing6 ?- l4 o2 q& l, v- }$ ]* {
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
! |6 W5 e3 f8 r$ \            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)6 f/ \! E! K( a2 |. Q/ S, b

9 m& O& d+ k' c$ q" A        reportPartLoadStatus(partLoadStatus1)& l- ]' {7 S8 b/ v/ E8 x
        partLoadStatus1.Dispose()
) O( \& q" O# D! |; X% g% f9 h& ^7 _9 A
        theSession.Parts.LoadOptions.UsePartialLoading = option16 Y$ o6 }( [$ ^# N. u# ]

# c4 Q2 o/ P( U: i, W! i    End Sub
4 y: R' W: v( m# F  d2 P) o# Z3 M+ x- ?# D1 m' m+ f
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()1 s4 W1 C1 D/ q5 ^8 ]
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList9 D+ f! G" U: B4 {, R$ K
        Dim aChildTag As Tag = Tag.Null4 E+ A3 \2 j4 Z2 C! Y% U( h2 b

) A7 o8 v/ q" u. t7 a        Do! R* x) _* H, S# C0 W
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)+ Q! s+ d5 [$ K: t/ j6 @3 F, t
            If (aChildTag = Tag.Null) Then Exit Do" Y+ x: b: V. k

( P" L6 R! x' M            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
( j5 F' o* q5 t% {' ^2 V' i5 E% l6 \            theChildren.Add(aChild): A: t% x& o7 c. O' [/ O. n
        Loop0 Q9 v$ E- k/ K" f! w* E  P
        Return theChildren.ToArray(GetType(Assemblies.Component))
/ ?3 ~6 a0 Y- D! |2 u8 \' N, |& x; |8 }
    End Function
. U3 X8 {1 c" N3 w9 d7 F, {0 V9 }
    Public Sub Main(ByVal args As String())5 g  T+ r% r8 l* F8 A7 Z; [2 O) p
        If dispPart IsNot Nothing Then
" ?5 J8 x0 F: j' d4 D" z            DoIt()* M% K8 J0 @/ }7 }1 a) B7 }- E
            Return. w; `) x( P2 W' Z) U# u
        End If
+ l# y' y- B! y
# |- g. \, K0 ~; F6 t    End Sub4 h% o7 U% l' z6 ?6 X' r. L* j$ x" h
/ W* p$ `6 m  |$ M- G- S
    Sub Echo(ByVal output As String)
  l2 b- r8 F. m- ]        theSession.ListingWindow.Open()" d9 s. M( V- O' N8 a
        theSession.ListingWindow.WriteLine(output)
$ z2 e; N) y( `; @( A        theSession.LogFile.WriteLine(output)4 h9 Z8 F; y/ k8 P* t' q; f
    End Sub
) y: f4 m$ b% q( C. p
/ S. \3 N7 X" ?  J: p/ p    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
% }  R3 B1 y/ F  E        If load_status.NumberUnloadedParts = 0 Then! z; L' C* j: \
            Return
$ P$ f3 }; M% N4 F' s' d- S        End If
' E; @6 v, c3 @0 n/ D( Q: q6 k& h  ]1 \- V
        Echo("  Load notes:")
) l$ q& E# S6 A. D& m# h' l: |  E* G4 j: w
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1! u/ C- @  G9 v( v
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))/ z" c# z6 n( `0 h9 S$ t( q
        Next* E6 v, ?$ `! k$ f8 N
    End Sub
: Z1 W: m3 o: e$ T$ B- G* O3 M
1 i0 T2 y! q2 K3 n' n: C. ?    Public Function GetUnloadOption(ByVal arg As String) As Integer; o- t7 q7 ~; O
        Return Session.LibraryUnloadOption.Immediately: p$ a6 X* O1 ?! y* d; d4 q* D2 X
    End Function
6 D) s  `- X7 F4 ]
0 c5 C" M8 `$ O8 xEnd Module[/mw_shl_code]
, R. A7 [" a1 n+ B# Z$ a
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了