Macro For Establishing Bend Deduction, Changing Units, Exporting Flat Pattern DXF

Hello,

 

I'm pretty new to macros but have had some success with smaller internal projects. I'm unsure of what I'm trying to accomplish is possible. 

 

High Level Work Flow - 

 

VBA Macro run within Solidworks on an individual part, or looped and run on a folder.

 

1st step) Identify Material and determine work flow accordingly.

 

If NOT Sheet metal, create 1:1 DXF of Front Plane. 

 

If Sheet Metal, identify thickness, apply bend deduction based on material and thickness, then export DXF 1:1 flat pattern in inches with forming tools.

 

We model in metric, but our manufacturing equipment programs in inch, so our current workflow is to change the methods and export a DXF. 

 

I've got everything working on this with two exceptions. My DXFs are importing into our programming software and when measuring, are showing that they are the correct length, but the flat pattern is actually twice as large as it should be. 

 

I also have not had any success in being able to set the bend deduction through macro. We have thousands of legacy parts that aren't on our current standard for bend deduction. Going forward we can use a bend table, but as these legacy parts come up, we want a fast way to apply current standards and get a flat pattern. 

 

here is the code I'm using for the sheet metal logic currently that is working to the point that I'm getting a flat pattern but not scaled correctly (I also need to allow for the possibility that some parts may be in inch and dont require further scaling). 

 

   ' === Sheet Metal Logic ===
   Dim swFeat As Feature
   Dim swSheetMetal As SheetMetalFeatureData
   Dim thicknessMeters As Double
   Dim thicknessInches As Double
   
   Set swFeat = swModel.FirstFeature
   Do While Not swFeat Is Nothing
       If swFeat.GetTypeName2 = "SheetMetal" Then
           Set swSheetMetal = swFeat.GetDefinition
           Exit Do
       End If
       Set swFeat = swFeat.GetNextFeature
   Loop
   
   If swSheetMetal Is Nothing Then Exit Sub
   
   thicknessMeters = swSheetMetal.Thickness
   thicknessInches = thicknessMeters * 39.3701
   thicknessInches = Round(thicknessInches, 3)
   Dim sheetMetalOptions As SheetMetalOptions_e
   sheetMetalOptions = Geometry Or HiddenEdges Or BendLines Or FormingTools
       
   Dim flatPatternFeature As Feature
Set flatPatternFeature = swPart.FeatureByName("Flat-Pattern")
If Not flatPatternFeature Is Nothing Then
   flatPatternFeature.SetSuppression2 1, 2, Nothing
   swModel.ForceRebuild3 False
   Debug.Print "Flat Pattern unsuppressed and rebuilt."
Else
   Debug.Print "Flat Pattern feature not found."
End If
   
       
   Dim success As Boolean
   Debug.Print "STEP 6: Attempting ExportToDWG2..."
success = swPart.ExportToDWG2(newFilePath, filePath, swExportToDWG_e.swExportToDWG_ExportSheetMetal, True, Nothing, False, False, 0, Nothing)
If success Then
   Debug.Print "STEP 7: ExportToDWG2 SUCCESS: " & newFilePath
Else
   Debug.Print "STEP 7: ExportToDWG2 FAILED."