使用VBA宏将单个CATIA正文从CATPart导出为stl

时间:2015-12-02 14:57:59

标签: vba stl catia

是否可以将单个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

1 个答案:

答案 0 :(得分:1)

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

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

我尝试导出CATBody但未成功。我们必须有一个CATPart来生成STL