Enum IfcFormat_e
Ifc2x3 = 23
Ifc4 = 4
End Enum
Const OUT_FILE_PATH As String = "C:\Test.ifc"
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
If Not swModel Is Nothing Then
ExportIfc swModel, OUT_FILE_PATH, IfcFormat_e.Ifc4
Else
MsgBox "Please open the model"
End If
End Sub
Sub ExportIfc(model As SldWorks.ModelDoc2, path As String, format As IfcFormat_e)
Dim curIfcFormat As Integer
curIfcFormat = swApp.GetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swSaveIFCFormat)
swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swSaveIFCFormat, format
Dim errors As Long
Dim warnings As Long
If False = model.Extension.SaveAs3(path, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, Nothing, errors, warnings) Then
Err.Raise vbError, "", "Failed to export file. Error code: " & errors
End If
swApp.SetUserPreferenceIntegerValue swUserPreferenceIntegerValue_e.swSaveIFCFormat, curIfcFormat
End Sub
This message is not caught by the saveAs function. SW reactivates the deleted component and suddenly the export is "not compliant" with what Ka.Couff wants .
This is not a configuration problem, so the response is not adequate ;)
We should look at SW events if we can pick up this message and do a treatment.
Yes, that's it I had tried to record the macro by launching the manipulation manually but there is nothing that displays the message:
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
' Save As
longstatus = Part.SaveAs3("XXX.IFC", 0, 0)
End Sub
I don't have much time at the moment to look at this but if you can't intercept the message there is always the possibility to delete the component in the deleted state, do the export and close without saving.
The API may not allow access to this message at this time (SW adds access to functions as SW is released).