Setting Base Flange Bend Allowance

Good Morning, Good Morning!

I am trying to create a macro that will change the CustomBendAllowance from k-Factor to a bend table. I've got what I believe to be the correct code but it wont permanently change the CustomBendAllowance. It runs through perfectly and sends back a true value for the ModifyDefinition but doesn't actually change it.

Thanks for your help!

Ive colored the area in question Red.

Public swApp As SldWorks.SldWorks

Public swModel As SldWorks.ModelDoc2

Public swFeat As SldWorks.feature

Public swSubFeat As SldWorks.feature

Public swSelMgr As SldWorks.SelectionMgr

Public Const STOCK_XREF As String = "J:\CP LIBRARY\CP-KRAUSE MATERIAL REFERENCE.xlsx"

Public Const CP_STEEL As String = "J:\Toolbox\Templates\Ga. Tables\CP-STEEL.xls"

Public Const CP_BEND As String = "J:\Toolbox\Templates\Ga. Tables\CP-BEND DEDUCTIONS.xls"

Public kStock As String

Public cpStock As String

Public cpGauge As String

Public cpRadius As String

Public customPropertyMgr As SldWorks.CustomPropertyManager

Public boolStatus As Boolean

Public component As SldWorks.Component2

Option Explicit

Public gaugeTable As String

Sub Main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swFeat = swModel.FirstFeature

Set customPropertyMgr = swModel.Extension.CustomPropertyManager("")

'get kstocknumber

kStock = swModel.GetCustomInfoValue("", "kstockNumber")

'figure out what stock number/material needs to be used

If swModel.GetType = 1 Then

    Stock_Convert

    Gauge_Table

'Select Base Flange

    Do While Not swFeat Is Nothing

        Select Case swFeat.GetTypeName

            Case "SMBaseFlange"

                Process_SMBaseFlange swApp, swModel, swFeat

            'Case "EdgeFlange"

                'Process_EdgeFlange swApp, swModel, swFeat

        End Select

        Set swFeat = swFeat.GetNextFeature

    Loop

Else

    MsgBox "Can only be used on parts, not assemblies"

    End

End If

End Sub

Function Stock_Convert()

Dim myExcelApp As Object

Dim xlSheet As Variant

'Open excel workbook

Set myExcelApp = CreateObject("Excel.Application")

myExcelApp.Visible = False

myExcelApp.WorkBooks.Open FileName:=STOCK_XREF

'get cpStock from .xls file

Set xlSheet = myExcelApp.ActiveSheet

Dim y As Double

y = 1

Do While xlSheet.Cells(y, 3) <> kStock

    If xlSheet.Cells(y, 3) <> kStock Then

        y = y + 1

    End If

Loop

cpStock = xlSheet.Cells(y, 1)

End Function

Function Gauge_Table()

Dim myExcelApp As Object

Dim xlSheet As Variant

Dim y As Double

'Figure out which gauge to use

Set myExcelApp = CreateObject("Excel.Application")

myExcelApp.Visible = False

myExcelApp.WorkBooks.Open FileName:=CP_STEEL

Set xlSheet = myExcelApp.ActiveSheet

y = 1

Do While xlSheet.Cells(y, 4) <> cpStock

    If xlSheet.Cells(y, 4) <> cpStock Then

        y = y + 1

    End If

Loop

cpGauge = xlSheet.Cells(y, 1)

End Function

Sub Process_SMBaseFlange _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swFeat As SldWorks.feature _

)

'set gauge table parameters

    Debug.Print "  +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"

Dim swBaseFlange As SldWorks.BaseFlangeFeatureData

'Dim component As SldWorks.Component2

    Set swBaseFlange = swFeat.GetDefinition()

       

    swBaseFlange.UseGaugeTable = True

   

    swBaseFlange.GaugeTablePath = CP_STEEL

   

    swBaseFlange.ThicknessTableName = cpGauge

   

    'boolStatus = swFeat.ModifyDefinition(swBaseFlange, swModel, component)

   

'set bend allowance parameters

Set swFeat = swModel.FirstFeature

Do While Not swFeat Is Nothing

        Select Case swFeat.GetTypeName

            Case "SheetMetal"

                Process_SheetMetal swApp, swModel, swFeat

                Exit Do

        End Select

        Set swFeat = swFeat.GetNextFeature

    Loop

  

   boolStatus = swFeat.ModifyDefinition(swCustBend, swModel, component)

  

    Debug.Print "   Gauge Table = " & swBaseFlange.GaugeTablePath

    Debug.Print "   Thickness = " & swBaseFlange.Thickness / 0.0254

    Debug.Print "   ThicknessName = " & swBaseFlange.ThicknessTableName

    Debug.Print "   Used Gauge Table = " & swBaseFlange.UseGaugeTable

   

End Sub

Sub Process_SheetMetal _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swFeat As SldWorks.feature _

)

Dim swSheetMetal As SldWorks.SheetMetalFeatureData

Set swSheetMetal = swFeat.GetDefinition

Dim swCustBend As SldWorks.customBendallowance

Set swCustBend = swSheetMetal.GetCustomBendAllowance

Process_CustomBendAllowance swApp, swModel, swCustBend, swSheetMetal, swFeat

End Sub

Sub Process_CustomBendAllowance _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swCustBend As SldWorks.customBendallowance, _

    swSheetMetal As SldWorks.SheetMetalFeatureData, _

    swFeat As SldWorks.feature _

)

swCustBend.BendTableFile = CP_BEND

swCustBend.Type = 1

Debug.Print "Bend Allowance = " & swCustBend.BendAllowance

Debug.Print "Bend Deduction = " & swCustBend.BendDeduction

Debug.Print "Kfactor = " & swCustBend.KFactor

Debug.Print "   Bend type = " & swCustBend.Type

Debug.Print "   BendTable File = " & swCustBend.BendTableFile

boolStatus = swFeat.ModifyDefinition(swSheetMetal, swModel, component)            <<<

End Sub


SolidworksApi macros