Does anyone have any VBA examples that use GetAmbientLightProperties or SetAmbientLightProperties. I can’t get anything but 0 or FALSE values from GettAmbientLightProperties. I also had to initialize/dim “Colour” to Long (instead of Integer as the API help defines it) to get it to complile.
What are you expecting to get from the function? It returns true or false. Do you understand what ByRef means? You have to pass variables into the function to receive all the values.
That’s how I’m using it and when I inspect the values after calling GetAmbienLight Properties, they are all zero or FALSE. Also, calling SetAmbientLightProperties with non-zero/non-False values has no affects on the properties of the Ambient light.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim ModelDocExtension As ModelDocExtension
Dim BoolStatus As Boolean
Dim i As Integer
Dim LightSourceCount As Integer
Dim LightSourcename As String
Dim LightSourceUserName As String
Dim Name As String
Dim Ambient As Double
Dim Diffuse As Double
Dim Specular As Double
' Dim Colour As Integer
Dim Colour As Long
Dim Enabled As Boolean
Dim Fixed As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
LightSourceCount = swModel.GetLightSourceCount
Debug.Print "LightSourceCount: " & LightSourceCount
For i = 0 To LightSourceCount - 1
LightSourcename = swModel.GetLightSourceName(i)
LightSourceUserName = swModel.LightSourceUserName(i)
Debug.Print i & ": " & LightSourcename & " - " & LightSourceUserName
Next i
BoolStatus = swModel.GetAmbientLightProperties(Name, Ambient, Diffuse, Specular, Colour, Enabled, Fixed)
Debug.Print "Name: " & Name
Debug.Print "Ambient: " & Ambient
Debug.Print "Diffuse: " & Diffuse
Debug.Print "Specular: " & Specular
Debug.Print "Colour: " & Colour
Debug.Print "Enabled: " & Enabled
Debug.Print "Fixed: " & Fixed
End Sub
The Name is an input to the function. You have 7 light sources in your model. You have to specify the name of the light source you want. You will need to run GetAmbientLightProperties 7 times, each time with “Name” having the value of one of the names you retrieved using GetLightSourceName.