Hey guys/gals,
I'm having issues getting the Hole Wizard feature to behave. The (VBA) macro that I've created is working smoothly, doing everything that I want it to. It will take a number of user selections, insert some 3D sketches, and insert the Hole Wizard feature. The problem that I am having is post-macro, where the Hole Wizard end conditions aren't necessarily being met. The strange thing is that this will only happen with one or two holes from the set, whereas I could see if I goofed up the end conditions when initializing the feature, but that's not the case when I go to check later.
See above (red markup). I can't seem to understand what is causing this behavior, so I'd like to ask the comunity if they have or have not experienced this when using the Hole Wizard Feature.
Relevant code:
This is the function used to insert the sketch points:
' Inserts new hole wizard sketch points
' Adds sketch relations to fully define sketch
Sub InsertSketchPoints(vSketchPtIDs As Variant, swFace As SldWorks.Face2)
Dim swSketchMgr As SldWorks.SketchManager
Set swSketchMgr = swModel.SketchManager
Dim swSketch As SldWorks.Sketch
Set swSketch = swSketchMgr.ActiveSketch
Dim swSketchRelationMgr As SldWorks.SketchRelationManager
Set swSketchRelationMgr = swSketch.RelationManager
Dim swSketchRelation1 As SldWorks.SketchRelation
Dim swSketchRelation2 As SldWorks.SketchRelation
Dim tempPoint As SldWorks.SketchPoint
Dim tempPointID As Variant
Dim newPoint As SldWorks.SketchPoint
Dim newRelations(1) As Object
Dim p1 As Variant
Dim p2 As Variant
Dim dist As Double
Dim err As Long
Dim i As Integer
' Add sketch objects to DataBase
' Enabled
' Ensures sketch points aren't snapped to one another
' during operation
swSketchMgr.AddToDB = True
' Loop # points
For i = 0 To UBound(vSketchPtIDs)
' Convert base 64 string to array required for persistent reference ID
tempPointID = Base64ToArray(CStr(vSketchPtIDs(i)))
' Get point (from DivideSegment sketch)
Set tempPoint = swModel.Extension.GetObjectByPersistReference3(tempPointID, err)
dist = swModel.ClosestDistance(tempPoint, swFace, p1, p2)
' If point is on face, then it is valid
' Certain points and erroneously be added to the array such as sketch arcs centerpoints
' These need to be filtered out
If Round(dist, 3) = 0 Then
' Create point, but only at the desired location
' Needs relations added manually
Set newPoint = swSketchMgr.CreatePoint(tempPoint.X, tempPoint.Y, tempPoint.Z)
swModel.ClearSelection2 True
Set newRelations(0) = newPoint
Set newRelations(1) = tempPoint
If swSketch.Is3D Then
' AlongZ relation between points
' Coincident is ideal, but causes restraint errors because of the On Surface relation
' that's added in the next step
Set swSketchRelation1 = swSketchRelationMgr.AddRelation(newRelations, swConstraintType_ALONGZPOINTS)
swModel.ClearSelection2 True
Set newRelations(1) = swFace
' On Surface relation
' Uses face selected by user
' Uses sketch point from DivideSegment sketch
Set swSketchRelation2 = swSketchRelationMgr.AddRelation(newRelations, swConstraintType_COINCIDENT)
swModel.ClearSelection2 True
Else
Set swSketchRelation1 = swSketchRelationMgr.AddRelation(newRelations, swConstraintType_COINCIDENT)
swModel.ClearSelection2 True
End If
' Reset variables
Set newPoint = Nothing
Set tempPoint = Nothing
Set newRelations(0) = Nothing
Set newRelations(1) = Nothing
Set p1 = Nothing
Set p2 = Nothing
End If
Next i
DoEvents
swModel.ClearSelection2 True
' Add sketch objects to DataBase
' Disabled
swSketchMgr.AddToDB = False
' Exit Hole Wizard Sketch
swSketchMgr.InsertSketch True
End Sub
Code to create the Hole Wizard feature:
' Object to create and initialize hole wizard feature
Set swFeatDataObj = swFeatMgr.CreateDefinition(swFmHoleWzd)
Set swWzdHoleFtr = swFeatDataObj
' Settings for initialization
swWzdHoleFtr.InitializeHole swWzdHole, swStandardAnsiInch, swStandardAnsiInchAllDrillSizes, "#40", swEndCondThroughNext
' Must have face selected for hole wizard creation
Set swEnt = swFace
swEnt.Select4 False, Nothing
' Create Hole Wizard Feature
Set swHoleFeat = swFeatMgr.CreateFeature(swWzdHoleFtr)
Does the API inherently make any particular feature behave in a way that it wouldn't normally behave? Is my part file somewhat corrupted? I can't even figure out where to start in fixing this issue. Hoping some gurus can give some guidance on this as it's a bit frustrating.
Thanks!
Austin
SolidworksApi/macros