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.
Thank You
Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
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.
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
It must be the byref thingy. Guess I'll have to figure that out. Never rant into that that before.
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
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.
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
Here's a sample of code:
and the output
Code: Select all
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
Code: Select all
LightSourceCount: 7
0: Ambient - Ambient
1: Direction1 - Directional1
2: SW#2 - Point1
3: SW#3 - Directional2
4: SW#4 - Spot1
5: SW#5 - Point2
6: SW#6 - Spot2
Name:
Ambient: 0
Diffuse: 0
Specular: 0
Colour: 0
Enabled: False
Fixed: False
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
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.
Re: Doesn't work: GetAmbientLightProperties or SetAmbientLightProperties
Josh,
This helps. There is only one Ambient light and this function only works on Ambient lights. Specifying the light name did do the trick, though.
This helps. There is only one Ambient light and this function only works on Ambient lights. Specifying the light name did do the trick, though.