2 Replies Latest reply on Oct 10, 2017 4:40 PM by Matt B.

    Midplane Sheet Metal macro Feature Definition Help

    Matt B.

      So I have written a macro that succesfully creates a MidPlane sheetmetal base flange - it creates an offset plane, moves a sketch to that plane, creates a sheetmetal flange, and then adds equations to make the plane offset be the half-width of the sheetmetal.

       

      My problem is that my code currently makes all of the sheet metal features use the newly selected thickness, instead of just the new feature. (I.E. I want this new flange to be it's own thickness from a table, selectable by user. But this new selection gets applied globally, instead of just locally)

       

      Also, critically, SolidWorks doesn't create a "D7@Sheet-Metal#" custom thickness dimension to use in the above equations.

       

      Does anybody have any idea why these two things happen? Here's the operative code:

       

      -------------------

      Dim featDef As SldWorks.BaseFlangeFeatureData

      Set featDef = swFeatmgr.CreateDefinition(swFmBaseFlange)

       

      ' need to ask user for thickness preference

      nStatus = swSMFeatData.GetUseGaugeTable(bRet, sTableFile)

       

      featDef.BendRadius = swSMFeatData.BendRadius

      featDef.D1OffsetDistance = 0#

      featDef.D1OffsetType = 0

      featDef.D1ReverseOffset = False

      featDef.D2OffsetDistance = 0#

      featDef.D2OffsetType = 0

      featDef.D2ReverseOffset = False

      featDef.OffsetDirections = 0

      featDef.ReverseDirection = False ' This line seems to control closed-profile base flange thickness direction.

      featDef.ReverseThickness = False

       

      'All of the following values depend on the previous values;

      ' you must set these values in sequence

      featDef.UseGaugeTable = True

       

      ' Set the path to the sheet metal gauge tables

      featDef.GaugeTablePath = sTableFile

       

      ThicknessNames = featDef.GetTableThicknesses()

       

      If (IsEmpty(ThicknessNames)) Then

          MsgBox "ERROR: No sheetmetal table. At this time,this sheet metal body cannot be the first one in the model."

          'TODO: Load thickness table seperately, use userform input to create sheetmetal

         

          End

      Else

       

          gThicknessNames = ThicknessNames

       

         ' get user input

          UserForm1.Show

         

      End If

        

      ' Set override values

      If gUseDefault Then

          override = False

      Else

          override = True

      End If

       

       

      If (override = True) Then

          featDef.OverrideRadius = False

          featDef.OverrideThickness = True 'False ' hoping this lets the system choose table radius and kfactor

          featDef.OverrideKFactor = False

         

          featDef.ThicknessTableName = gUserThickness

         

      Else

          featDef.OverrideRadius = False

          featDef.OverrideThickness = False

          featDef.OverrideKFactor = False

      End If

       

      Set swNewFeat = swFeatmgr.CreateFeature(featDef)

        • Re: Midplane Sheet Metal macro Feature Definition Help
          Manikandan Babu

          Hi Matt B,

           

          Lets try with sheet metal feature data.

          Created the separate base flanges and then modifying the second base flange thickness using sheet-metal2 through SheetMetalFeatureData API.

           

          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swfeat As SldWorks.Feature

          Dim swSheetMetal  As SldWorks.SheetMetalFeatureData

          Sub main()

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swfeat = swmodel.FeatureByName("Sheet-Metal2")

          Set swSheetMetal = swfeat.GetDefinition

          swSheetMetal.AccessSelections swmodel, Nothing

          swSheetMetal.SetUseGaugeTable False, ""

          swSheetMetal.Thickness = 10 / 1000

          swfeat.ModifyDefinition swSheetMetal, swmodel, Nothing

          End Sub

           

           

          Manikandan

            • Re: Midplane Sheet Metal macro Feature Definition Help
              Matt B.

              This doesn't seem to work.

               

              All of the methods I can think of to change the thickness will change the default, and none of them create "D7@Sheet-metal#".

              the other method involves using the BaseFlangeFeatureData and a call to Feature::ModifyDefinition

               

              if I SetOverrideDefaultParameter (True) on swSheetMetal, it errors out the base-flange feature. When I go back and manually accept the settings, it DOES create D7, which is interesting.