vbacatia

how do I export a part as a .stp in CATIA 3DExperience Macro


How can I use a VBA macro in the 3DExperience to save a part as a step file? I have found references in the documentation to the ExportData method, which requires it to be referred to a document, but I cannot figure out how to get the current active document. In an example I found online for CATIA V5 they use the "Open" method to convert files, but I would like to refer to the current active document instead, how could I do this?

Thanks!!!

Dim PartDocument0 As Document
' Reading a CATPart file
Set PartDocument0 = CATIA.Documents.Open("C:\desktop\File1.CATPart")
' Saving the part in a STEP file
PartDocument0.ExportData("C:\desktop\File1.stp", "stp")

Documentation references:

Exportdata

Sub ExportData(fileName As String, format As String)

Member of INFITF.Document

ActiveDocument

Property ActiveDocument As Document

Member of INFITF.CATIAApplicationCoClass read-only

Document

Sub ExportData(fileName As String, format As String)

Member of INFITF.Document

Application

Property Application As CATIAApplicationCoClass

read-only

Member of INFITF.AnyObject

But if I run the following code:

Dim PartDocument1 As Application
Set PartDocument1 = CATIA.ActiveDocument

or even the following code:

Dim PartDocument1 As Documents
Set PartDocument1 = CATIA.ActiveDocument

I get the error:

Method "ActiveDocument" of object "Application" failed


Solution

  • Unfortunately, I don't think there is an equivalent of the ExportData function with 3DExperience. Only thing I have found close to a solution is using StartCommand and SendKeys functions to simulate key presses: https://www.coe.org/p/fo/et/thread=28059

    yet it is not a robust solution, tho it may solve your problem. I would really appreciate it if you came up with a solution and share it.