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 2120 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  L( A3 U" ^( e7 i+ c8 G
Imports NXOpen. |: I, O# e+ K8 p
Imports NXOpen.UF. L' f3 A4 w+ J9 W. ]
Imports NXOpen.Utilities
" x! \5 [) d! O$ G! n% V'
7 _) B5 C* a5 r% v  f0 s1 C# m9 Q' The OpenComponents() parameter1 _& B- s, l( R. ^
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly( l" t4 W* o% ?& c
' only opens unloaded components fully (see also PR-8406345)  a, i: B& p$ d# A6 Y
' Workaround: collect and open all components individually! ]7 O' `- M. g+ T0 R
'0 w, X8 y! R( I' @# I' B0 L7 S
Module NXJournal% A+ H% f1 k# t+ t) ^
    Dim theSession As Session = Session.GetSession()
: m0 s) J. o  ?1 ~    Dim theUFSession As UFSession = UFSession.GetUFSession()
! @: Q/ H; e/ J. A2 c0 P6 t( V" E4 M    Dim dispPart As Part = theSession.Parts.Display
% a8 K" P8 w9 w7 z) u6 m0 p! {3 t1 {) }4 O: k3 g: T2 @+ n. n
    Sub DoIt()
: C# m) E9 _2 a( l' ]' C* t        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
6 J0 W8 i0 w; {! }, x' e3 h3 Q2 k        Echo("Number of Components: " & allComps.Length.ToString)
6 M1 P! X; _, f4 c2 Y3 i8 H        For ii As Integer = 0 To allComps.Length - 1" {4 g3 T$ Q* P6 T3 p& o% P+ U
            Echo(allComps(ii).DisplayName)9 a  s4 w: S/ J: k* _4 R* ~
        Next
* R! O& I- r8 J  M- S! D. F# H6 ^# ~: K. [8 C
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading+ W! {  h3 W; T) @+ x
        theSession.Parts.LoadOptions.UsePartialLoading = False
2 _7 G" i. Z1 b1 ?; o# L) f/ X/ I. p' [* T# ~* m) s- U6 D
        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
+ e5 Z( A5 z% T& u' d" O  W: j2 z        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing$ \/ T9 d& t. a1 V8 v
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(5 C+ t& d' P3 Q" q3 B" i: ]6 h
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
0 J$ Z3 T- s% o$ ]/ W6 h7 ?  @- D0 r( S( k  j
        reportPartLoadStatus(partLoadStatus1)
0 o0 I+ M4 }% T4 f1 U' {# L        partLoadStatus1.Dispose(), x' j8 y+ n: t2 O
$ e$ d. s& \  E  I- L
        theSession.Parts.LoadOptions.UsePartialLoading = option1. }4 C/ x; i: P' f; `' D8 E$ g

) h) N" h; d6 m) v) V7 f  ]6 _    End Sub
1 t8 K4 ]9 C- v& ]1 x5 m+ i, q2 w9 D
    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()/ E& r+ ~5 {$ B  J7 c9 \
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
3 \# K/ T, N- W" U: \        Dim aChildTag As Tag = Tag.Null7 P3 Q8 Q* W6 |) Z

* z* K( ^; F2 G4 ?6 l. ^& n% |' i; J        Do8 S& K1 o" M4 I4 _& N  F" I
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
1 u3 l1 z$ t1 P7 ?. M  X            If (aChildTag = Tag.Null) Then Exit Do' ]4 [- V0 n, A0 }6 L) T
1 d  Q# R0 z8 D) _! c
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)  c, k1 ^# [% u# H+ N
            theChildren.Add(aChild)3 r+ V. E6 [3 d# V& ]
        Loop
" |8 ^# t$ s% l$ J4 p. h0 V1 H' }. C+ i        Return theChildren.ToArray(GetType(Assemblies.Component))
+ A: C8 @3 j3 N( ?6 a% x, \9 E% C' {$ |- \
    End Function0 L2 d# M/ b: M' Z
1 n" {2 K. J/ ^# b6 c+ h
    Public Sub Main(ByVal args As String())
( A1 a# [' K7 |) l3 N* q) _        If dispPart IsNot Nothing Then/ S8 B. E% N# j3 Y1 p7 j  n" X" k
            DoIt(). }% Y' V/ W2 L; D+ `$ v/ M
            Return
. A& t1 P& G+ ~% G        End If; |3 P! B: t3 M: ]# E1 ]0 v1 x. w

$ r/ `9 Q5 y7 \    End Sub
) I1 p+ @) z. `" v# W! W4 _
1 f# }' Q  V: Z/ w  P    Sub Echo(ByVal output As String), ^4 t$ d  k/ p. Y- q" n- x
        theSession.ListingWindow.Open()" L5 c# G. R9 w% w! i
        theSession.ListingWindow.WriteLine(output)
/ ^' P" H: u! K9 A0 H1 Q: v* }        theSession.LogFile.WriteLine(output)9 G" W; M. Q9 X( M* u
    End Sub
7 w! n3 u  |' X
6 n  P. J2 I) S) z  @2 m8 O+ @0 i    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
' z0 G3 g( R8 c6 C        If load_status.NumberUnloadedParts = 0 Then
8 O/ W2 x0 E6 \8 A- J. x+ s+ M            Return
! O% ~# v) }+ c4 X        End If& d% G% L) A7 Y, a
5 w6 [8 l* n' m3 _2 ?# R
        Echo("  Load notes:")
4 n! h2 N3 E; T% g' P
- F+ d+ s2 [2 C        For ii As Integer = 0 To load_status.NumberUnloadedParts - 19 Z0 }7 ?3 ]8 _# |1 ^
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
+ R2 X, f; \- \' ^  H1 m        Next2 o+ w1 ~  |. t: U# y
    End Sub8 p% |+ k) N; G. @, S7 w
5 t& ^$ A# j! R% a5 \
    Public Function GetUnloadOption(ByVal arg As String) As Integer
  x4 W& ~* F& U$ j2 D1 M- b        Return Session.LibraryUnloadOption.Immediately3 I; v! J1 F. X5 p( B; n
    End Function' j" |  A  u. }- C

$ |9 v( K. |' K& VEnd Module[/mw_shl_code]  X) B6 E! H2 _3 ?: _2 n0 c; V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了