PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

2019-4-12 09:06:31 2441 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+ a" l" ^5 T/ g1 O; q- v' K
Imports NXOpen
. c+ V) O0 K  VImports NXOpen.UF
( t8 O8 |8 Q  e- ~/ \Imports NXOpen.Utilities: ~" \" R( N: w
'. V6 M0 j/ u' j4 @
' The OpenComponents() parameter: Q5 r  ?! `. M% l- `. D* b
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly) {0 B7 j) A. f+ l' G% `1 F
' only opens unloaded components fully (see also PR-8406345)
% E( }# Q6 u$ M5 `  b7 L# y) Y% y/ Q' Workaround: collect and open all components individually
  U: I, i! a5 I5 p' S& g" G4 C'
0 @! {& i$ M- s3 b" ]# ]Module NXJournal8 z# T! J( ~/ F/ G6 e
    Dim theSession As Session = Session.GetSession()
: U5 [( L; b: X3 C    Dim theUFSession As UFSession = UFSession.GetUFSession()6 U* R. q$ ?& R6 ~
    Dim dispPart As Part = theSession.Parts.Display& l' J6 A" n: S; ^/ @/ h4 @
7 v4 {* f1 B% {/ {$ w
    Sub DoIt()
+ G- _, D2 q8 c# b        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
8 s% t* [  d& k: O! `6 D3 U        Echo("Number of Components: " & allComps.Length.ToString)# w4 G& V' M9 C+ j) l9 j
        For ii As Integer = 0 To allComps.Length - 1
- q; G+ u# @) ~            Echo(allComps(ii).DisplayName)9 m, _0 h. Q* L& Q& `
        Next$ M- Q+ d* E6 u- e" G7 ~9 o
3 W, R  ~& a9 O
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
$ J8 h2 \/ ~8 }        theSession.Parts.LoadOptions.UsePartialLoading = False% \7 u: }1 ?/ u$ o: F, [9 k

+ c0 t$ P. o* U  U- x! \* b0 Y. L        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
; d' g: f3 P- Q" q4 I3 W  O  r        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
+ P' l: M2 P3 z' j; L! K        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
# l3 _  N" s1 d            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
7 j9 L- ?9 Q) Y# O7 N5 s) f$ V" [5 e4 T; p% J+ z" C
        reportPartLoadStatus(partLoadStatus1)
! p  x) c& S. ]9 S: H- g) i        partLoadStatus1.Dispose()3 w* U6 T5 F6 x& U
( G$ \1 C4 y" G5 K* t: y
        theSession.Parts.LoadOptions.UsePartialLoading = option1% P% s1 j3 n4 s3 B2 U
! x% b  D- U, x
    End Sub$ `! z) A$ y( D
# S1 O/ N  ?! s8 b
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component(): P  R) G$ m  }3 |! G
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
* _1 L$ k' `9 C4 O        Dim aChildTag As Tag = Tag.Null
+ j* r5 v$ x; A+ Z% I% Y* F
4 z# n5 B  D( I% u! E        Do
: _9 R) u/ y6 L, V  g1 H            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
5 c& V5 L1 F6 V0 {! s1 J$ g            If (aChildTag = Tag.Null) Then Exit Do
  v7 z  m0 M; a" W, V- D" o% H! _' f& c/ \% C' Z
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
: e' X" F- ?+ X2 v6 _: u- f" W9 w            theChildren.Add(aChild)* }, w2 X2 B: w( v8 @
        Loop
) J* u) S$ O5 i/ G        Return theChildren.ToArray(GetType(Assemblies.Component))5 K' H" b8 A/ W) @2 H

  z) m3 q' |0 j9 h    End Function% j) Y/ W/ Y- h: S% i: j
9 D. u( _% S$ \6 Z
    Public Sub Main(ByVal args As String())7 [$ l$ W& l# D' M2 p. S- M! c
        If dispPart IsNot Nothing Then4 D. Q. t: x1 U: W) L* X( e
            DoIt()) Q$ p3 e; c7 y* F1 t
            Return
1 \; L" o" [- ~& M$ ~$ W        End If
" _8 E1 x1 }9 u3 L5 |2 s1 ^" K: F1 Y1 h  F! G0 M
    End Sub; H" k' v4 _/ L' B; ^

2 J- Q9 N/ `. @    Sub Echo(ByVal output As String)3 I, t) u+ q; J" e, }4 t
        theSession.ListingWindow.Open()
9 @8 [0 V7 S. Z/ H        theSession.ListingWindow.WriteLine(output)
! v" T% Y% Y1 O- D, A6 {0 U! _; T        theSession.LogFile.WriteLine(output)
2 a( X# [( X4 G! ?: o6 x4 R4 B    End Sub
* a8 P  L, |0 k" R$ t5 _- n2 c2 j" |# J2 R$ T
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)* A: v, a9 Y+ F# P) n
        If load_status.NumberUnloadedParts = 0 Then$ q3 W7 x( b* L+ f2 B% p; p) c
            Return$ r9 d( t& T2 L% v' E5 m: y
        End If
8 m+ i  Q% }6 ~7 _9 T* v1 {
) ^! N( ^8 o" S        Echo("  Load notes:")
& K+ X" `; G) L$ c: {  x8 n( O: C( r3 {$ v% Y* X
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 13 `4 h8 [; S( @6 B& M
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
1 L& K8 u) W; t$ h' C) V8 I        Next, R. K' ?$ Z- [- s1 |
    End Sub. @2 ?+ z, }# ^8 ]1 i
4 c0 ^! t/ |! ]- x4 b
    Public Function GetUnloadOption(ByVal arg As String) As Integer
+ J$ J, b* f0 y7 g        Return Session.LibraryUnloadOption.Immediately0 c. x; F/ d" E8 P" t! J
    End Function5 u0 M7 P6 a% E. |7 l& N' d

! e8 p9 G( e* X3 cEnd Module[/mw_shl_code]* H. b8 G5 Q% {0 W4 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二次开发专题模块培训报名开始啦

    我知道了