Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save All Parts As Step Optimization Help

Status
Not open for further replies.

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.


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
 
Replies continue below

Recommended for you

I actually didn't know it existed. Thanks for the info.

But since I already have the and I'd like to learn more, can you recommend a better way to do this?
 
Try to search for all desired parts (if you want only parts, according to what criteria you wish) in the active document, loop thru selection, and use ExportData as stp for each item in selection to a specific folder (hard coded, no interaction from the user). Is just an idea, I don't have CATIA now.

Still, that utility is faster if you have a lot of files...I learned that out of the box solutions in CATIA are the best...

Regards
Fernando

 
I appreciate the thought on an approach.
I will personally use the utility every time but it will be more difficult for me to train others on how to use the Utility correctly.
When instead I can just create a button to do it, regardless of if its slower, I aim for less confusing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor