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

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

[复制链接]

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

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

admin 楼主

2019-4-12 09:06:31

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

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

x
[mw_shl_code=csharp,true]Imports System1 `+ z. o' V! D9 s# l, Y
Imports NXOpen9 }- |; K  @: T( T" T
Imports NXOpen.UF2 F( @$ y9 V1 X8 M: A
Imports NXOpen.Utilities
7 w. ~1 G/ f" ]! v) g) ^+ l'
1 e2 i1 P$ n* |% R) X, u. ~1 [8 v7 Q' The OpenComponents() parameter
- c# L* i/ Q$ m3 Y/ o+ F" q0 j' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly8 o( ?- l' h- b2 @! Y: U3 B$ q
' only opens unloaded components fully (see also PR-8406345)6 u* K, o, t! D" `% e
' Workaround: collect and open all components individually' P% n0 j/ f# O% z* s' k. M) C
', G) J1 k& C! l6 {
Module NXJournal! X# L+ w. X: c, M! R
    Dim theSession As Session = Session.GetSession()
0 v: s; j3 g$ ]8 T7 D+ _% g7 C    Dim theUFSession As UFSession = UFSession.GetUFSession()* [8 w9 c. E4 E! o3 B! h* ?
    Dim dispPart As Part = theSession.Parts.Display: u( v' K1 H! T9 G8 J

) a& `6 s8 Q3 \+ z0 r    Sub DoIt()" p# m* q9 j& A+ C* }9 ]4 Q, R: r
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)$ \- t6 y1 B1 y+ G' T4 o
        Echo("Number of Components: " & allComps.Length.ToString)( f2 ?. l& p0 a) |7 V- W
        For ii As Integer = 0 To allComps.Length - 1
$ J- Z* B& H# N; b& V* P) U            Echo(allComps(ii).DisplayName)
" T1 V+ B6 m  ?2 V$ E: Z' j        Next
7 o, \+ b0 V1 y1 ]% g! o+ L5 C$ t
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
/ w/ P- W, ]! u6 j4 r( Z0 O2 X# c        theSession.Parts.LoadOptions.UsePartialLoading = False
. M' \( w" w. S
% ^: B. F/ d# n$ m        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus+ |' X+ T+ s( Y- q4 Q' d% T+ D
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing6 A5 r4 B: y: o+ c* J
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(# l! ^; Q, Q5 w) F6 A( f
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
! o+ Y4 B9 @4 r# |1 r; g: |2 \, Y
+ ?; d  U0 y- L, L4 p! w, U( [        reportPartLoadStatus(partLoadStatus1)
" c9 a3 k8 z9 A* j! u) |' p        partLoadStatus1.Dispose()& |( o% p% `+ M$ `9 j* |* b( {2 ?
# a  f; ^& A0 @' K' Z& V9 [
        theSession.Parts.LoadOptions.UsePartialLoading = option1; w* a8 S. p8 B7 |
9 D9 J" o9 n. l$ e* ^! M" ?
    End Sub
" N- K6 m( M2 t* X9 X
" ?1 h( L" J  |9 t7 y% }    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()/ _/ L# w- {. Z
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList; I$ C$ u9 B# I
        Dim aChildTag As Tag = Tag.Null
( [$ g! ?" r( H7 K, p6 ~7 D7 N8 h! L* z( |; b
        Do
4 T- ^5 W3 z( g# ~3 C0 }            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
/ I% P  e7 B9 e& _/ s: A! z            If (aChildTag = Tag.Null) Then Exit Do6 M' x, @- g4 q  z9 P
' Z. Q0 x8 v- S" ~+ Y
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
2 X9 y1 m- ?! S+ ^$ B, I& ~            theChildren.Add(aChild). N  k, J2 Y; j* z- j" c$ a
        Loop
& W! Z! ~0 j+ P" n6 \! J9 k  A; A        Return theChildren.ToArray(GetType(Assemblies.Component))
8 F4 D' B# p1 b8 e
. R. X' {( g9 R' I8 j1 m, ^    End Function6 h8 l, q6 t3 G/ k, r( G+ M
4 j1 f: Q" E+ N: p
    Public Sub Main(ByVal args As String())2 k' _; d' o+ n0 S
        If dispPart IsNot Nothing Then
7 z7 c3 ~: V1 w$ p' M8 P            DoIt()
7 ]1 X1 j' l" D. }4 f% A            Return
/ D+ L; u$ H; Y6 B        End If! Y6 p, j# Q  `! D" v$ n( `  `* e

5 W4 n8 u; h, o* {$ D: R( w3 ~; @3 g    End Sub* t' b+ D' Z2 h0 ~9 Y+ W+ e3 u

( H' P3 a' F9 _' Q) f, \& _* m    Sub Echo(ByVal output As String), g: _4 g6 J2 ~! ^1 w" p
        theSession.ListingWindow.Open()
7 `$ `2 _- u7 ?9 A4 c0 t        theSession.ListingWindow.WriteLine(output)
/ _# _3 O2 F+ Q( Z        theSession.LogFile.WriteLine(output), `3 h) x& m& y; `  r* U/ E
    End Sub4 ?& Y$ ~1 \5 h  m

2 b! N, L1 u- @2 d5 i    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
8 W4 n0 M/ G9 v& s        If load_status.NumberUnloadedParts = 0 Then
4 j) Q* R7 D2 ~6 K6 m            Return
1 O, k4 k8 @# C        End If; v2 U% s' P$ A4 T' B/ f7 y: d: g/ j
) t2 w# N4 t! w* l
        Echo("  Load notes:")
7 x5 o6 A3 H; y* E% n
$ C! S* w% S3 A3 A4 x' c6 N! n        For ii As Integer = 0 To load_status.NumberUnloadedParts - 17 P& Z9 c* P7 ?) B3 U+ C4 G
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))) C1 X+ {7 s/ ^: c2 g
        Next# Q. ]+ a' T9 n0 [8 [) c6 H
    End Sub
7 Z; _# h% b7 @9 [% ^7 g1 D, k; [: u* h9 X/ H9 U% i: C( a& a
    Public Function GetUnloadOption(ByVal arg As String) As Integer
5 f) F3 w% S" x2 h        Return Session.LibraryUnloadOption.Immediately
; l6 Q5 T7 v, U0 m; Z    End Function
! w# v* G$ B) _
: T4 q' ^) }+ j; b4 C1 b# \9 ]/ REnd Module[/mw_shl_code]4 M5 z! F  m0 O9 l
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了