Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Save As - Part Files for Part Numbering

Status
Not open for further replies.

weagan22

Aerospace
Aug 27, 2015
79
US
I am working on a macro to rename all of the parts in an assembly. I have gotten all of the "Part Numbers" to update to the new numbers but am having a hard time saving "Save As" all of the files so that the file has the same name as the part number. I started by trying to save at the same time as I changed the part number but it seems very difficult to jump between products and their respective document to be able to save. I therefore went the route shown below of just saving all of the documents by recursively scrolling though the tree and saving any parts. It still isn't working though. Any suggestions?







Sub SaveParts(oInDocuments As Documents, oInPart As PartDocument, ByVal bLevel As Integer, DocPath As String)

bLevel = bLevel + 1

Dim oInst As Documents
Set oInst = oInDocuments
Dim PartDoc As PartDocument
Set PartDoc = oInPart

'No components --> CATPart
If oInst.Count = 0 Then
oInPart.SaveAs (DocPath & "\" & PartDoc.Part.Name & ".CATPart")
Exit Sub
End If

'Multiple components --> CATProduct
Dim i As Integer

For i = 1 To oInst.Count
Dim partType As String
partType = oInst.Item(i).Name
partType = Right(partType, 2)

If partType = "rt" Then
Dim Part2 As PartDocument
Set Part2 = oInst.Item(i)
Else
Dim nInst As Documents
Set nInst = oInst.Item(i)
End If
Call SaveParts(nInst, Part2, bLevel, DocPath)
Next

End Sub
 
Replies continue below

Recommended for you

looking quickly... you save only CATParts, no CATproduct ?

do you know about typename(object)? should work for part / partdocument / product / productdocument...

I made several recursive for the almost same reason as you.
when i 'recurse' I give only one object, in my case i save all in the same folder.

if it's a partdoc then i save it, if it's a productdoc then i recurse its products (child elements) one by one. Then I save it.

That should do.

when you say it does not work, what is the result you have, if any?



Eric N.
indocti discant et ament meminisse periti
 
I just wanted to share that I figured it out. The problem I was having was setting a product as a document. The line "Set oPart1 = oDoc2.Product" solved this issue. This was required to be able to identify the Part Number of a given Document. Thanks for helping!

Dim oDocs As Documents
Set oDocs = CATIA.Documents

Dim docPath As String
docPath = oDocs.Item(1).Path

Dim changePath As Integer
changePath = MsgBox("Current save location is: " & docPath & " Would you like to change file path?", vbYesNo)

If changePath = vbYes Then
docPath = InputBox("Enter new file path (eg. T:\_PROGRAMS\COMMERCIAL\_DATA\will.eagan\A330):", "File path")
End If

Dim v As Integer
For v = 1 To oDocs.Count

If TypeName(oDocs.Item(v)) = "PartDocument" Then
Dim oDoc2 As PartDocument
Set oDoc2 = oDocs.Item(v)

Dim oPart1 As Product
Set oPart1 = oDoc2.Product

oDoc2.SaveAs docPath & "\" & oPart1.PartNumber & ".CATPart"

End If
Next 'v

Dim x As Integer
For x = 1 To oDocs.Count

If TypeName(oDocs.Item(x)) = "ProductDocument" Then
Dim oDoc1 As ProductDocument
Set oDoc1 = oDocs.Item(x)

Dim oProduct1 As Product
Set oProduct1 = oDoc1.Product

oDoc1.SaveAs docPath & "\" & oProduct1.PartNumber & ".CATProduct"

End If
Next 'x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top