Export as .dxf from weldment + custom properties

Hello all,

We have been playing around with an excellent macro from these forums >>

This has been modified to save to our particular saving location & drag specific custom properties to name the file from the sheetmetal part... all good there!

When exporting to DXF we need to map the file with bend line colours, so my thought was to modify the export code based on 2014 SOLIDWORKS API Help - swExportToDWG_e Enumeration :

"swExportToDWG_ExportSelectedFacesOrLoops" to "swExportToDWG_ExportSheetMetal" to enable to use of the DXF mapping tool

However when changed, the macro is producing no output.

Perhaps this was the wrong macro to start with? All help appreciated. Code below..

<p>Option Explicit</p><p>' LATEST REVISION 06MAY2019 EDD - NOT SAVING AS SHEETMETAL</p><p></p><p></p><p></p><p></p><p>Sub Main()</p><p>Dim swApp               As SldWorks.SldWorks</p><p>Dim Part                As SldWorks.ModelDoc2</p><p>Dim swFace              As SldWorks.Face2</p><p>Dim swBody              As SldWorks.Body2</p><p>Dim feat                As SldWorks.Feature</p><p>Dim swCustPropMgr       As SldWorks.CustomPropertyManager</p><p>Dim SelMgr              As SldWorks.SelectionMgr</p><p>Dim BodyFolder          As SldWorks.BodyFolder</p><p>Dim CutListBdy          As Body2</p><p>Dim strValue(10)        As String</p><p>Dim WorkFace            As Face2</p><p>Dim WorkSurface         As Surface</p><p>Dim savepathdxf         As String</p><p>Dim varAlignment        As Variant</p><p>Dim dataAlignment(11)   As Double</p><p>Dim seltype             As Integer</p><p>Dim i                   As Integer</p><p>Dim isThisAPlane        As Boolean</p><p>Dim vBodies             As Variant</p><p>Dim j                   As Integer</p><p>Dim wasResolved         As Boolean</p><p>Dim itemnumber As Variant</p><p>Const SaveLoc           As String = "R:\\CUSTOMER BUILDS\\- RECENT PDF FILES\\RECENT FILES - EDD\\TESTING\\" 'Change Path here</p><p></p><p></p><p></p><p></p><p>Set swApp = Application.SldWorks</p><p>Set Part = swApp.ActiveDoc</p><p></p><p></p><p>'Don't run if no part is loaded</p><p>If Part Is Nothing Then</p><p>    swApp.SendMsgToUser "There is no part loaded."</p><p>    GoTo cleanupandquitnopart</p><p>End If</p><p></p><p></p><p>'did the user have the open file saved</p><p>If Part.GetPathName = "" Then</p><p>        'user does not have open file saved</p><p>        swApp.SendMsgToUser "Please save the file before running this script."</p><p>        GoTo cleanupandquit</p><p>End If</p><p></p><p></p><p>Set swCustPropMgr = Part.Extension.CustomPropertyManager("")</p><p>'Get Custom Property Project</p><p>swCustPropMgr.Get5 "Project", False, strValue(8), strValue(0), wasResolved</p><p>'Get Custom Property Number</p><p>swCustPropMgr.Get5 "Number", False, strValue(9), strValue(1), wasResolved</p><p></p><p></p><p>'did the user pre-select a face?</p><p>Set SelMgr = Part.SelectionManager</p><p>If SelMgr.GetSelectedObjectCount2(1) <> 1 Then</p><p>seltype = SelMgr.GetSelectedObjectType3(1, 0)</p><p>    If seltype <> SwConst.swSelFACES Then</p><p>        'user did not preselect one face</p><p>        swApp.SendMsgToUser "Please select a (one) 2D face before running this command."</p><p>        GoTo cleanupandquit</p><p>     Else</p><p>           </p><p>    Set swFace = SelMgr.GetSelectedObject6(1, -1)</p><p>    Set swBody = swFace.GetBody</p><p>        </p><p>    Set feat = Part.FirstFeature</p><p>    While Not feat Is Nothing</p><p>        If feat.GetTypeName = "CutListFolder" Or feat.GetTypeName = "SubWeldFolder" Then</p><p>            Set BodyFolder = feat.GetSpecificFeature2</p><p>            vBodies = BodyFolder.GetBodies</p><p>            If Not IsEmpty(vBodies) Then</p><p>            For j = LBound(vBodies) To UBound(vBodies)</p><p>                Set CutListBdy = vBodies(j)</p><p>                If CutListBdy.Name = swBody.Name Then</p><p>                Set swCustPropMgr = feat.CustomPropertyManager</p><p>                    'Get Custom Property PART NO from cut list</p><p>                        swCustPropMgr.Get5 "PART NO", False, strValue(5), strValue(2), wasResolved</p><p>                    'Get Custom Property REV (REVISION) from cut list</p><p>                        swCustPropMgr.Get5 "REV", False, strValue(6), strValue(3), wasResolved</p><p>                itemnumber = feat.Name</p><p>                End If</p><p>            Next j</p><p>            End If</p><p>        End If</p><p>        Set feat = feat.GetNextFeature()</p><p>    Wend</p><p>       </p><p>    End If</p><p>End If</p><p></p><p></p><p>'Determine if the selected face is a true 2D plane... exit if not</p><p>isThisAPlane = False  'initalize variable to false</p><p>'make sure that what is selected is a face... exit if not</p><p></p><p></p><p></p><p></p><p>If SelMgr.GetSelectedObjectType3(1, -1) <> 2 Then</p><p>    swApp.SendMsgToUser "Item selected is not a face. You must select a (one) complete 2D Face to export."</p><p>    GoTo cleanupandquit</p><p>End If</p><p></p><p></p><p>Set WorkFace = SelMgr.GetSelectedObject5(1)</p><p>Set WorkSurface = WorkFace.GetSurface</p><p>isThisAPlane = WorkSurface.IsPlane</p><p></p><p></p><p>If isThisAPlane = False Then</p><p>    swApp.SendMsgToUser "The face selected is not 2D. Please select a (one) 2D face before running this command."</p><p>    GoTo cleanupandquit</p><p>End If</p><p>    </p><p>        </p><p>'Save a DXF</p><p>    dataAlignment(0) = 0#</p><p>    dataAlignment(1) = 0#</p><p>    dataAlignment(2) = 0#</p><p>    dataAlignment(3) = 1#</p><p>    dataAlignment(4) = 0#</p><p>    dataAlignment(5) = 0#</p><p>    dataAlignment(6) = 0#</p><p>    dataAlignment(7) = 1#</p><p>    dataAlignment(8) = 0#</p><p>    dataAlignment(9) = 0#</p><p>    dataAlignment(10) = 0#</p><p>    dataAlignment(11) = 1#</p><p>    varAlignment = dataAlignment</p><p></p><p></p><p>'Clean off the file name so that we can add our desired name</p><p>'savepathdxf = SaveLoc</p><p>'### previous code = 'Left(Part.GetPathName, InStrRev(Part.GetPathName, "\\"))</p><p></p><p></p><p>'File name in the standard of PART NO & REV & .DXF</p><p>savepathdxf = SaveLoc & strValue(5) & " " & strValue(6) & ".DXF"</p><p></p><p></p><p>'Export selected face to a DXF</p><p>Part.ExportToDWG2 savepathdxf, Part.GetPathName, <span style="color: #e23d39;">swExportToDWG_ExportSelectedFacesOrLoops</span>, True, varAlignment, False, False, 101, Null</p><p>Part.ClearSelection2 False</p><p></p><p></p><p>GoTo cleanupandquit</p><p></p><p></p><p>'#############################################################</p><p>'DRAWING (this macro started while a drawing was active )</p><p>'#############################################################</p><p>GoTo cleanupandquit</p><p></p><p></p><p>cleanupandquit:</p><p>Part.DeleteConfiguration (Part.GetActiveConfiguration.Name & "SM-FLAT-PATTERN")</p><p>Set swApp = Nothing</p><p>Set Part = Nothing</p><p>Set SelMgr = Nothing</p><p></p><p></p><p>cleanupandquitnopart:  'only called if no part is loaded</p><p>Set swApp = Nothing</p><p>Set Part = Nothing</p><p>Set SelMgr = Nothing</p><p></p><p></p><p>End Sub</p>
SolidworksApi/macros