1 Reply Latest reply on Oct 21, 2013 1:14 PM by Luke Heckrodt

    Sheet Metal Bend Allowance Type not changing correctly

    Luke Heckrodt

      I am finding that parts created with Solidworks 2013 or Solidworks 2014 seem to not update their BendAllowanceType when it is changed in code. The BendAllowanceType can be changed in the Sheet-Metal feature by selecting either Bend Table, K-Factor, Bend Allowance, etc in the drop down menu in the Edit Feature pane. The BendAllowanceType changes when changed in code for parts created in older versions of Solidworks.

       

      The difference I see between previous parts and parts created with Solidworks>2012 is that there is an additional child Sheet-Metal item under the Sheet-Metal feature in the feature tree.

       

      Here is my code that changes the BendAllowanceType in older versions of Solidworks, but not in newer versions.

       

      Dim swModel As ModelDoc2 = Iswapp.IActiveDoc

      swModel.DeleteBendTable()      'Delete old bend table so the new one is loaded from the xls file - this changes the BendAllowanceType back to k-factor which is not what we want

       

      model = swModel

      Dim bendTable As String = "C:\BendTable.xls"

      Dim smFeatData As SheetMetalFeatureData

      Dim featName As String

      Dim swCustBendAllow As CustomBendAllowance

       

       

      For Each swFeat As Feature In model.FeatureManager.GetFeatures(True)

          featName = swFeat.GetTypeName()

          If featName = "SheetMetal" Then

            

             'Insert bend table - do not want k-factor

             smFeatData = swFeat.GetDefinition

       

             'trying this out to see if it works. Doesn't work with new parts but works with old parts

             smFeatData.AccessSelections(swModel, Nothing)

             swCustBendAllow = smFeatData.GetCustomBendAllowance

             swCustBendAllow.Type = swBendAllowanceTypes_e.swBendAllowanceBendTable ' changes the Type to a 1 which looks correct but the Sheet-Metal feature does not change in the bend allowance section

             smFeatData.SetCustomBendAllowance(swCustBendAllow)

             swFeat.ModifyDefinition(smFeatData, swModel, Nothing)

       

             'Old method which only works with parts created with sw<2013 where the sheetmetal feature does not have a subfeature

             smFeatData.BendAllowanceType = swBendAllowanceTypes_e.swBendAllowanceBendTable

             smFeatData.BendTableFile = bendTable

             swFeat.IModifyDefinition2(smFeatData, model, Nothing)

          End If

      Next

       

      I have been struggling with this for over a year and figured it would be fixed in Solidworks 2014 but it has not been.

       

      Thank you, Luke

       

      Here is the bend allowance asetting that goes back to k-factor when the above code is run for a part created in sw2013 or sw2014.

      editFeature.jpg

       

      Here's the feature tree for a part created in sw2012. Notice that there is no sheet-metal feature under the sheet-metal feature.

      sw2012part-no subFeature.jpg

       

      Here's the feature tree for a part created in sw2014. Notice that there is a sheet-metal feature under the sheet-metal feature. I'm not sure if this is what is causing the issue, but it's the only difference I see. I tried going to the firstchild after getting to the sheetmetal feature but it returned Nothing.

       

      sw2014part-subFeature.jpg

        • Re: Sheet Metal Bend Allowance Type not changing correctly
          Luke Heckrodt

          I would like to add some additional comments on things I have been trying to get around this issue.

           

          I found that if I do not delete the current bend table by calling swModel.DeleteBendTable() then the Bend Allowance type does not change back to K-Factor.

           

          When I change to a K-Factor in code, and then back to the bend table, this appears to reload the bend table (the xls file opens and I see the spreadsheet being read), but then the new values in the updated bend table still aren't used.

           

          Dim swModel As ModelDoc2 = Iswapp.IActiveDoc

          Dim bendTable As String = "C:\BendTable.xls"

          Dim smFeatData As SheetMetalFeatureData

          Dim swCustBendAllow As CustomBendAllowance

          Dim featName As String

           

          For Each swFeat As Feature In model.FeatureManager.GetFeatures(True)

             featName = swFeat.GetTypeName()

             If featName = "SheetMetal" Then

           

                'First change to k-factor - need to do this step to get it to re-load the bend table without calling delete beforehand

                '(delete changed the selection in the feature tree to k-factor), but changing below does not change it in the Feature Tree

                smFeatData.AccessSelections(swModel, Nothing)

                swCustBendAllow = smFeatData.GetCustomBendAllowance

                swCustBendAllow.Type = swBendAllowanceTypes_e.swBendAllowanceKFactor ' change to k-factor

                smFeatData.BendTableFile = bendTable

                smFeatData.SetCustomBendAllowance(swCustBendAllow)

                swFeat.ModifyDefinition(smFeatData, swModel, Nothing)

           

                'Must do this to get it to reload the bend table.

                smFeatData.BendAllowanceType = swBendAllowanceTypes_e.swBendAllowanceBendTable

                smFeatData.BendTableFile = bendTable

                swFeat.IModifyDefinition2(smFeatData, model, Nothing) ' looks like it re-loads the bend table here - excel files opens in SW

             End If

          Next

           

          The above code appears to re-load the bend table, but unfortunately the new values in the bend table are not used when the drawing is re-created and the dimensions are checked at bend locations. The bend dimensions are still using the old bend table values. Whatn else should I do?

           

          Thanks again for the support,

           

          Luke