2015-12-02 2 views
0

Est-il possible d'exporter un seul corps CATIA en tant que STL sans créer de pièce séparée?Exporter un seul corps CATIA à partir de CATPart en tant que stl à l'aide de la macro VBA

Pour le moment, j'ai codé un script qui boucle les CATParts présents dans un dossier, récupère les corps contenus et crée un seul CATPart avec chacun d'entre eux et l'exporte au format 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 

Répondre

1

Catia V5 est capable de créer des fichiers STL à partir de pièces (fichiers CatiaPART), mais pas d'assemblées (fichiers CatiaPRODUCT) ou des représentations géométriques (fichiers de voiture). Par conséquent, les fichiers source, y compris ceux sauvegardés dans un format neutre (STEP ou IGES, par exemple), doivent être sauvegardés en tant que parties. Si la conception source a été enregistrée en tant qu'assemblage, elle est importée dans Catia en tant que produit. -

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

J'ai essayé exporter CATBody mais sans succès. Nous devons avoir un CATPart pour générer STL

+0

Merci @Sree Harska. Par conséquent, je devrais exporter chaque CATBody dans un CATPart séparé et l'enregistrer en tant que STL. Cela prend un certain temps car "CATIA.Documents.Open (objFile.path)" charge graphiquement le modèle. Y at-il un moyen d'empêcher l'ouverture du CATPart mais de le manipuler? – Nic

+1

vous pouvez démarrer catia en mode batch en fournissant "-nowindow" comme argument de ligne de commande. Il sera beaucoup plus rapide nous avons déjà écrit un CATMacro qui lit des centaines de CATProducts dans un dossier et identifie les liens brisés Il y a une réduction significative du temps si nous lançons CATIA en mode batch avec "-nowindow" et fournissons le nom de macro qui doit être exécuté –