0

I am new at using macros. I tried making a simple code where a macro would save my part in different formats. stp, igs and 3dxml.

Sub CatMain()

pathInputBox = InputBox("Enter path")

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = objFSO.GetFolder(pathInputBox)

CATIA.DisplayFileAlerts = False
For Each oFile In oFolder.Files
If Right(oFile.Name, 8) = ".CATPart" Then
Set oProdDoc = CATIA.Documents.Open(oFolder & "\" & oFile.Name)
newname = Replace(oFile.Name, ".CATPart", "")
oProdDoc.ExportData oFolder & "\" & newname, "stp"
oProdDoc.ExportData oFolder & "\" & newname, "igs"
oProdDoc.ExportData oFolder & "\" & newname, "3dxml"

End If
Next
End Sub

And it works. But what if my part has more bodies. Say I also have an unfolded as a body and I would want to save that separately too? How would a macro code look if I wanted to save a body from the catpart? Can someone help me with this simple operation?

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

ExportData exports only geometry that is visible.
The simplest way would be to show only one body and hide all others.
To do this, select the body and show or hide it using the VisProperties (setShow).

Shrotter
  • 350
  • 3
  • 9
  • Hello. I was thinking about that. I could hide main body and only leave body I want to be saved. But how should I change my macro. If I will save again it will just ask me if I want to overwrite or not. Can macro script be changed and create a save function under a different name? example: If file already exists save it under different name? – BuffalloKing Feb 17 '22 at 09:44
  • So you already using the FileSystemObject you can use the `FileExists`-method ( [link](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/fileexists-method) ) – Shrotter Feb 17 '22 at 09:51
  • So you're tellimg me to replace FileSystemObject with FileEixists command? – BuffalloKing Feb 17 '22 at 09:59
  • No, before the ExportData check with obj.FileExists(sCompleteFilePath) if such a file exists – Shrotter Feb 17 '22 at 10:04
  • Ok. Just another question. I wonder, wouldn't it be easier to run the macro a second time and just add "unfolded" to the parts name? Is there such a way? to export but also add unfolded in name? It seems less complicated for a beginner :)) – BuffalloKing Feb 17 '22 at 10:17
  • So... Is there a way to make my script add "unfolded" at the end of each part name when it exports data in stp, igs and 3dxml? – BuffalloKing Feb 17 '22 at 15:48
  • Yes, for example `oProdDoc.ExportData oFolder & "\" & newname & "_unfolded", "stp"` – Shrotter Feb 17 '22 at 16:09
  • You're a God!! It works. Thank you kindly sir. Problem solved – BuffalloKing Feb 18 '22 at 05:31