How to update K-Factor through API

Discussion in 'SolidWorks' started by Steve Fye, Aug 18, 2004.

  1. Steve Fye

    Steve Fye Guest

    Ok, I'm pulling my hair out over this one. This subroutine was
    modified from the "Get all sheetmetal feature data" example. I got
    the example running fine, but I'm trying to get it to change the
    K-Factor for a part. It simply won't do it. The value for
    swCustBend.KFactor is updated, but not the model.

    Any help is greatly appreciated. Here is the subroutine in question
    (the code in question has been commented for convenience):

    'Begin Code

    Sub Process_SheetMetal(swApp As SldWorks.SldWorks, swModel As
    SldWorks.ModelDoc2, swFeat As SldWorks.Feature)

    Dim swSheetMetal As SldWorks.SheetMetalFeatureData
    Dim swCustBend As SldWorks.CustomBendAllowance

    Set swSheetMetal = swFeat.GetDefinition
    Set swCustBend = swSheetMetal.GetCustomBendAllowance

    Debug.Print "PROCESS SHEET METAL"
    Debug.Print " +" & swFeat.Name & " [" & swFeat.GetTypeName & "]"
    Debug.Print " BendRadius = " & swSheetMetal.BendRadius * 1000#
    & " mm"

    'Change Default Bend Radius
    Dim bRet As Boolean
    Dim NewBendRadius As Double

    ' Rollback to change default bend radius
    bRet = swSheetMetal.AccessSelections(swModel, Nothing):
    Debug.Assert bRet

    ' Set new bend radius value
    NewBendRadius = (0.083 * 25.4 / 1000)
    swSheetMetal.BendRadius = NewBendRadius


    ' Apply changes to model
    bRet = swFeat.ModifyDefinition(swSheetMetal, swModel,
    Nothing): Debug.Assert bRet

    'Display Results
    Debug.Print " New BendRadius = " & swSheetMetal.BendRadius
    * 1000# & " mm"
    Debug.Print " K-Factor (old) = " & swCustBend.KFactor



    '===========================================================================
    '===========================================================================
    '===========================================================================
    'Change Default KFactor
    Dim NewKFactor As Double

    Set swSheetMetal = swFeat.GetDefinition
    Set swCustBend = swSheetMetal.GetCustomBendAllowance

    ' Set new KFactor value
    NewKFactor = 0.456
    swCustBend.KFactor = NewKFactor

    'Apply changes
    'THIS LINE DOES NOT APPEAR TO UPDATE THE ACTUAL MODEL
    bRet = swFeat.ModifyDefinition(swSheetMetal, swModel,
    Nothing): Debug.Assert bRet

    'Display Results
    Debug.Print " K-Factor (new) = " & swCustBend.KFactor

    'THe above line displays the correct new K-Factor. The model
    still does not get updated.
    '===========================================================================
    '===========================================================================
    '===========================================================================


    Process_CustomBendAllowance swApp, swModel, swCustBend

    End Sub
    'End Code
     
    Steve Fye, Aug 18, 2004
    #1
  2. Did you try rebuilding

    Corey

     
    Corey Scheich, Aug 18, 2004
    #2
  3. Steve Fye

    Steve Fye Guest


    Not through the API, but after the macro has run, I manually rebuild,
    and check the K-Factor (REdefine Feature for Sheet MEtal) it's still
    the original value. Nothing changes.

    Help!
     
    Steve Fye, Aug 19, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.