PLM之家

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

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

[复制链接]
admin 发表于 2019-4-12 09:06:31 |阅读模式

admin 楼主

2019-4-12 09:06:31

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

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

x
[C#] 纯文本查看 复制代码
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Utilities
'
' The OpenComponents() parameter
' NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly
' only opens unloaded components fully (see also PR-8406345)
' Workaround: collect and open all components individually
'
Module NXJournal
    Dim theSession As Session = Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession()
    Dim dispPart As Part = theSession.Parts.Display

    Sub DoIt()
        Dim allComps() As Assemblies.Component = getAllChildren(dispPart)
        Echo("Number of Components: " & allComps.Length.ToString)
        For ii As Integer = 0 To allComps.Length - 1
            Echo(allComps(ii).DisplayName)
        Next

        Dim option1 As Boolean = theSession.Parts.LoadOptions.UsePartialLoading
        theSession.Parts.LoadOptions.UsePartialLoading = False

        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
        Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
        partLoadStatus1 = dispPart.ComponentAssembly.OpenComponents(
            NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, allComps, openStatus1)

        reportPartLoadStatus(partLoadStatus1)
        partLoadStatus1.Dispose()

        theSession.Parts.LoadOptions.UsePartialLoading = option1

    End Sub

    Function getAllChildren(ByVal assy As BasePart) As Assemblies.Component()
        Dim theChildren As Collections.ArrayList = New Collections.ArrayList
        Dim aChildTag As Tag = Tag.Null

        Do
            theUFSession.Obj.CycleObjsInPart(assy.Tag, UFConstants.UF_component_type, aChildTag)
            If (aChildTag = Tag.Null) Then Exit Do

            Dim aChild As Assemblies.Component = NXObjectManager.Get(aChildTag)
            theChildren.Add(aChild)
        Loop
        Return theChildren.ToArray(GetType(Assemblies.Component))

    End Function

    Public Sub Main(ByVal args As String())
        If dispPart IsNot Nothing Then
            DoIt()
            Return
        End If

    End Sub

    Sub Echo(ByVal output As String)
        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)
    End Sub

    Sub reportPartLoadStatus(ByVal load_status As PartLoadStatus)
        If load_status.NumberUnloadedParts = 0 Then
            Return
        End If

        Echo("  Load notes:")

        For ii As Integer = 0 To load_status.NumberUnloadedParts - 1
            Echo("  " & load_status.GetPartName(ii) & " - " & load_status.GetStatusDescription(ii))
        Next
    End Sub

    Public Function GetUnloadOption(ByVal arg As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module

# A; \' V+ y( A& b& @! A4 v! {
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

用户组 : 管理员
邮   箱 :xduniverse@qq.com
手   机 :VIP用户可查看[申请]
Q   Q : 点击这里给我发消息
性别 : 就不告诉你
主页 :http://www.plmhome.com
个人介绍 :原西门子NX高级教务员,10多年NX培训,开发咨询,Teamcenter培训实施等

主题2173

帖子3400

积分64430

  • NX Realize Shape创意

    NX Realize Shape是一个任务环境,您可以通过操作

  • Teamcenter12.0 汽车

    Teamcenter12.0 汽车解决方案TcAE 入门教程 *

  • teamcenter四层weblog

    teamcenter 12安装好后,部署四层 inserb 生成tc

  • NX二次开发源码:分享

    NX二次开发源码:分享下公差标注类型符号 [mw

  • PLM之家NX插件V8.0.0.

    PLM之家NX插件 ============================

  • 发布新帖
  • 在线客服1
  • 在线客服2
  • 微信
  • 客户端
  • 返回顶部
  • NX讨论
    Catia
    TC讨论
    Tecno
    云课堂
    业务合作