【问题标题】:Export single CATIA body from CATPart as stl using VBA macro使用 VBA 宏将单个 CATIA 主体从 CATPart 导出为 stl
【发布时间】:2015-12-03 01:48:55
【问题描述】:

是否可以将单个 CATIA 实体导出为 STL,而无需使用它创建单独的零件?

目前,我编写了一个脚本,该脚本循环遍历文件夹中存在的 CATPart,获取包含的主体并为每个主体创建一个 CATPart,然后导出为 stl 格式。

    Dim output_stl_path_HD As String
    Dim output_stl_path_MD As String
    Dim output_stl_path_SD As String
    Dim output_stl_path_via_points As String
    Dim output_transformations_path As String
    Dim input_path As String

    Sub CATMain()
    'Path for output file


    input_path = CATIA.ActiveDocument.path + "\"


    Dim it As Integer
    Dim prod As Product
    Dim t_p_ref(11)

    'List of part names to export
    Dim list As Collection
    Set list = New Collection


    'GET LIST OF CATPART IN FOLDER
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim i As Integer

    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Get the folder object
    Set objFolder = objFSO.GetFolder(input_path)
    i = 1
    'loops through each file in the directory and prints their names and path
    For Each objFile In objFolder.Files

        'print file name
        If (InStr(objFile.path, ".CATPart")) Then

            list.Add (objFile.name)

    '        Set objDocument = CATIA.Documents.Open(objFile.path)

            Dim srcDoc As PartDocument
            Set srcDoc = CATIA.Documents.Open(objFile.path)
            Dim srcPart As Part
            Set srcPart = srcDoc.Part

            Dim oSel As Selection
            Dim bodies1 As Bodies
            Dim body1 As body
    '
            Set bodies1 = srcPart.Bodies

            For Each single_body In srcPart.Bodies
                A = exportStl(single_body)
            Next
            Set body1 = srcPart.Bodies.Item(i)

    'Dim BoxProduct
    'BoxProduct = MsgBox("Quantity of the bodies found:" & srcDoc.Part.Bodies.Count & "", 64)

        End If
    Next

    End Sub



    Public Function exportStl(ByVal myBody As body)
        Dim oSrc As Part
        Dim oTgt As Part
        Dim oSrcDoc As PartDocument
        Dim oTgtDoc As PartDocument
        Dim oBod As body
        Dim oSel As Selection

        'Sets documents for Source and Target files
        Set oSrcDoc = CATIA.ActiveDocument
        Set oTgtDoc = CATIA.Documents.Add("Part")
        oTgtDoc.Product.PartNumber = myBody.name




        'Gets Body to copy
        Set oSrc = oSrcDoc.Part
        Set oTgt = oTgtDoc.Part
        Set oBod = myBody
        Set oSel = oSrcDoc.Selection

        'Copies Body
        oSel.Add oBod
        oSel.Copy
        Set oSel = oTgtDoc.Selection

        'Sets and Pastes in Target file as result with link
        oSel.Clear
        oSel.Add oTgt.Bodies.Item(1)
        oSel.Paste
        oSrcDoc.Selection.Clear


         CATIA.ActiveDocument.ExportData input_path + myBody.name, "stl"

         CATIA.ActiveDocument.Close


    End Function

【问题讨论】:

    标签: vba stl catia


    【解决方案1】:

    Catia V5 能够从零件(CatiaPART 文件)创建 STL 文件,但不能从装配体(CatiaPRODUCT 文件)或几何表示(汽车文件)创建 STL 文件。因此,源文件,包括以中性格式(例如 STEP 或 IGES)保存的源文件,必须保存为部件。如果源设计保存为装配体,则将其作为产品导入 Catia。 -

    来源:http://www.stratasys.com/customer-support/cad-to-stl/catia

    我尝试导出CATBody,但不成功。我们必须有一个 CATPart 才能生成 STL

    【讨论】:

    • 谢谢@Sree Harska。因此,我应该将每个 CATBody 导出到单独的 CATPart 中并将其保存为 STL。这需要相当长的时间,因为“CATIA.Documents.Open(objFile.path)”以图形方式加载模型。有没有办法阻止打开 CATPart 但仍对其进行操作?
    • 您可以通过提供“-nowindow”作为命令行参数以批处理模式启动 catia。我们曾经编写了一个 CATMacro,它读取文件夹中的数百个 CATProducts 并识别损坏的链接会快得多 如果我们使用“-nowindow”以批处理模式启动 CATIA 并提供必须执行的宏名称,则可以显着减少时间/跨度>
    猜你喜欢
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2012-07-03
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多