Windows XP and SW 2011 SP 4.0
Hi There,
I am trying to alter the colour of a feature (Boss-Extrude) to a light brown colour using a VBA macro. However when the macro runs the feature that has been selected turns black.
Now, when I go into the appearance properties the colour shows as light brown but in the graphics window it is black.
Also if I close the part and assembly and re-open them the colour has changed to the light brown.
I don’t want to have to close and re-open the documents.
Any suggestions?
Thanks
Dec
Here is the code:
' Make sure a feature is selected in the feature tree
' Boss-Extrude, Sweep etc
Sub ChangeFeatureColour()
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.ModelDoc2
Dim swCompModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim swFeat As SldWorks.Feature
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim vMatProp As Variant
Dim vConfigNames As Variant
Dim bRet As Boolean
On Error GoTo ErrH:
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
Set swSelMgr = swModelDoc.SelectionManager
Set swModelDocExt = swModelDoc.Extension
Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)
Set swFeat = swSelMgr.GetSelectedObject(1)
' Exit if user has not selected a feature
If swFeat Is Nothing Then
MsgBox "select feature"
Exit Sub
End If
Debug.Print swFeat.Name
' Get property values e.g Colour, Transparency etc
vMatProp = swFeat.GetMaterialPropertyValues2(1, 1)
Debug.Print " RGB = [" & vMatProp(0) * 255# & ", " & vMatProp(1) * 255# & ", " & vMatProp(2) * 255# & ", " & vMatProp(7) & "]"
vConfigNames = swModelDoc.GetConfigurationNames
' Force component color to brown
vMatProp(0) = 232# / 255
Debug.Print vMatProp(0)
vMatProp(1) = 113# / 255
Debug.Print vMatProp(1)
vMatProp(2) = 8# / 255
Debug.Print vMatProp(2)
Debug.Print " RGB = [" & vMatProp(0) * 255# & ", " & vMatProp(1) * 255# & ", " & vMatProp(2) * 255# & "]"
bRet = swFeat.SetMaterialPropertyValues(vMatProp)
swModelDoc.ClearSelection2 True
swModelDocExt.UpdateRenderMaterialsInSceneGraph True
swModelDoc.WindowRedraw
Set swFeat = Nothing
Set swComp = Nothing
Set swSelMgr = Nothing
Set swModel = Nothing
Set swApp = Nothing
ErrH:
If Err.Number = 13 Then
MsgBox "Select feature in the Feature Tree and not in the model"
Exit Sub
End If
End Sub
BEFORE
SHOWING BROWN IN APPEARANCE WINDOW
I HAVE CLOSED THE PART AND ASSEMBLY DOWN. RE-OPENED THEM AND THE FEATURE IS NOW BROWN