Files
Color hole wizard feature after creation
Code
Module: mMain
'Preconditions: part is open
'Results: when a hole wizard feature is created, its color is changed to red
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Dim listener As clsListener
Sub main()
Set listener = New clsListener
listener.connect
End Sub
Class: clsListener
Dim WithEvents swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim WithEvents swPart As SldWorks.PartDoc
Dim strNewItemName As String
Dim blnFeatAdded As Boolean
Public Sub connect()
Set swApp = Application.SldWorks
If Not swApp.ActiveDoc Is Nothing Then
Set swModel = swApp.ActiveDoc
If swModel.GetType = swDocPART Then Set swPart = swModel
End If
strNewItemName = Empty
blnFeatAdded = False
End Sub
Private Function swApp_ActiveDocChangeNotify() As Long
Set swModel = Nothing
Set swPart = Nothing
Set swModel = swApp.ActiveDoc
If swApp.ActiveDoc.GetType = swDocPART Then Set swPart = swModel
swModel.EditRebuild3
End Function
Private Function swApp_OnIdleNotify() As Long
Dim swFeat As SldWorks.Feature
Dim swHoleWizFeatData As SldWorks.WizardHoleFeatureData2
Dim vProps As Variant
If blnFeatAdded = True Then
Set swFeat = swPart.FeatureByName(strNewItemName)
If swFeat.GetTypeName2 = "HoleWzd" Then
Set swHoleWizFeatData = swFeat.GetDefinition
vProps = swFeat.GetMaterialPropertyValues2(swAllConfiguration, Empty)
'Modify / add to the following case statements if you want to control the colors _
for various types of hole wizard holes
'Select Case swHoleWizFeatData.Type
' Case swCounterBoreBlind
' vProps(0) = 1: vProps(1) = 0: vProps(2) = 0
' Case swHoleBlind
' vProps(0) = 0: vProps(1) = 1: vProps(2) = 0
'End Select
'Delete this next line if you decide to use the case logic above
vProps(0) = 1: vProps(1) = 0: vProps(2) = 0
vProps(3) = 1: vProps(4) = 1: vProps(5) = 0.8
vProps(6) = 0.3125: vProps(7) = 0: vProps(8) = 0
swFeat.SetMaterialPropertyValues2 vProps, swAllConfiguration, Empty
swModel.ActiveView.GraphicsRedraw
strNewItemName = Empty
blnFeatAdded = False
End If
End If
End Function
Private Function swPart_AddItemNotify(ByVal EntityType As Long, ByVal itemName As String) As Long
If EntityType = swNotifyFeature Then
blnFeatAdded = True
strNewItemName = itemName
End If
End Function