1 Reply Latest reply on Dec 30, 2015 7:40 PM by Michael Spens

    How to change size of tapped hole?

    Yong Ning

      Hole Specification

      The Hole Specification options vary depending on the hole type. Use the PropertyManager images and descriptive text to set the options.

       

      5.jpg

       

      Help me , Size. Select a size for the fastener → M16 Change M20

       

      **********************************************

      Follow code, don't change M16 → M20

       

      tmp = .ChangeStandard(swStandardISO, swStandardISOTappedHole, "M20")

      Result is True

       

       

      6.jpg

       

       

      Private Sub ll2()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

            Set SwApp = Application.SldWorks

            Set SwModel = SwApp.ActiveDoc

         Dim SwSelMgr As SelectionMgr

            Set SwSelMgr = SwModel.SelectionManager

         Dim Feature As SldWorks.Feature

         Dim SwFeatData As SldWorks.WizardHoleFeatureData2

             ' Here Write code for selecting the feature

             Set Feature = SwSelMgr.GetSelectedObject5(1)

             Set SwFeatData = Feature.GetDefinition

             ''

             With SwFeatData

                tmp = .ChangeStandard(swStandardISO, swStandardISOTappedHole, "M20")

                Stop

             End With

      End Sub

       

      *******************************************************

       

      WizardHoleFeatureData2::FastenerSize→This property allows you to get the fastener size for this hole.

       

      Hope, set the fastener size for this hole.

       

       

      WizardHoleFeatureData2 API problem | SOLIDWORKS Forums

      https://forum.solidworks.com/message/383777#383777

        • Re: How to change size of tapped hole?
          Michael Spens

          Hello Young,

               When editing an existing feature through the API, you must surround the edit with FeatureData.AccessSelections and Feature.ModifyDefinition.  I've added a couple lines to your code and it should work now.

           

          Private Sub ll2()

             Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                Set SwApp = Application.SldWorks

                Set SwModel = SwApp.ActiveDoc

             Dim SwSelMgr As SelectionMgr

                Set SwSelMgr = SwModel.SelectionManager

             Dim Feature As SldWorks.Feature

             Dim SwFeatData As SldWorks.WizardHoleFeatureData2

                 ' Here Write code for selecting the feature

                 Set Feature = SwSelMgr.GetSelectedObject5(1)

                 Set SwFeatData = Feature.GetDefinition

                 ''

                 With SwFeatData

                      Call .AccessSelections(SwModel, Nothing)

                      tmp = .ChangeStandard(swStandardISO, swStandardISOTappedHole, "M20")

                      Call Feature.ModifyDefinition(SwFeatData, SwModel, Nothing)

                 End With

          End Sub