3 Replies Latest reply on Nov 3, 2015 4:52 AM by Amen Allah Jlili

    K Factor

    Hrituc Alexandru

      Hi,

       

      I try to make a macro to change value for K Factor and for the moment I didn't made it ... it's possible to create a macro like this?

      Thanks

      1.jpg

        • Re: K Factor
          Hrituc Alexandru

          With this code i can modify only for mitter flange

           

          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''

           

          Option Explicit

           

           

          Dim swApp As SldWorks.SldWorks

          Dim Part As SldWorks.ModelDoc2

          Dim boolstatus As Boolean

          Dim FeatureData As SldWorks.MiterFlangeFeatureData

          Dim Feature As SldWorks.Feature

          Dim Component As SldWorks.Component

          Dim bData As SldWorks.CustomBendAllowance

          Dim nam As String

           

           

          Sub main()

           

           

              Set swApp = CreateObject("SldWorks.Application")

              Set Part = swApp.ActiveDoc

            

           

           

              ' Get the selected feature

              Set Feature = Part.SelectionManager.GetSelectedObject6(1, -1)

            

           

           

              ' Get the name of the selected feature

              nam = Feature.GetTypeName

            

           

           

              ' Get the feature definition

              Set FeatureData = Feature.GetDefinition

            

           

           

              ' Get whether to use default bend allowance to determine the current state

              Dim useCustom As Boolean

              useCustom = FeatureData.UseDefaultBendAllowance

            

           

           

              ' Get the custom bend allowance object

              Set bData = FeatureData.GetCustomBendAllowance

            

           

           

              Dim bType As Long

              bType = bData.Type

              ' Set the bend allowance type to deduction

              bData.Type = swBendAllowanceDeduction

            

           

           

              ' Set the value of the bend deduction

              bData.KFactor = 0.2841

            

           

           

              FeatureData.UseDefaultBendAllowance = False

            

           

           

              ' Set the value of the bend deduction

              Call FeatureData.SetCustomBendAllowance(bData)

            

           

           

              ' Modify the feature definition

              boolstatus = Feature.ModifyDefinition(FeatureData, Part, Component)

           

           

          End Sub

           

           

          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            • Re: K Factor
              Hrituc Alexandru

              I succedeed!  ..here's the code:

               

              ''''''''''''''''''''''''''''''''''''''''''''''''''

              Option Explicit

               

               

              Dim swApp As SldWorks.SldWorks

              Dim Part As SldWorks.ModelDoc2

              Dim boolstatus As Boolean

              Dim FeatureData As SldWorks.SheetMetalFeatureData

              Dim Feature As SldWorks.Feature

              Dim Component As SldWorks.Component

              Dim bData As SldWorks.CustomBendAllowance

              Dim nam As String

               

              Sub main()

                  Set swApp = CreateObject("SldWorks.Application")

                  Set Part = swApp.ActiveDoc

                 

                  ' Get the selected feature

                  Set Feature = Part.SelectionManager.GetSelectedObject6(1, -1)

                 

                  ' Get the name of the selected feature

                    nam = Feature.GetTypeName

               

               

                  ' Get the feature definition

                  Set FeatureData = Feature.GetDefinition

               

                  ' Get whether to use default bend allowance to determine the current state

                 'Dim useCustom As Boolean

                 'useCustom = FeatureData.UseDefaultBendAllowance

                

                  ' Get the custom bend allowance object

                  Set bData = FeatureData.GetCustomBendAllowance

                  Dim bType As Long

                  bType = bData.Type

                 

                  ' Set the bend allowance type to deduction

                  bData.Type = swBendAllowanceDeduction

               

                  ' Set the value of the bend deduction

                  bData.KFactor = 0.2841

               

                 'FeatureData.UseDefaultBendAllowance = False

               

                  ' Set the value of the bend deduction

                  Call FeatureData.SetCustomBendAllowance(bData)

               

                  ' Modify the feature definition

                  boolstatus = Feature.ModifyDefinition(FeatureData, Part, Component)

                 

              End Sub