PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

[复制链接]

2019-4-12 09:06:31 2119 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: E+ n6 l: {0 H- h7 S
Imports NXOpen% y0 S, Q2 ]6 c, A' K, W& g
Imports NXOpen.UF
2 i5 K1 G+ S. L8 I, c3 |Imports NXOpen.Utilities
# A( Y8 d. }8 m( b% r: L'8 X( c: H! D1 c9 \  x
' The OpenComponents() parameter4 }8 ~  T. R1 o
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly  R7 _" D+ C. B1 L( `! v8 A& i
' only opens unloaded components fully (see also PR-8406345)
  A2 Z. C8 G8 f$ D& p& E' Workaround: collect and open all components individually
/ G2 A$ ^7 x  }  B$ D9 H'+ T' r' f1 I7 F0 R1 ^. z1 ^
Module NXJournal/ o, B; x4 a$ G: h) t& K
    Dim theSession As Session = Session.GetSession()0 ]# O* m; e4 y! n2 V
    Dim theUFSession As UFSession = UFSession.GetUFSession()7 p% B/ Z  L/ \, i8 Q5 R3 X
    Dim dispPart As Part = theSession.Parts.Display
9 S: f4 n# @1 F( n' i7 k
5 ^  _, B; f: R( L) x$ v    Sub DoIt()1 t1 `6 N0 \8 X
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)  t! P. B; h* d9 }3 u
        Echo("Number of Components: " & allComps.Length.ToString)% m: h9 q& a5 p! H0 O4 q% P6 a
        For ii As Integer = 0 To allComps.Length - 1
6 B4 y8 u3 C$ b, ]+ f& [            Echo(allComps(ii).DisplayName)
( Q  X7 U5 j3 i, s- K2 e        Next
8 |( P6 d1 k. n: l4 e7 G7 i! i
  m$ U. K2 i& g) [        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading+ f# G2 o: m+ N% ~3 d0 `; K' m
        theSession.Parts.LoadOptions.UsePartialLoading = False
5 B7 S" G# h0 k% J# K+ C3 @
. a: [6 \- K3 T+ {+ X( E        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus6 D0 y5 t8 ]. V) z* d& W/ f
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing2 u  {4 o; V; |7 b) Z1 W& _3 \' g
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
4 t6 u2 m- d1 i. ~            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
4 Y3 h9 q( l7 V* B/ {  m& e
) _0 K! ^  D; R7 G        reportPartLoadStatus(partLoadStatus1)
5 w) S0 @$ f/ J$ i( S4 I! n        partLoadStatus1.Dispose()1 d$ T) f3 P; e; s+ N7 D

: `! v& [5 ]9 I; H- Z- G9 B        theSession.Parts.LoadOptions.UsePartialLoading = option1
% s; v, ?+ Y) \) ~5 W0 v/ D
3 a  b# d6 y( [8 f    End Sub
( [5 D7 v$ ?6 a- o* |0 ?8 O# J  _5 X* x( }
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()9 l$ |' p5 t! s2 A. f( ]& T  [3 Y  h2 M
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList/ g  w3 T6 U- K. x* I
        Dim aChildTag As Tag = Tag.Null1 Q9 o0 z* T. }( |

9 w/ o0 `0 M  T/ [3 T        Do
! g4 d/ \4 \) p& H            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
0 Z# x9 ^, }# Q4 w* X! v. F3 p7 J            If (aChildTag = Tag.Null) Then Exit Do
! M" r1 l+ I" p, S; Y6 F* N( [: C. w  h# g
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
9 a! _6 m9 j) l3 e# \5 v0 E( g" a7 c            theChildren.Add(aChild)# t# ]7 e. `6 d6 D3 i0 T
        Loop4 j# d' O/ b( V7 ^" I
        Return theChildren.ToArray(GetType(Assemblies.Component))
5 C( {& f0 M( J1 Z4 e, @
/ a8 W2 T) u1 M1 F5 x    End Function
/ A% E4 U' J- x" ~4 l+ p+ p" y; F6 p' q1 B: c
    Public Sub Main(ByVal args As String())8 i6 U  G/ j+ q, D, D7 W  G  ]5 s
        If dispPart IsNot Nothing Then
; c  V3 U- I3 l! `* M            DoIt(), b+ S$ h* R- `
            Return
% }! A- F; g3 R- h% t7 G        End If
1 M* l$ W0 }& Z& C& @  c( T! a* h7 W/ U3 n4 m' F
    End Sub0 [; \5 G( |% j2 @. S9 J

% B' k9 S9 J" R+ A! \2 e& M    Sub Echo(ByVal output As String)
- q2 y  `+ Q: [8 j, a: x- U, R        theSession.ListingWindow.Open()6 @5 u% V' R$ L# y- \
        theSession.ListingWindow.WriteLine(output)0 G7 J6 V4 w* R- U
        theSession.LogFile.WriteLine(output)
: M& i. f' C! @+ K- B: y  c    End Sub1 N9 z9 w) Y0 Q- ]2 X
. ?  [% K0 }. S) ?0 y
    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
0 X7 O0 y* S& v# n* O        If load_status.NumberUnloadedParts = 0 Then4 r4 e! q: C0 T( {  O, C1 J
            Return
+ J: C# z0 P0 T. x: }2 R        End If" n. F- Z& {0 u" f
! `+ Q6 f: L0 J% {
        Echo("  Load notes:")
$ F  P  U+ A, c, t" @
/ o8 m/ ]% e- [5 e        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
1 \2 s4 E* ^7 [( o6 V" J# z            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))! Y4 Y: F  R9 \3 n8 G. L
        Next
. Z* G5 B4 [1 N& K' |6 {    End Sub2 b, _2 A6 N0 A' T+ y$ q

! n+ t8 R( W  b  ^1 U* x    Public Function GetUnloadOption(ByVal arg As String) As Integer
" }: O3 A4 u' Y7 n3 J* `+ W6 D2 A        Return Session.LibraryUnloadOption.Immediately
% G7 v9 h% E* d: R. z    End Function$ J3 l2 H0 X& }5 ^2 L- x: ^. w

: F2 ~& l! x8 G6 UEnd Module[/mw_shl_code]4 l; G& c* u1 p7 e
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了