jzecha
Aerospace
- Jan 20, 2016
- 236
I found another macro and modified it to work for my purpose.
I needed a macro to save all the parts in an assembly as Step files but not save the Products.
This works exactly as I need it, but I'd like to know a better way to only save the parts besides referencing the .CATPart file type.
I needed a macro to save all the parts in an assembly as Step files but not save the Products.
This works exactly as I need it, but I'd like to know a better way to only save the parts besides referencing the .CATPart file type.
Code:
Sub CATMain()
Dim mainDocument
Set mainDocument = CATIA.ActiveDocument
mainDocument.Save
On Error GoTo 0
Set oProduct = mainDocument.Product
'Selecting Folder To Save Files Into
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = &H0001
Const File_Path = 17
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, File_Path)
Set objFolderItem = objFolder.Self
docPath = objFolderItem.Path
CATIA.RefreshDisplay = False
'Counting and Selecting Files
Dim i 'As Integer
Dim intIncrement 'As Integer
intIncrement = Int(100 / mainDocument.Product.Products.Count)
For i = 1 to mainDocument.Product.Products.Count
Set prdSubProduct = mainDocument.Product.Products.Item(i)
Set prdRefProduct = prdSubProduct.ReferenceProduct
Set docSubDocument = prdRefProduct.Parent
strSubFullPath = docSubDocument.FullName
'extract information of FullName
Dim n 'As Long
Dim prodfilename 'As String
Dim oProdnumber 'As String
n = Len(docSubDocument.Path) + 2
prodfilename = Mid(oProdFile, n)
'identification of the component (CATPart or CATProduct)
Dim extension 'As String
If InStr(strSubFullPath, ".CATPart" ) Then
'extension = ".CATPart"
extension = ".STP"
End If
CATIA.DisplayFileAlerts = False
docSubDocument.SaveAs docPath & "\" & prdRefProduct.Name & extension
Next
CATIA.RefreshDisplay = True
CATIA.DisplayFileAlerts = True
End Sub