holewizard macro problem
holewizard macro problem
(OP)
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?
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?
RE: holewizard macro problem
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
"Node news is good news."
RE: holewizard macro problem
The code listed above doesn't work and any combinations tried resulted in interesting (and wrong) results. Some of these results could not be fixed in code. Unless I am missing something, the guys at SolidWorks have some serious bugs or, more likely, didn't bother to actually make the API commands work the way they were supposed to.
The only way I have found this can be done is to place a temporary point on the part. Then you create and new hole using HoleWizard3 and use CopyWizardHole to update the hole you want to change. Then you have to delete the hole you just created. A VERY bizzarre way to have to do this.
You would think changing the type and/or size of a wizard hole would be something lots of people would want to do - its an almost required thing to do for automated design.
This issue has been somewhat typical for us. Problems like this are beyond what our then provider could understand and no help from Solidworks was ever forthcoming. We did not know why we were paying them the $1,000s for "support" so we stopped.
RE: holewizard macro problem
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: holewizard macro problem
RE: holewizard macro problem
Use the following:
site:eng-tips.com SolidWorks CAD VBA API
I got 413 hits, all in the 3D CAD forum. People that hang out on this forum only want to discuss FEA, CFD and Kinematics. Thanks.
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."