PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System6 o7 U7 `+ T- Z; M! d" \3 S* O
Imports NXOpen) H) _4 G. ^3 S% q3 e9 y
Imports NXOpen.UF
6 l3 N  U: J% f- E: Q( PImports NXOpen.Utilities
( n2 i2 N' J" o$ O# S+ \8 ~) o  n% b'
& Y2 f: c( h9 z) w! U8 S& h1 i' The OpenComponents() parameter
, W$ G& u& ]6 \+ u' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
' o4 s% |6 a8 z* `# L  V- G' only opens unloaded components fully (see also PR-8406345)( a1 y4 h: h+ E4 z* k  G0 t2 H4 Y
' Workaround: collect and open all components individually
4 L  j$ o# s3 n( Y% I8 a'
9 L& `( a+ f) {, hModule NXJournal/ j/ Y: q" S; Q. V7 }/ R
    Dim theSession As Session = Session.GetSession()
7 A8 e* ]% U4 n+ `    Dim theUFSession As UFSession = UFSession.GetUFSession()
' u* N1 Q1 f  J& b' _$ h    Dim dispPart As Part = theSession.Parts.Display, c$ K8 u: k( J8 \9 s( o

& |/ V0 b0 i! \0 e- q6 [- r, p    Sub DoIt()
* x7 ~( e& [1 W* M        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
  i( x6 c  b: h0 E% N5 N0 B8 r        Echo("Number of Components: " & allComps.Length.ToString)
& p3 U% G" d9 E2 w6 W        For ii As Integer = 0 To allComps.Length - 1) s9 I7 _( q6 b' |" m' u) o
            Echo(allComps(ii).DisplayName)
2 Z, D0 D$ Q3 @/ w. E        Next, E8 V4 s7 F: c  _8 C0 C- G+ G
, P6 R- V* L. l! L2 K  U  _
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading/ }. e2 Z& h/ d0 P( F
        theSession.Parts.LoadOptions.UsePartialLoading = False
4 X$ |) Y) Q) j9 K# V! i) G! ^
" x$ X2 b: n) x7 c* b. V& \        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
& V6 ^' h0 ]. u6 z        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing, M  r$ N  ^. u' Y' ^! h3 {
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
" h. k+ W& Q$ K9 [  L8 ?8 A            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
6 e7 \# b6 A! h5 I8 d) @# [3 B1 ^0 U" r" F: r1 n
        reportPartLoadStatus(partLoadStatus1)
3 ]' O- L0 f, i7 f        partLoadStatus1.Dispose()
- n) G1 ?  u3 _
' Z: j% x6 m3 W( U+ z, L+ S        theSession.Parts.LoadOptions.UsePartialLoading = option1. O) y" `5 Z* A' [1 `

- e. b$ I+ i9 o0 m1 f/ l    End Sub
* T7 t* B- ~6 \% ~& O! f2 L: z, T" t* C8 Y* l9 w' o; V! F! H4 V
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
" T  L" ^# ]- ^, w5 P        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
% R2 c' Q* v: I        Dim aChildTag As Tag = Tag.Null
. p. _/ o1 x; N/ E: h
( L1 r% F5 p4 a  x( h6 y        Do, X# _" X% Q: u2 v3 U
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)7 l8 P( q  S, \8 M% e
            If (aChildTag = Tag.Null) Then Exit Do
. n% _% }' V/ V9 B3 O: ?2 d- O, r" ]& N# t7 {
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)! f1 w) q, c' @7 Q) L) K& Y
            theChildren.Add(aChild)+ V6 N/ p+ l9 u
        Loop$ P# n1 A! b' D3 y4 ?
        Return theChildren.ToArray(GetType(Assemblies.Component))
3 p$ Q/ Y. S' t
# Y! c& t* T5 q1 B/ l$ m. m    End Function$ p! ?* f& g! j' ], {
/ _8 \8 y& I$ f8 o' M
    Public Sub Main(ByVal args As String())
: u6 s1 l$ b. r- @        If dispPart IsNot Nothing Then
6 k9 X4 H& T4 A1 U8 ~% z9 ~            DoIt()- m3 L, D% d. e3 f6 H
            Return3 v) n9 h- U& z! `& K% r# q3 ^+ m
        End If
/ L' O. @1 ]8 u3 W9 {. A7 i4 {
  A6 z+ k  Z, @3 U    End Sub9 L& v4 H* i& i' G+ B& b. Q
5 Q- _7 q! b* W
    Sub Echo(ByVal output As String)4 L, ]+ c6 q. O$ `/ c" t
        theSession.ListingWindow.Open()) u% r& T' r/ ~. d6 j1 i
        theSession.ListingWindow.WriteLine(output)
" E# @1 T% r! `" I  R) L( Q( k        theSession.LogFile.WriteLine(output)! A. w+ x$ P, _/ g# ?
    End Sub
% O$ N& R  y# ~  H  M- S9 d% q/ P/ S0 M/ d! X) l0 D* E/ ^- o  B
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)+ s8 o1 l) s& z( [" K
        If load_status.NumberUnloadedParts = 0 Then) S" A, Y+ T, q  z
            Return
. ]3 M( G( f" C7 k        End If' L7 R, f& _) ~( f
5 W$ ^& Q9 G# t3 J! Z3 i# F
        Echo("  Load notes:")
2 U* t! L' B% |$ u5 |( e( z7 R% ]4 {3 Y1 I4 @* m3 j
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
$ N7 `$ q' P- s1 k( ^  b            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
! ]+ o. P# H7 w" `        Next1 n' o# @  q) i; j  M/ ^/ T
    End Sub
% g; T. Y8 Z1 Q, u7 ]  D* Y( Z' W. Z9 w
    Public Function GetUnloadOption(ByVal arg As String) As Integer
. ]- ~8 ^& U# ~# ]0 G1 f        Return Session.LibraryUnloadOption.Immediately
8 G( O3 d: w# M6 C/ P* T; n' q    End Function) b4 S$ d, Z0 t0 D

3 c( @# j3 v; z/ [! p% j3 U9 r9 UEnd Module[/mw_shl_code]
3 L8 Q7 `, D2 W1 M5 I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了