Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Hole Wizard Macro Problem

Status
Not open for further replies.

jefrado

Mechanical
Jun 9, 2006
44
0
0
US
We do most of our design via VBA /Excell/Soliworks programs. We use common drawing files so that means a drawing file has to handle hole sizes that change. Holes can change from various tap sizes to various drilled hole sizes in the same location.

I have been doing this by suppressing unused tapped holes and/or simple holes. This is a pain because the dimensions do not automatically handle this - you either have to have a drawing with all the options dimensioned (and hidden, but that causes problems, too) or you have to manually dimension it every time. Typically, we now have to erase all the unused ones since the hidden dangling dimensions make the drawing a real pain to work with.

In any case, this is the subroutine I am using:

Sub HoleWzChng(WzPart As ModelDoc2, WzHoleId As String, WzHoleSz As String, WzHoleTyp As Long)

Dim boolstatus As Boolean
Dim swFeatMgr As SldWorks.FeatureManager
Dim swFeatDataObj As Object
Dim swWzdHole As WizardHoleFeatureData2
Dim SelMgr As SelectionMgr

Set swFeatMgr = WzPart.FeatureManager

boolstatus = WzPart.Extension.SelectByID2(WzHoleId, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
If boolstatus = False Then Exit Sub
Set SelMgr = WzPart.SelectionManager

Set swFeatDataObj = SelMgr.GetSelectedObject6(1, -1)
WzPart.ClearSelection2 True

Set swWzdHole = swFeatDataObj.GetDefinition

boolstatus = swWzdHole.AccessSelections(WzPart, Nothing)

swWzdHole.Type = WzHoleTyp
If WzHoleTyp = swTapThru Then
boolstatus = swWzdHole.ChangeStandard(swStandardAnsiInch, swStandardAnsiInchTappedHole, WzHoleSz) 'if tapped hole, WzHoleSz is a string like "1/2-13"
swWzdHole.CosmeticThreadType = swCosmeticThreadWithCallout
Else
boolstatus = swWzdHole.ChangeStandard(swStandardAnsiInch, swStandardAnsiInchFractionalDrillSizes, "1") 'if a drilled hole, WZHoleSz is the OD of the hole - still a string
swWzdHole.ThruHoleDiameter = vaL(WzHoleSz) * 0.0254
End If
boolstatus = swFeatDataObj.ModifyDefinition(swWzdHole, WzPart, Nothing)

End Sub

It works, sort of. All the information is put into the hole wizard and the drawing call out is correct, but the model doesn't look right unless you manually go into the hole feature, edit the feature (do nothing), and exit. Restore defaults is not performed and the 2nd sketch (hole profile) has irrellevant junk in it (BIG countersunk hole). Rebuild commands have no effect and neither does a macro trying to do the same thing.

I have done some checking, and the changestandard command is putting in the right values, as near as I can tell, into the definition, but it is getting ignored.

Any body got any ideas?
 
Status
Not open for further replies.
Back
Top