I'm trying to programatically toggle a hole between tapped and simple. I found the Tapped property in the object browser but when I try to use it I get a "Method 'Tapped' of object 'HoleFeature' failed" error.
Public Sub setThd(tap As Boolean, doc As PartDocument) Dim hole As HoleFeature Dim holes As HoleFeatures Set holes = doc.ComponentDefinition.Features.HoleFeatures For Each hole In holes If hole.HealthStatus <> kSuppressedHealth Then hole.tapped = tap End If Next End Sub
Any thoughts are appreciated,
Mike
Solved! Go to Solution.
Solved by thomaskennedy. Go to Solution.
Hi Mike,
I think you need to use the TapInfo property (Tapped property just returns a true / false)
Create your tap info :
Dim oHoleTapInfo As HoleTapInfo
oHoleTapInfo = odoc.ComponentDefinition.Features.HoleFeatures.CreateTapInfo(True, "ANSI Unified Screw Threads", "7/16-14 UNC", "1B", False, "5mm")
Then set the property :
If hole.HealthStatus <> kSuppressedHealth Then
hole.TapInfo = oHoleTapInfo
End If
Hope this helps!
Tom
Thanks, Tom! That was just what I needed. For some reason I thought that method would only change the information associated with a hole that was already set to tapped and not actually make it tapped. What's odd is that the .tapped property is what's needed to switch it back to simple. I suppose Inventor needs to be re-fed the info every time it "taps" the hole?
Here's the code that worked for me if anyone wants it:
Public Sub setThd(tap As Boolean, doc As PartDocument, thd As String) Dim hole As HoleFeature Dim holes As HoleFeatures Set holes = doc.ComponentDefinition.Features.HoleFeatures Dim oHoleTapInfo As HoleTapInfo If Right(Left(thd, 2), 1) = "/" Or Right(Left(thd, 3), 1) = "/" Then Set oHoleTapInfo = holes.CreateTapInfo(True, "ANSI Unified Screw Threads", thd, "2B", True) Else Set oHoleTapInfo = holes.CreateTapInfo(True, "ANSI Metric M Profile", thd, "2B", True) End If For Each hole In holes If hole.HealthStatus <> kSuppressedHealth Then If tap = True Then hole.TapInfo = oHoleTapInfo Else hole.tapped = False End If End If Next End Sub
Tanks,
I was struggling with this, and with this code it did not seem to work form me.
the problem was that I used a hole in my test part with linear placement, but without the reference dimensions...
in a normal part, you would always enter these reference dimensions, but for my test part I didn't and I could not change the hole with this VB-code. after entering the two dimensions it worked..