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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
[mw_shl_code=csharp,true]Imports System; B; `3 U! w6 ]. m- \
Imports NXOpen/ @; |; z0 a' u
Imports NXOpen.UF
: p9 R! O! @4 w! K1 R1 L8 JImports NXOpen.Utilities, r) k5 V" j6 @; ?) i7 P* K- J
'' B7 n; S2 p9 `! u( t, h: A) Z9 c
' The OpenComponents() parameter
3 W& y9 V- x' p" y9 n' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
8 c2 |. T% d% G4 S8 ~, x& a1 U0 f: s' only opens unloaded components fully (see also PR-8406345)
5 p) y7 u$ x: u1 l' Workaround: collect and open all components individually
3 G. z) ~; m; x4 j9 k'
# ?0 P# h3 |0 A/ W% RModule NXJournal
9 h: {0 Q9 N* P7 l) _; Y& `  q# z    Dim theSession As Session = Session.GetSession()
4 D2 K# s: n3 P; A5 \+ s! M  G    Dim theUFSession As UFSession = UFSession.GetUFSession()
' B" J/ O  ~" e  [    Dim dispPart As Part = theSession.Parts.Display, D2 P+ i0 k7 w5 d9 p- F

- y( o& S, y' S8 S    Sub DoIt()
# Q2 m: y6 L* K. T        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)6 n' D5 Q' M9 F, i$ d9 u  e8 ^
        Echo("Number of Components: " & allComps.Length.ToString)
8 e3 o% P' G% r        For ii As Integer = 0 To allComps.Length - 1  Q2 a% t, O" f9 V1 o; ^& P. {
            Echo(allComps(ii).DisplayName)
; `1 e' W; F( g9 m$ l* a+ Y/ w        Next7 N( t7 r, y$ v& F

) c) s# N' y+ w% {: W2 m        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
- v  N. H& V" A7 a3 N8 S        theSession.Parts.LoadOptions.UsePartialLoading = False
5 p% p3 t$ N) _% ~# X; o
6 D$ h4 [: M" b% h% l        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
, ?. n8 ^7 i0 d# i6 T9 ^* }        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing' }) }/ J6 v6 K$ p2 f% ?% s& {7 R
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(( o; y' K) A7 \; z. f
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
& Q# v: |# Y: x1 e# {2 L
5 K. o$ I1 ]6 ?  \        reportPartLoadStatus(partLoadStatus1)' b' }+ ?/ D( x8 q/ Q! z, a/ _
        partLoadStatus1.Dispose()* E  S1 B: A8 g! b! Q2 t( L

( n+ x! f+ s1 U) L. a' r        theSession.Parts.LoadOptions.UsePartialLoading = option1) |% i: b& a5 H* z7 ?
( x( a! d( ~" |* x: u2 o
    End Sub
, N: g# `1 w$ C1 K1 H1 \& w+ E
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
2 P. c# p- }, K& v6 B$ ?% `        Dim theChildren As Collections.ArrayList = New Collections.ArrayList' q% J# E. N, i) c0 a: u/ M7 p
        Dim aChildTag As Tag = Tag.Null
) p: M% H7 R7 i4 l5 t1 v% g& q- j3 L. i  E2 C* D
        Do* B- i1 _9 w; L. t; L
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
8 I( Y7 o. K# J  ~( W. e            If (aChildTag = Tag.Null) Then Exit Do
1 B5 [: K* l. K3 K3 k- J$ u$ k: P5 _( C
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
& E% U$ a# q0 E% D  W8 x; T            theChildren.Add(aChild); U+ _! C. ^! Z
        Loop
' s* T) \4 }4 v# F9 w        Return theChildren.ToArray(GetType(Assemblies.Component))
2 y3 B2 |$ d& @9 G5 `3 ^% [1 d( Z
  r% D$ b4 u+ d4 _* }5 S6 w    End Function1 n* o9 _/ F1 B) U  X" J6 ^5 v

' a- Z8 B. Y# ^9 C& W    Public Sub Main(ByVal args As String())
- A' d) L+ t4 r6 i% [( K: H8 S        If dispPart IsNot Nothing Then  p1 Q4 V( d6 l4 `7 H! ~
            DoIt()( Z2 Q& N) Q9 J* D
            Return
! u) P1 p8 `7 C- l6 i        End If) ?- \$ h6 d0 L; W

) B8 u: N4 E  Y. ^2 w    End Sub) v! d% G% s" C2 @2 f8 F( Y, z
; G# E5 \7 t9 L( u6 E+ Q' Y
    Sub Echo(ByVal output As String)
+ I$ p  [3 w2 ^( p        theSession.ListingWindow.Open()
* f2 L( Z" T  d        theSession.ListingWindow.WriteLine(output). X8 z; r/ Q) `0 c0 V& C
        theSession.LogFile.WriteLine(output)& j- U2 I* k* Y
    End Sub
  d+ g1 ]; `7 k
2 R4 t% S2 K9 R: |1 c& A    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)3 l% m7 B7 A  p
        If load_status.NumberUnloadedParts = 0 Then
) u2 i; L" p3 J& x# I, Y, ^            Return3 j9 h; u& ]! D! [
        End If
3 m  J  ~3 T0 z. D) \1 a0 P6 Y3 N
        Echo("  Load notes:")+ f# F& U4 S6 u  v& v1 Z1 t, W

- n9 X4 ^: T; m- H        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1& c/ F5 [/ C: E  `
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))  G7 T) P3 [( J! g1 G# K
        Next
3 B, d8 M0 x; G2 v/ U' w, \! N    End Sub
; I9 N- `/ R, D- j' F" ~% x0 k
* @6 M$ P! |# Y- @' L4 b: U+ y" o    Public Function GetUnloadOption(ByVal arg As String) As Integer" o+ {9 w! U/ p" p& \) W* g
        Return Session.LibraryUnloadOption.Immediately" K+ k) K7 V4 U
    End Function) O1 x: {% [, j$ c( ^: z' `

, j, H. G8 p0 {0 r+ Q6 w% l9 l' E2 t$ iEnd Module[/mw_shl_code]) H$ y1 U/ R3 j% x
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了