5 Replies Latest reply on Dec 29, 2015 9:37 AM by Yong Ning

    WizardHoleFeatureData2 API problem

    Vinicius Pontes



      I'm trying to write a function which will change the "Size" of a "Tapped hole" hole wizard type.


      My HoleWizard feature has the hole in 3 positions, like the picture below. The problem is that only one of them is changed correctly. The oders show a wrong cosmetc, which is reflected in the drawing.


      I'm changing from M16 to M30, for example. The inner diameter is updated correctly, but the outer don't.


      Does anybody know why it's happening?


      I've notice that after the function completes its job, if I edit the feature and finishe edition without changing anything, the cosmetics is updated.


      Thanks for any help,




      C++ code below:


      bool ChangeHoleWizardSize(IModelDoc2 *pModel, LPCTSTR featureName, LPCTSTR value)


                HRESULT hr = S_OK;

                VARIANT_BOOL ok = VARIANT_FALSE;


                IModelDocExtensionPtr ptrModelDocExt = NULL;



                struct IDispatch *pDispatch = NULL;

                hr = pModel->get_SelectionManager(&pDispatch);


                ISelectionMgrPtr ptrSelMgr = NULL;

                pDispatch->QueryInterface(__uuidof(ISelectionMgr), reinterpret_cast<void**>(&ptrSelMgr));



                ICalloutPtr ptrCallout = NULL;

                hr = ptrModelDocExt->SelectByID2(_bstr_t(featureName), _bstr_t("BODYFEATURE"), 0, 0, 0, VARIANT_FALSE, 0, ptrCallout, 0, &ok);

                if ( ok == VARIANT_FALSE )


                          return false;



                hr = ptrSelMgr->GetSelectedObject5(1, &pDispatch);


                IFeaturePtr ptrFeat = NULL;

                pDispatch->QueryInterface(__uuidof(IFeature), reinterpret_cast<void**>(&ptrFeat));



                IWizardHoleFeatureData2Ptr ptrHoleWiz = NULL;


                pDispatch->QueryInterface(__uuidof(IWizardHoleFeatureData2), reinterpret_cast<void**>(&ptrHoleWiz));



                long nStandard = swStandardDIN;

                long nFastnerType = swStandardDINTappedHole;

                hr = ptrHoleWiz->get_Standard2(&nStandard);

                hr = ptrHoleWiz->get_FastenerType2(&nFastnerType);


                hr = ptrHoleWiz->AccessSelections(pModel, NULL, &ok);

                hr = ptrHoleWiz->ChangeStandard(nStandard, nFastnerType, _bstr_t(value), &ok);


                ptrFeat->IModifyDefinition2(ptrHoleWiz, pModel, NULL, &ok);






                return ( ok != VARIANT_FALSE )?true:false;


        • Re: WizardHoleFeatureData2 API problem
          Vinicius Pontes



          I found out that there is nothing wrong with this function. There is a problem in the API which changes only the first hole cosmetics. To solve this problem I've linked the diameter's dimension of the holes up to the second with the dimension of the first hole:


          This is the first hole:



          This is the second hole:



          I've made the second hole's diameter equals to the first. Doing this, everything works well. You have to do this for every hole up to the second.


          Note: This is only needed when changing the Hole Wizard through API.


          Hope it helps,


          Vinicius Pontes




          For those how are interested, this is a VB version of this function:



          Dim swApp As SldWorks.SldWorks

          Dim Part As ModelDoc2



          Sub main()

              Set swApp = Application.SldWorks

              Set Part = swApp.ActiveDoc


              Dim myModelView As Object

              Set myModelView = Part.ActiveView

              myModelView.FrameState = swWindowState_e.swWindowMaximized

              Part.Extension.SelectByID2 "M18x1.5 Tapped Hole2", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0


              Dim selMgr As SelectionMgr

              Set selMgr = Part.SelectionManager


              Dim feature As feature

              Set feature = selMgr.GetSelectedObject5(1)


              Dim holewiz As IWizardHoleFeatureData2

              Set holewiz = feature.GetDefinition


              Dim std As Long

              std = holewiz.Standard2


              Dim fst As Long

              fst = holewiz.FastenerType2


              Dim tpe As Long

              tpe = holewiz.TapType


              Dim sze As String

              sze = holewiz.FastenerSize


              Dim result As Boolean

              holewiz.AccessSelections Part, Nothing

              result = holewiz.ChangeStandard(std, fst, "M30x2.0")

              result = feature.ModifyDefinition(holewiz, Part, Nothing)



              Part.ForceRebuild3 False

          End Sub

            • Re: WizardHoleFeatureData2 API problem
              Matt Martens

              I am trying to use the method you described above for some hole wizard changes myself. I was wondering if when running your code the tap drill diameter is changing. I cannot get it to change when I run it here. The cosmetic threads change diameter and feature name updates, but i cannot get the tap drill diameter to update.


              Any suggestions?

              • Re: WizardHoleFeatureData2 API problem
                Yong Ning

                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")

                       End With

                       tmp = Feature.ModifyDefinition(SwFeatData, SwModel, Nothing)


                End Sub