I'm trying to build a list of all HoleWizardFeature(s) on a face in the context of an assembly. This needs to include features that start on the face as well as any thru holes that break through the face. The purpose is to build a selection list for another macro that copies holes from one component to another.
The following function getHolesInFace takes a Face2 and should return an array of Features of type HoleWzd that intersect that face. It fails to get all intersecting holes.
<p>Private Function getHolesInFace(swParentFace As SldWorks.Face2) As Variant</p><p> Dim swFeature As SldWorks.Feature</p><p> Dim swEdge As SldWorks.Edge</p><p> Dim swFace As SldWorks.Face2</p><p> Dim vFaces As Variant</p><p> Dim vEdge As Variant</p><p> Dim swHoleWizardFeatures() As SldWorks.Feature</p><p> </p><p> Dim found As Boolean</p><p> Dim i As Integer</p><p> </p><p> </p><p> ReDim swHoleWizardFeatures(0)</p><p> Set swHoleWizardFeatures(0) = Nothing</p><p> For Each vEdge In swParentFace.GetEdges</p><p> Set swEdge = vEdge</p><p> vFaces = swEdge.GetTwoAdjacentFaces2</p><p> </p><p> 'check the first face from getTwoAdjacentFaces</p><p> Set swFeature = Nothing</p><p> If Not vFaces(0) Is Nothing Then</p><p> Set swFace = vFaces(0)</p><p> Set swFeature = swFace.GetFeature</p><p> Debug.Print swFeature.GetTypeName2</p><p> Debug.Print swFeature.Name</p><p> If Not swFeature.GetTypeName2 = "HoleWzd" Then</p><p> 'set Feature to Nothing if it isn't a HoleWizardFeature</p><p> Set swFeature = Nothing</p><p> End If</p><p> End If</p><p> </p><p><span style="background-color: #f6f6f6;"> 'check the second face from getTwoAdjacentFaces</span></p><p> If swFeature Is Nothing Then</p><p> If Not vFaces(1) Is Nothing Then</p><p> Set swFace = vFaces(0)</p><p> Set swFeature = swFace.GetFeature</p><p> Debug.Print swFeature.GetTypeName2</p><p> Debug.Print swFeature.Name</p><p> If Not swFeature.GetTypeName2 = "HoleWzd" Then</p><p><span style="background-color: #f6f6f6;"> 'set Feature to Nothing if it isn't a HoleWizardFeature</span></p><p> Set swFeature = Nothing</p><p> End If</p><p> End If</p><p> End If</p><p> </p><p> If Not swFeature Is Nothing Then</p><p> 'insert the feature into the array if it is unique</p><p> found = False</p><p> For i = 0 To UBound(swHoleWizardFeatures)</p><p> If Not swHoleWizardFeatures(i) Is Nothing Then</p><p> If swHoleWizardFeatures(i).Name = swFeature.Name Then</p><p> found = True</p><p> Exit For</p><p> End If</p><p> End If</p><p> Next i</p><p> If Not found Then</p><p> If Not swHoleWizardFeatures(0) Is Nothing Then</p><p> ReDim Preserve swHoleWizardFeatures(UBound(swHoleWizardFeatures) + 1)</p><p> End If</p><p> Set swHoleWizardFeatures(UBound(swHoleWizardFeatures)) = swFeature</p><p> End If</p><p> End If</p><p> Next vEdge</p><p> </p><p> Debug.Print "hole Count:"; (UBound(swHoleWizardFeatures) + 1)</p><p> getHolesInFace = swHoleWizardFeatures</p><p>End Function</p>
The Face2 that I pass as an argument is selected in the image below. You can see that the 11.0 dia holes and the 8H7 holes(green) interesect said Face.
Immediate Window:
<p>ICE</p><p>Boss-Extrude5</p><p>ICE</p><p>Boss-Extrude5</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>HoleWzd</p><p>Ø11.0 (11) Diameter Hole1</p><p>HoleWzd</p><p>Ø11.0 (11) Diameter Hole1</p><p>HoleWzd</p><p>Ø11.0 (11) Diameter Hole1</p><p>HoleWzd</p><p>Ø11.0 (11) Diameter Hole1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>ICE</p><p>Cut-Extrude1</p><p>hole Count: 1 </p>
It seems to be finding edges associated with the "11.0 Dia" clearance holes but not the 8H7 reamed holes. Both of these are hole wizard features that appear to intersect the face in question.
I believe I've narrowed the problem down to Face2::GetEdges. It is not returning the edges at the intersection of the 8H7 hole features and the face (selected below).
Looking further, it appears that the CutExtrude feature that generated the Face was created after the 8H7 holes. The 11.0 Dia holes were created after the CutExtrude. I can imagine why that would make a difference but don't know how to use that information to proceed. My function needs to return the H7 hole regardless of its order in the feature tree. There should be a way of accessing those edges.
Does anyone have experience with this? Any suggestions are appreciated.
Thanks,
John Alexander
SolidworksApi macros
change vFaces(0) to vFaces(1)
gah, thanks. I feel like a dolt.