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

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

[复制链接]

2019-4-12 09:06:31 2369 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
9 ^3 X7 K# `+ a" P: @) c2 |4 j. xImports NXOpen
9 P' L1 {0 e# o8 BImports NXOpen.UF
1 x+ h3 b9 z8 X9 V0 X) b" ZImports NXOpen.Utilities
+ M  Z* s9 A: @'
$ C5 X& u& X6 Q7 I' The OpenComponents() parameter' h, ^. R% q" Q* X. ?
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
# _, M4 t5 ?. v' C6 t# P* E' only opens unloaded components fully (see also PR-8406345)
$ R# g  M( G# z# H4 @' Workaround: collect and open all components individually# k* ~  z) ?, M! I* V
'6 C. `0 O7 Y" K, f: |. m* x2 {5 n
Module NXJournal
$ `! G+ W! l& Z    Dim theSession As Session = Session.GetSession()
' R6 F  E& _* e% X& U  W. k    Dim theUFSession As UFSession = UFSession.GetUFSession()! R) b) j: p8 a( P# H4 ?- [: d
    Dim dispPart As Part = theSession.Parts.Display* c" e+ |' f0 q. ~

" j: T0 n2 T5 U* ^4 O0 A1 r    Sub DoIt()) h: a" g9 d9 B# Y1 |
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)# O! ?0 C: R; z8 V/ y
        Echo("Number of Components: " & allComps.Length.ToString)4 w7 l5 ]  r1 n: o2 h3 B; v' ^
        For ii As Integer = 0 To allComps.Length - 1
4 l  m6 {8 F) S) X/ Q4 j  U            Echo(allComps(ii).DisplayName)
  u5 I/ m6 k3 |. ~" P        Next8 o' ^$ q: Q$ H
' z6 ~0 t  d) F7 v/ r
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
0 b  B9 m! A# ~8 @' T2 W0 F        theSession.Parts.LoadOptions.UsePartialLoading = False* C" {9 ?& B2 j. H
/ z) U5 O, {- _4 e9 [( Z
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
  N1 ^/ ]: j2 h  A        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
# I' J" s, [  B8 ?4 u) I0 T        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
9 [) [" d% }( B/ W% m" `- ?3 f- \3 F            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
: f. u4 x% y$ M$ a
& ^2 |3 T7 F1 c1 C8 X) f/ {        reportPartLoadStatus(partLoadStatus1)- P+ j) `+ |: T$ J- L
        partLoadStatus1.Dispose(); ~, s, g4 u7 `" T( E5 ?7 ^
  S3 }8 G$ i. `8 F# _2 D# L
        theSession.Parts.LoadOptions.UsePartialLoading = option19 S; Y$ h' @( o8 z, @9 i# J
* K. G, T0 W% {4 Y
    End Sub
4 F! d' |9 l5 O7 A, _/ X; t% l2 P2 C7 r! @. B4 H5 I
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()4 L. d& X) P/ V1 Q) P- M! @
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList* g2 t3 A: U9 E. \- c
        Dim aChildTag As Tag = Tag.Null
# ~# }7 ?% A) Z8 m) {6 W
2 l) U  b) E, c7 {4 F        Do
5 _2 q/ @+ H8 B' R3 M/ r8 H            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
3 L- h& k3 U7 {1 u+ n6 s9 P+ V2 E- s            If (aChildTag = Tag.Null) Then Exit Do) p: u; V  R; H7 D6 l  y' Z
% M0 j* p* u# w- h
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag), h) `3 W4 F0 @. S% q/ [5 L
            theChildren.Add(aChild)% b: N; L" C0 Z( ~0 J3 d' ?) c5 F  I
        Loop
  U$ J, [7 _$ W, e4 \  D        Return theChildren.ToArray(GetType(Assemblies.Component))
3 H* S& p  K* q' N5 H+ d# p" W3 V, U- o, d* s. e0 i
    End Function
& K8 q6 \( T9 [" x( n0 `$ p. k4 ^8 |, B/ J
    Public Sub Main(ByVal args As String())
6 x( c$ t+ T  t2 {$ P5 @1 Z        If dispPart IsNot Nothing Then
+ S! S4 ~. h/ J8 a$ ]/ f: ^6 G            DoIt()
/ S* F, R& z* c' ?4 B  _+ i            Return
' e! z( S. \. {7 c: z        End If
! }# H& a7 B& ?- `5 P+ @  F& [( D2 r- X$ L  B! \4 [: b2 _/ s) q6 U
    End Sub
* e  N) B: X7 K% H' J1 i" N
7 F1 W) i& L+ h% t! E  x    Sub Echo(ByVal output As String)) |/ ]+ C+ a3 a  ^# |( L
        theSession.ListingWindow.Open()9 c; s2 L2 x0 ^: N
        theSession.ListingWindow.WriteLine(output)" ]; F) R7 T  n
        theSession.LogFile.WriteLine(output)$ X& A$ S; l$ i, d
    End Sub% ^' @# f" A' d/ E$ S

) T, Z4 C- B( S    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
9 N. j* P& Z0 J- |: s: P        If load_status.NumberUnloadedParts = 0 Then
7 ~8 t$ g5 R! K9 Q6 f8 {            Return
7 d1 s+ a2 V! f$ c        End If* F) b3 k1 |; \5 E  V% \) J
+ I* ^) Y* B9 b" h
        Echo("  Load notes:")8 ^0 J4 ^3 b, X2 D, D) z

# g0 o9 ?0 e* x& j6 s# p        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1$ C8 L1 K) l7 h4 T# U9 l" E) C4 G
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
9 T6 c' Z% [/ l        Next- B, l0 N) `$ `- e; e
    End Sub% N# n/ z7 N4 W/ c" g  }- N0 P4 B

4 W- V' K; S5 D' D& f    Public Function GetUnloadOption(ByVal arg As String) As Integer
4 \. X" ]7 [+ u" y; b: }        Return Session.LibraryUnloadOption.Immediately
3 W. w- o. r: q: C! c    End Function
9 Y$ ^0 w3 `! ]9 E& h
3 J! Z5 r. F. m( xEnd Module[/mw_shl_code]3 ~# F) k; h% S$ [8 h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了