×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Directional Lighting Problem

Directional Lighting Problem

Directional Lighting Problem

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources