Hello everyone,
I often work with holes created using macros, but I would need to create the holes with the tolerance, as shown in the image.
I can't create the hole directly with the tolerance, there are no parameters in my opinion.
Do you know by chance if it is possible to do it, or if it is possible to insert it later via macro by modifying the properties of the hole?
This my base code.
Sub Main()
Dim swapp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swWizHole As SldWorks.WizardHoleFeatureData2
Set swapp = Application.SldWorks
Set swModel = swapp.ActiveDoc
Set swFeatMgr = swModel.FeatureManager
Set swFeat = swFeatMgr.HoleWizard _
( _
swWzdCounterBore, _
swStandardISO, _
swStandardISOHexCapScrew, _
"M6", _
swEndThreadTypeBLIND, _
0.0066, _
0.02, _
0.014547, _
0.004, _
0#, _
1#, _
2.059488517353, _
0#, _
0#, _
0#, _
0#, _
0#, _
0#, _
0# _
)
' Hole creation can fail due to geometry conditions
If swFeat Is Nothing Then
CreateHoleWizardFeature = False
Exit Sub
End If
Set swWizHole = swFeat.GetDefinition
Debug.Print "Feature = " + swFeat.Name
Debug.Print " Type = " & swWizHole.Type
Debug.Print ""
Debug.Print " CosmeticThreadType = " & swWizHole.CosmeticThreadType
Debug.Print " CounterBoreDepth = " & swWizHole.CounterBoreDepth * 1000# & " mm"
Debug.Print " CounterBoreDiameter = " & swWizHole.CounterBoreDiameter * 1000# & " mm"
'1 radian = 180º/p = 57.295779513º or approximately 57.3º
Debug.Print " CounterDrillAngle = " & swWizHole.CounterDrillAngle * 57.3 & " deg"
Debug.Print " CounterDrillDepth = " & swWizHole.CounterDrillDepth * 1000# & " mm"
Debug.Print " CounterDrillDiameter = " & swWizHole.CounterDrillDiameter * 1000# & " mm"
Debug.Print " CounterSinkAngle = " & swWizHole.CounterSinkAngle * 57.3 & " deg"
Debug.Print " CounterSinkDiameter = " & swWizHole.CounterSinkDiameter * 1000# & " mm"
Debug.Print " Depth = " & swWizHole.Depth * 1000# & " mm"
Debug.Print " Diameter = " & swWizHole.Diameter * 1000# & " mm"
Debug.Print " DrillAngle = " & swWizHole.DrillAngle * 57.3 & " deg"
Debug.Print " EndCondition = " & swWizHole.EndCondition
Debug.Print " FarCounterSinkAngle = " & swWizHole.FarCounterSinkAngle * 57.3 & " deg"
Debug.Print " FarCounterSinkDiameter = " & swWizHole.FarCounterSinkDiameter * 1000# & " mm"
Debug.Print " FastenerSize = " & swWizHole.FastenerSize
Debug.Print " FastenerType = " & swWizHole.FastenerType2
Debug.Print " HeadClearance = " & swWizHole.HeadClearance * 1000# & " mm"
Debug.Print " HeadClearanceType = " & swWizHole.HeadClearanceType
Debug.Print " HoleDepth = " & swWizHole.HoleDepth * 1000# & " mm"
Debug.Print " HoleDiameter = " & swWizHole.HoleDiameter * 1000# & " mm"
Debug.Print " MajorDiameter = " & swWizHole.MajorDiameter * 1000# & " mm"
Debug.Print " MidCounterSinkAngle = " & swWizHole.MidCounterSinkAngle * 57.3 & " deg"
Debug.Print " MidCounterSinkDiameter = " & swWizHole.MidCounterSinkDiameter * 1000# & " mm"
Debug.Print " MinorDiameter = " & swWizHole.MinorDiameter * 1000# & " mm"
Debug.Print " NearCounterSinkAngle = " & swWizHole.NearCounterSinkAngle * 57.3 & " deg"
Debug.Print " NearCounterSinkDiameter = " & swWizHole.NearCounterSinkDiameter * 1000# & " mm"
Debug.Print " Standard = " & swWizHole.Standard2
Debug.Print " TapDrillDepth = " & swWizHole.TapDrillDepth * 1000# & " mm"
Debug.Print " TapDrillDiameter = " & swWizHole.TapDrillDiameter * 1000# & " mm"
Debug.Print " ThreadAngle = " & swWizHole.ThreadAngle * 57.3 & " deg"
Debug.Print " ThreadDepth = " & swWizHole.ThreadDepth * 1000# & " mm"
Debug.Print " ThreadDiameter = " & swWizHole.ThreadDiameter * 1000# & " mm"
Debug.Print " ThruHoleDepth = " & swWizHole.ThruHoleDepth * 1000# & " mm"
Debug.Print " ThruHoleDiameter = " & swWizHole.ThruHoleDiameter * 1000# & " mm"
Debug.Print " ThruTapDrillDepth = " & swWizHole.ThruTapDrillDepth * 1000# & " mm"
Debug.Print " ThruTapDrillDiameter = " & swWizHole.ThruTapDrillDiameter * 1000# & " mm"
CreateHoleWizardFeature = True
End Sub

Hi, I am not quite sure, but I guess you need to loop through the sketch and set the values inside of the sketch. As you can see here:
Oh yes, that's right.
If I add the tolerance to the color of the sketch dimension it also appears in the hole menu.
Thanks a lot