Hello everyone! May I ask SOLIDWORKS2016 VBA how to use Hole Wizard to punch Φ10 holes?
Hello everyone! May I ask SOLIDWORKS2016 VBA how to use Hole Wizard to punch Φ10 holes?
Thank you Fifi Riri, but these are examples of threaded holes, what I need are examples of holes such as "swWzdHole.InitializeHole swWzdCounterBore, swStandardISO, swStandardISOHexBolt, "M48", swEndCondBlind",How to modify "M48" into "Φ10"
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeat As SldWorks.Feature
Dim swWzdHole As WizardHoleFeatureData2
Dim swFeatDataObj As Object
Dim boolstatus As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set swFeatMgr = swModel.FeatureManager
' Create the hole wizard feature data object
Set swFeatDataObj = swFeatMgr.CreateDefinition(swFmHoleWzd)
Set swWzdHole = swFeatDataObj
' Initialize the hole wizard feature
swWzdHole.InitializeHole swWzdGeneralHoleTypes_e.swWzdHole, swWzdHoleStandards_e.swStandardAnsiMetric, swWzdHoleStandardFastenerTypes_e.swStandardAnsiMetricDrillSizes, "Ø10.0", swEndConditions_e.swEndCondBlind
'Change the hole wizard feature's depth
'swWzdHole.HoleDepth = 0.15
'Change the hole wizard feature's diameter
'swWzdHole.HoleDiameter = 0.01
' Select the face on which to create the hole
boolstatus = swModelDocExt.SelectByID2("", "FACE", 9.30621655732011E-03, 3.96239999998897E-02, -3.32715966641217E-03, False, 0, Nothing, 0)
' Create the hole wizard feature
Set swFeat = swFeatMgr.CreateFeature(swWzdHole)
End Sub
With multiple points:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swFeat As SldWorks.Feature
Dim swWzdHole As WizardHoleFeatureData2
Dim swFeatDataObj As Object
Dim swSketchFeature As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim swSketchPointArray As Variant
Dim swSkPoint As SldWorks.SketchPoint
Dim boolstatus As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
boolstatus = swModel.Extension.SelectByID2("", "FACE", 0, 0, 0, False, 0, Nothing, 0)
Set swFeatDataObj = swModel.FeatureManager.CreateDefinition(swFmHoleWzd)
Set swWzdHole = swFeatDataObj
swWzdHole.InitializeHole swWzdGeneralHoleTypes_e.swWzdHole, swWzdHoleStandards_e.swStandardAnsiMetric, swWzdHoleStandardFastenerTypes_e.swStandardAnsiMetricDrillSizes, "Ø10.0", swEndConditions_e.swEndCondBlind
Set swFeat = swModel.FeatureManager.CreateFeature(swWzdHole)
Set swSketchFeature = swFeat.GetFirstSubFeature
swSketchFeature.Select2 False, 0
swModel.EditSketch
Set swSketch = swSketchFeature.GetSpecificFeature2
swSketchPointArray = swSketch.GetSketchPoints2
Set swSkPoint = swSketchPointArray(0)
swSkPoint.Select4 False, Nothing
swModel.EditDelete
Set swSkPoint = swModel.SketchManager.CreatePoint(0.01, 0.01, 0)
Set swSkPoint = swModel.SketchManager.CreatePoint(-0.01, -0.01, 0)
swModel.SketchManager.InsertSketch True
End Sub