oorah
Mechanical
- Jul 29, 2003
- 10
I'm having trouble setting the ambient color code for Directional2 in a macro. The color code I want is 12615808 (Red 128, Grn 128, Blu 192). The macro that folows works but does not change the Directional2 ambient color. Any help?
Code:
'Clr-DyeBlack.swb - 08/13/03 by [Me]
'
'Changes the part color, ambience, and directional lighting attributes
'to anodized dye black.
'
'1. Ensure a part is open before running macro.
'2. Add Directional2 lighting if it does not already exist.
'
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim PropertyArray(9) As Double
Const swDocPART = 1
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
'Ensure a part is open
If Part Is Nothing Or (Part.GetType <> swDocPART) Then
MsgBox ("A Part must be open to run this macro."
End
End If
'Assign values for the color
PropertyArray(0) = 75 / 255 'Red
PropertyArray(1) = 75 / 255 'Green
PropertyArray(2) = 75 / 255 'Blue
'Assign values for the advanced properties
PropertyArray(3) = 10 / 10 'Ambient
PropertyArray(4) = 7.9 / 10 'Diffuse
PropertyArray(5) = 8.85 / 10 'Specularity
PropertyArray(6) = 2 / 10 'Shininess
PropertyArray(7) = 0 / 10 'Transparency
PropertyArray(8) = 2 / 10 'Emission
'Set Ambient lighting
Part.SetLightSourcePropertyValuesVB "Ambient", _
1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, 0
Part.LockLightToModel 0, False
'Set Directional1 lighting
Part.SetLightSourcePropertyValuesVB "Direction1", _
4, 0.45, 16777215, 1, -2.5, 2.5, 7.5, 0, 0, 0, 0, 0, 0, 0, 0.2, 0.69, 0, 0
Part.LockLightToModel 1, False
'Set Directional2 lighting (must exist first)
Part.SetLightSourcePropertyValuesVB "Direction2", _
4, 0.88, 12615808, 1, 1.70132, -0.270355, -0.180017, 0, 0, 0, 0, 0, 0, 0, 0.13, 0.85, 0, 0
Part.LockLightToModel 2, False
'Change the model values
varArray = PropertyArray
Part.MaterialPropertyValues = varArray
'Redraw the current graphics to display changed color
Part.GraphicsRedraw
'Clean up
Set Part = Nothing
Set swApp = Nothing
End Sub
Code:
'Clr-DyeBlack.swb - 08/13/03 by [Me]
'
'Changes the part color, ambience, and directional lighting attributes
'to anodized dye black.
'
'1. Ensure a part is open before running macro.
'2. Add Directional2 lighting if it does not already exist.
'
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim PropertyArray(9) As Double
Const swDocPART = 1
Sub main()
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
'Ensure a part is open
If Part Is Nothing Or (Part.GetType <> swDocPART) Then
MsgBox ("A Part must be open to run this macro."
End
End If
'Assign values for the color
PropertyArray(0) = 75 / 255 'Red
PropertyArray(1) = 75 / 255 'Green
PropertyArray(2) = 75 / 255 'Blue
'Assign values for the advanced properties
PropertyArray(3) = 10 / 10 'Ambient
PropertyArray(4) = 7.9 / 10 'Diffuse
PropertyArray(5) = 8.85 / 10 'Specularity
PropertyArray(6) = 2 / 10 'Shininess
PropertyArray(7) = 0 / 10 'Transparency
PropertyArray(8) = 2 / 10 'Emission
'Set Ambient lighting
Part.SetLightSourcePropertyValuesVB "Ambient", _
1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, 0
Part.LockLightToModel 0, False
'Set Directional1 lighting
Part.SetLightSourcePropertyValuesVB "Direction1", _
4, 0.45, 16777215, 1, -2.5, 2.5, 7.5, 0, 0, 0, 0, 0, 0, 0, 0.2, 0.69, 0, 0
Part.LockLightToModel 1, False
'Set Directional2 lighting (must exist first)
Part.SetLightSourcePropertyValuesVB "Direction2", _
4, 0.88, 12615808, 1, 1.70132, -0.270355, -0.180017, 0, 0, 0, 0, 0, 0, 0, 0.13, 0.85, 0, 0
Part.LockLightToModel 2, False
'Change the model values
varArray = PropertyArray
Part.MaterialPropertyValues = varArray
'Redraw the current graphics to display changed color
Part.GraphicsRedraw
'Clean up
Set Part = Nothing
Set swApp = Nothing
End Sub