Hello everyone, I wrote a macro to export the unfolded sheet metal parts, everything works well when it is engaged from a part.
I want to make it work even when the active document is a plan (I'm getting there for export step).
The object is, in the case where the starting point is a plan, to open/activate the part of the same name and then to export it via ExportToDWG2.
But I get a "property or method not handled by this object" error in this context, ideas?
(however, after opening the part, MsgBox ("The active document is: " & swApp.ActiveDoc.GetTitle) tells me that the part is active)
---------------------------------CONTEXT CHECK AND LAUNCH-------------------------
Sub dxfexport()
If Not swDOC Is Nothing Then
If swDOC.GetType = swDocDRAWING Then
If fso. FileExists(PART_PATH) Then
Call openpart
Call dxf
Call closepart
Else: MsgBox ("Pièce Introuvable")
End If
ElseIf swDOC.GetType = swDocPART Then
'openpart
dxf
End If
Else
MsgBox "Please open a document", vbExclamation + vbOKOnly
End If
End Sub
--------------------------------- OPENING OF THE ROOM----------------------------
Sub openpart()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Do
If fso. FileExists(PART_PATH) Then
Set Part = swApp.OpenDoc6(PART_PATH, 1, 0, "", longstatus, longwarnings)
swApp.ActivateDoc3 PART_PATH, False, swRebuildOnActivation_e.swDontRebuildActiveDoc, longstatus
'swApp.ActivateDoc2 PART_PATH, False, longstatus
Set Part = swApp.ActiveDoc
Else: MsgBox ("part not found")
End If
Loop Until Part.GetType = swDocPART
Part.EditRebuild3
Part.ViewZoomtofit2
MsgBox ("The active document is: " & swApp.ActiveDoc.GetTitle)
End Sub
-------------------------------------------EXPORT------------------------------------
Sub dxf()
Dim modelPath As String
Dim longstatus As Long
modelPath = swDOC.GetPathName
Dim OUT_PATH As String
OUT_PATH = EXPORT_PATH & FILE_NAME & Indice + ".DXF"
Dim options As Long
options = 1 Or 2 Or 4 Or 8 Or 16 Or 32
'Codes d'options d'export:
'ExportFlatPatternGeometry = 1
'IncludeHiddenEdges = 2
'ExportBendLines = 4
'IncludeSketches = 8
'MergeCoplanarFaces = 16
'ExportLibraryFeatures = 32
'ExportFormingTools = 64
'ExportBoundingBox = 2048
If modelPath = "" Then
Err.Raise vbError, "", "Enregistrez votre pièce avant export"
Else
If False = swDOC.ExportToDWG2(OUT_PATH, PART_PATH, swExportToDWG_e.swExportToDWG_ExportSheetMetal, True, Empty, False, False, options, Empty) Then
Err.Raise vbError, "", "Erreur d'export DXF"
End If
End If
End Sub