Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

CATShape and a save macro

Status
Not open for further replies.

JayEnn1

Automotive
Sep 29, 2015
50
Good morning!

We have enjoyed using a nice macro from thread: thread560-435146, ( saving parts & products using part numbers as filenames )
but just recently ran into an issue where our customer has provided us with a CATShape item in the design. The macro seems
to crash/stop when it trys to process the CATShape. A work around is to remove the CATShape from the design, run macro, then
add the CATShape back into the design.
I've experimented around with the macro trying to get it to process or handle a CATShape with no luck. Could be because I don't
fully understand how CATShapes work considering their link to reference is to a CATProduct but it has its own CATShape file?

Any helpful ideas would be greatly appreciated. Here's the original macro.

CATIA.DisplayFileAlerts = False

Set oDocs = CATIA.Documents
docPath = oDocs.Item(1).Path
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", "File path")
End If


For x = 1 To oDocs.Count

If TypeName(oDocs.Item(x)) = "ProductDocument" Then
Set oDoc1 = oDocs.Item(x)
Set oProduct1 = oDoc1.Product
oDoc1.SaveAs docPath & "\" & oProduct1.PartNumber & ".CATProduct"
End If
Next 'x

For v = 1 To oDocs.Count

If TypeName(oDocs.Item(v)) = "PartDocument" Then
Set oDoc2 = oDocs.Item(v)
Set oPart1 = oDoc2.Product
oDoc2.SaveAs docPath & "\" & oPart1.PartNumber & ".CATPart"
End If
Next 'v

Msgbox "Save Finished!",,"SAVE FINISH!"

End Sub
 
Replies continue below

Recommended for you

I am happy somebody else got some use out of this Macro.
I can't answer the question on the CATShape issue, but I did run into an issue with that Macro where it crashed when it runs into a symbol that is not allowed in save names.
I added some code to replace the symbols with underscores and this allowed it to work.

You might turn CATIA.DisplayFileAlerts = False to True and click through the file alerts to see exactly what is causing the failure.
This is what I did to find out the symbols were the issue.
 
Thank you jzecha!

I did exactly what you mentioned and the messages didn't clue me in.

Right now, as time permits, I have been trying to learn more about CATShapes. Thinking if I learn more about them
I'll learn why the macro doesn't like handling them.

Also, thanks for the idea to replace symbols with an underscore. We have been doing that manually right now because
the amount of times we ran into such symbols was small.
 
What is the exact error message that the Macro fails on?
 
RunTimeError1_rzavj3.jpg


During macro execution with display set to True I get the "Do you want file to be overwritten" and then "Save As will update the links" message.
Then when it gets to the CATShape item in the design the macro just bails with the error shown in the attached image to this post.

Source CATIAPartDocument
Description: The method Product failed
Line 46
Column 4
bails on: "Set oPart1 = oDoc2.Product"


Dim v As Integer
For v = 1 To oDocs.Count
' If current object in loop is a CATPart then save as a CATPart using part number value as new filename
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
 
Hi.

Change:

Code:
Dim oPart1 As Product
Set oPart1 = oDoc2.Product

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

To this:

Code:
oDoc2.SaveAs docPath & "\" & oDoc2.Part.Name & ".CATPart"
 
Thank you very much for the reply!
I will definitely give it a try today!

Can you explain the filing differences between a CATProduct/CATPart versus a CATShape?

Its a bit confusing because when I check properties of a CATShape the link to reference points to a product
much like how components work but in my directory of files there is a CATShape file.
 
Part can be inserted in a product thus creating an "instance". To enable this CATIA maintains product to product relationships and that's why we have Product property in PartDocument object.

CATShape contrarily can not be used to form an instance as it's sole purpose is to provide geometrical representation to both parts and products. Parts and catshapes are very similar in terms of internal structure, so PartDocument is used for both of these document types, although it's Product property for catshapes is unavailable (the exact source of your error in first place).
 
That perfectly helps me understand the macro error!
I did put in the changes and test ran the macro. It worked like a champ!

Really appreciate the assistance Mr. H.P. Lovecraft!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor