iCAx开思网

标题: vb.net 导出 *x_t(Parasolid文件) [打印本页]

作者: cwz0571    时间: 2011-6-21 15:28
标题: vb.net 导出 *x_t(Parasolid文件)
Option Strict Off
Imports System.IO
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UF.UFPs
Imports NXOpen.UF.UFAssem
Imports NXOpen.UF.UFModl
Imports NXOpen.UF.UFObj
Imports NXOpen.UF.UFPart
Imports NXOpen.UF.UFConstants

Module Module1
    Public body_list() As Tag
    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUI As UI = UI.GetUI()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        ' TODO: Add your application code here
        Dim displayPart As Part = theSession.Parts.Display
        MsgBox("1")

        'Dim prtname As String = "D:\1111111.prt"                    '部件文件名
        'Dim prtname As String = "F:\lashen.prt"
        'Dim expname As String = "F:\lashen.txt"                                 '表达式文件名
        Dim x_tname As String = "D:\aasse_pb.x_t"                              'ParaSolid文件名
        Dim part_tag As NXOpen.Tag = displayPart.Tag
        'Dim load_status As NXOpen.UF.UFPart.LoadStatus
        'Try
        '    theUfSession.Part.Open(prtname, part_tag, load_status)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
        'Try
        '    theUfSession.Modl.ImportExp(expname, 0)
        'Catch ex As Exception
        '    MsgBox(ex.ToString)
        'End Try
        Try
            theUfSession.Modl.Update()
        Catch ex As Exception
            ex.ToString()
        End Try
        Try
            theUfSession.Part.Save()
        Catch ex As Exception
            ex.ToString()
        End Try
        Dim root_part_occ As NXOpen.Tag
        root_part_occ = theUfSession.Assem.AskRootPartOcc(part_tag)
        theUfSession.Modl.CreateList(body_list)
        Try
            If root_part_occ = Tag.Null Then
                make_body_list_part(part_tag)
            Else
                Dim obj As NXOpen.Tag = theUfSession.Assem.AskPrototypeOfOcc(root_part_occ)
                make_body_list_assem(obj)
            End If
            theUfSession.Ps.ExportData(body_list, x_tname)
            theUfSession.Modl.DeleteBodyParms(body_list)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Sub make_body_list_part(ByVal body_tag As Tag)
        Dim obj As NXOpen.Tag = Tag.Null
        Dim UF_body_type As Int32
        Dim type As Int32
        Dim subtype As Int32
        Do
            UFSession.GetUFSession().Obj.CycleObjsInPart(body_tag, UF_solid_type, obj)
            If obj <> Tag.Null Then
                UFSession.GetUFSession().Obj.AskTypeAndSubtype(obj, type, subtype)
                UFSession.GetUFSession().Modl.AskBodyType(obj, UF_body_type)
                If subtype <> UF_solid_body_subtype Then
                    Continue Do
                End If
                If UF_body_type = UF_MODL_SOLID_BODY Then
                    UFSession.GetUFSession().Modl.PutListItem(body_list, obj)
                    Exit Do
                End If
            End If
        Loop
    End Sub

    Sub make_body_list_assem(ByVal body_tag As Tag)
        Dim obj As Tag = Tag.Null
        Dim UF_body_type As Int32
        Dim type As Int32
        Dim subtype As Int32
        Do
            Dim UF_OBJ As UFObj = UFSession.GetUFSession().Obj
            UF_OBJ.CycleObjsInPart(body_tag, UF_solid_type, obj)
            If obj <> Tag.Null Then
                UF_OBJ.AskTypeAndSubtype(obj, type, subtype)
                Dim UF_MODL As UFModl = UFSession.GetUFSession().Modl
                UF_MODL.AskBodyType(obj, UF_body_type)
                If subtype <> UF_solid_body_subtype Then
                    Continue Do
                End If
                If UF_body_type = UF_MODL_SOLID_BODY Then
                    UF_MODL.PutListItem(body_list, obj)
                    Exit Do
                End If
             End If
        Loop
    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------
    End Function

End Module
[attach]1085559[/attach]
[attach]1085560[/attach]

本帖最后由 cwz0571 于 2011-6-21 16:02 编辑
作者: cscgr    时间: 2012-2-19 22:14
好东西 顶一个 自学vb。net  希望可以交流交流
作者: harryx88    时间: 2012-9-14 15:54
好东西啊,老大,但是有个问题,导出单个模型没问题,导出装配体会出错。
后来看了下代码,发现make_body_list_part和make_body_list_assem这两个过程的语句是一样的啊。
出错的语句是UF_MODL.AskBodyType(obj, UF_body_type)
错误反馈说Non-body EID input。。。
可能这里的参数obj是一个装配体而不是单个零件,所以得不到BodyType?
我都是用录制“操作记录”来编的,导出x_t不支持录制,所以没有办法了,希望给点提示哈~~




欢迎光临 iCAx开思网 (https://www.icax.org/) Powered by Discuz! X3.3