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 2114 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$ _+ t9 B) H# f1 m# }9 q0 I# h- D
Imports NXOpen9 U) ?7 N: O6 j3 ?# ?* ~- l
Imports NXOpen.UF
* [. F+ b* f2 |- rImports NXOpen.Utilities
' V; {8 ]# C5 c) ^2 u) V4 {$ g! N'( o6 Q( Z9 M5 @% i7 X) P- B8 i
' The OpenComponents() parameter
/ ~9 n  h1 }3 a, [+ s" o- v' Y: H' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
$ j  {0 N) n0 u4 W' only opens unloaded components fully (see also PR-8406345)5 C; Q) s% F9 y7 W7 y8 I( E1 P, J& Z
' Workaround: collect and open all components individually* }8 B  s  y  u$ t& A2 L6 C# y
'+ `' ]8 g' e4 k' Y7 G
Module NXJournal) r0 `3 s8 l5 _; v! \& [
    Dim theSession As Session = Session.GetSession()# O! I, \# X$ t5 r' f  v: @0 z
    Dim theUFSession As UFSession = UFSession.GetUFSession(). M( ^& ]' \+ u4 X* k
    Dim dispPart As Part = theSession.Parts.Display
& z( a! X( Z8 z$ N
# _. z* e8 D9 r; U5 q+ a2 [    Sub DoIt()
; i, R$ Q  L: ^: m        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
# m# B" c8 L2 y7 [# a        Echo("Number of Components: " & allComps.Length.ToString)0 B1 r0 W6 l# ?) T( A
        For ii As Integer = 0 To allComps.Length - 1
1 A( E! w' q$ u! F2 i            Echo(allComps(ii).DisplayName)
, ]( @) g7 k8 V# R4 `1 r        Next
  h! `) b* \& |2 b' |9 r& ~$ g0 A5 B* |' k$ h( s- ^' p  z" t9 r; H
        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading' s& m8 I; X2 z3 R% w4 k' G3 X
        theSession.Parts.LoadOptions.UsePartialLoading = False
4 R2 J- @) E( @+ }' w. \! v3 e
6 M' U; A( a" t, b        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus5 j- r* I4 S$ [- N9 |
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
9 T# {( z: L5 }' [$ l        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(. w& o9 ]9 }5 \! }9 u# ~
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)
+ [& y1 U1 W* _5 {
& ~: J7 V6 t8 b/ Z' W) D$ J        reportPartLoadStatus(partLoadStatus1)" ]; F& X8 o) ~! I6 _' Q
        partLoadStatus1.Dispose()/ _& X# x' s3 m2 `9 l

7 `# v7 Q/ ?. L- @6 J        theSession.Parts.LoadOptions.UsePartialLoading = option1& s7 K2 q7 f$ k6 `
; Z2 o  k& c8 L3 g+ B
    End Sub
7 g. x) N6 F4 r0 A5 w- P  R) l
' j. ?6 Q, Y3 _$ L! B( _    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()% T5 o, l* o+ ]( \( C
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
) r' ]& q8 P2 W* J* G( c: S        Dim aChildTag As Tag = Tag.Null3 C& p9 ?# H- K
/ a2 F6 j. m( j/ k# m( t2 V
        Do
7 y- s. X6 y" a& W) R- V# R            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)" f' a/ S1 D# `' h7 h' P5 H
            If (aChildTag = Tag.Null) Then Exit Do
* b+ D* s1 w$ x5 }8 k7 M5 T  r  b: z& s4 @! ?2 x% x) j& N
            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
8 W" M3 o( J% n1 @3 [            theChildren.Add(aChild)
% ]1 ~. w! S! M' v3 i5 a! \. o* ?        Loop
$ x# H1 J6 l# V& b1 g: J        Return theChildren.ToArray(GetType(Assemblies.Component))
* M& E- Q/ r3 A% B
$ n+ E" B; R: T- }7 H( ^; O. ~# S    End Function9 b4 ~. P  v4 H0 T( i* F* b

, r1 R7 b& @( C0 {' U9 F' t    Public Sub Main(ByVal args As String())
5 L" x5 t* P5 b! M        If dispPart IsNot Nothing Then/ M9 l0 h( n( {3 i/ U  H" R# F
            DoIt()
. v& ^4 d+ K6 w1 |            Return
; w9 V& Z$ E2 U6 Q        End If5 C5 G0 b# _+ i, t

( ]5 W: o: t, D9 b! z    End Sub
+ D/ l/ n7 O4 J, f
  p& R8 b9 O* W    Sub Echo(ByVal output As String)
+ J/ F6 D! r7 p. Q        theSession.ListingWindow.Open()1 c" v6 a7 j8 M1 j9 S
        theSession.ListingWindow.WriteLine(output)
/ m( |9 d0 {# n, r2 y4 Y        theSession.LogFile.WriteLine(output)
. f  Q* K6 {( K    End Sub
! Y: Q0 s  z+ W
$ x% Z1 R7 b6 Y) ?    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
, G$ [% X/ `/ q1 `4 R6 z* l& f' I        If load_status.NumberUnloadedParts = 0 Then
" C. u! M0 }+ S* f" k' L            Return
9 h4 u6 ^2 R/ b; j6 n4 @        End If! j3 V3 U$ f( W7 X5 J3 S7 R% f4 }
6 T* t- R/ f5 @( K; w+ {0 n- c; J
        Echo("  Load notes:")
7 Y4 [1 s& j. O+ _6 S8 C5 n: Y# o$ N% i# ], e, d
        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
5 K7 E9 I* i( k9 K4 `9 R6 Q            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
# a9 z2 _* S7 D5 l$ g2 C7 q2 Y        Next
* s5 R; T' O0 V  K+ v    End Sub+ K9 _8 ~7 o/ m) H! k5 L
2 D, ~# u* h. C; x, C( s
    Public Function GetUnloadOption(ByVal arg As String) As Integer" y, H+ L# [; v; R. s/ j
        Return Session.LibraryUnloadOption.Immediately- a# Y! V3 K! p6 t
    End Function
0 u. F. a* k% S, N* `
+ B  r  `  F8 }- N' U. d: U% dEnd Module[/mw_shl_code]
& ?; y# q. w4 U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了