Advertisement
Guest User

Untitled

a guest
Jun 12th, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Sub CATMain()
  2.  
  3. 'Error handling in case of empty CATIA window, no open objects.
  4. On Error Resume Next
  5. Set currDocument = CATIA.ActiveDocument
  6.  
  7. If Err.Number <> 0 Then
  8. Err.Clear
  9. MsgBox "An assembly file needs to be opened and active for this macro.", vbCritical, "Wrong context"
  10. Exit Sub
  11. End If
  12.  
  13. IF Instr(CATIA.ActiveDocument.Name,".CATProduct") THEN
  14. sFilePath = CATIA.ActiveDocument.Path + "\"
  15. ExportNextProduct CATIA.ActiveDocument.Product, sFilePath
  16. Else
  17. MsgBox "An assembly file needs to be opened and active for this macro.", vbCritical, "Wrong context"
  18. END IF
  19.  
  20. MsgBox "STP file export complete.", vbInformation, "Finished"
  21.  
  22. End Sub
  23.  
  24. Sub ExportNextProduct(oCurrentProduct as Product, sFilePath as String)
  25. Dim oCurrentTreeNode As Product
  26. Set FileSys = CATIA.FileSystem
  27.  
  28. For i = 1 To oCurrentProduct.Products.Count
  29. Set oCurrentTreeNode = oCurrentProduct.Products.Item(i)
  30. sFileName = oCurrentTreeNode.Nomenclature + " " + oCurrentTreeNode.DescriptionRef + ".stp"
  31.  
  32. IF oCurrentTreeNode.Source = catProductMade and oCurrentTreeNode.Definition <> "ASM" Then
  33. IF FileSys.FileExists(sFilePath + sFileName) = FALSE Then
  34. oCurrentTreeNode.ReferenceProduct.Parent.ExportData sFilePath + sFileName, "stp"
  35. END IF
  36. END If
  37.  
  38. If oCurrentTreeNode.Products.Count > 0 AND oCurrentTreeNode.Definition = "ASM" Then
  39. ExportNextProduct oCurrentTreeNode, sFilePath
  40. END If
  41. Next
  42.  
  43.  
  44. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement