I have a function in my macro that is saving all parts from an assembly into .dxf format. this function sorts through all of the parts in the assembly to only process the parts with "PL" in the custom properties. In this PL category, there are two types of parts. sheet metal parts and regular "plate" parts. I am able to make all parts visible when they need to be but only regular parts will become invisible. I do not understand why the sheet metal parts are the only exception.
Function PrintDXF(ByRef swPrtDoc As ModelDoc2) As String
Dim sa As Variant
Dim swBody As SldWorks.Body2
Dim i As Integer
Dim modelPath As String
Dim OUT_PATH As String
Dim swSelObj As Object
Dim smExpRetVal As Boolean
Dim prtExpRetVal As Boolean
Dim fso1 As New FileSystemObject
If swPrtDoc.GetType = swDocPART Then
Set swPart = swPrtDoc
modelPath = swPart.GetPathName
prtCustProp
OUT_PATH = savePath & "\" & CustPropPiece & ".dxf"
Debug.Print OUT_PATH
If Not fso1.FileExists(OUT_PATH) Then
If CustPropType = "PL" Then
swPrtDoc.Visible = True
sa = swPart.GetBodies2(swSolidBody, True)
For i = 0 To UBound(sa)
Set swBody = sa(i)
If swBody.IsSheetMetal Then
smExpRetVal = swPart.ExportToDWG2(OUT_PATH, modelPath, swExportToDWG_e.swExportToDWG_ExportSheetMetal, True, Empty, False, False, SheetMetalOptions_e.ExportFlatPatternGeometry + SheetMetalOptions_e.ExportBendLines, Empty)
If smExpRetVal = False Then
err.Raise vbError, "", "Failed to export sheet metal part"
Else
swPrtDoc.Visible = False
End If
Else
Set swSelMgr = swPrtDoc.SelectionManager
While swSelObj Is Nothing
Dim y As Integer
For y = 1 To swSelMgr.GetSelectedObjectCount2(-1)
If swSelMgr.GetSelectedObjectType3(y, -1) = FilterY Then
Set swSelObj = swSelMgr.GetSelectedObject6(1, -1)
End If
Next
DoEvents
Wend
prtExpRetVal = swPart.ExportToDWG2(OUT_PATH, modelPath, swExportToDWG_ExportSelectedFacesOrLoops, True, Empty, False, False, Empty, Null)
If prtExpRetVal = False Then
err.Raise vbError, "", "Failed to export part"
Else
End If
swPrtDoc.ClearSelection2 True
End If
swPrtDoc.Visible = False
Next
AcadApp.Visible = True
AcadApp.Documents.Open OUT_PATH
AcadApp.ActiveDocument.SendCommand ("QWB") & vbCr
AcadApp.Visible = False
'killPath = Replace(OUT_PATH, "dxf", "bak")
'Debug.Print killPath
'Kill killPath
End If
End If
End If
End Function
I tried to move swPrtDoc.Visible = False to different lines to see if that made any difference- it did not.
i tried to close the document using swApp.CloseDoc "" - it did not close the sheet metal document