4 Replies Latest reply on Sep 16, 2016 10:13 AM by Chris Angevine

    Increasing Ambient Light Value

    Chris Angevine

      Where I work, the projectors in conference rooms don't show our SolidWorks assemblies very well.  The brightness just isn't there.  If I turn it up on the projector for SolidWorks, all of the other applications are washed out.  One of the people here wrote a macro that will increase the ambient light in the assembly just for when we are in a conference room.  It works great.  The only problem is that when you change the assembly configuration, the ambient light goes back to it's original setting.  The SetLightSourcePropertyValuesVB command doesn't seem to have an option for configurations.  Although if you do it manually, there is.  The macro is below.

       

      Any ideas on what else I can do?

       

      Thanks, Chris

       

      Dim swApp As Object

      Dim swModel As ModelDoc2
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long

      Sub main()

      Set swApp = _
      Application.SldWorks

      Set swModel = swApp.ActiveDoc
      Dim LightProps As Variant
      Dim AmLightNum As Integer
      Dim AmValue As Double
      Dim Name As String
      Dim i As Integer
      Dim pos As Integer
      If Not swModel Is Nothing Then
          AmLightNum = swModel.GetLightSourceCount
          For i = 0 To AmLightNum - 1
              LightProps = swModel.LightSourcePropertyValues(i)
              Name = swModel.GetLightSourceName(i)
              pos = InStr(Name, "Ambient")
              If pos > 0 Then
                  AmValue = LightProps(15)
                  If AmValue < 0.3 Then boolstatus = swModel.SetLightSourcePropertyValuesVB(Name, 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.75, 0, 0, False)
                  If AmValue > 0.29 Then boolstatus = swModel.SetLightSourcePropertyValuesVB(Name, 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, False)
              End If
          Next i
      End If

      swModel.ForceRebuild3 (True)

      End Sub

        • Re: Increasing Ambient Light Value
          Deepak Gupta

          You can loop thru each configuration and set the lights

            • Re: Increasing Ambient Light Value
              Chris Angevine

              Thanks Deepak.  With some of my assemblies, that could take 5-10 minutes to cycle through them all.  Especially machine and system layouts.  I was hoping to find a command that works on all the configurations incase I want to view just 3 or 4 of them.

              If not, I will take your advice and make a small dialog box where I can pick the configurations I want.  Thanks.

            • Re: Increasing Ambient Light Value
              Keith Rice
              Sub main()
                  Dim swApp As SldWorks.SldWorks
                  Dim swModel As SldWorks.ModelDoc2
                  Dim vConfigNames As Variant
                  Dim strOrigConfigName As String
                  Dim i As Integer
                  
                  Set swApp = Application.SldWorks
                  Set swModel = swApp.ActiveDoc
                  
                  If swModel Is Nothing Then Exit Sub
                  
                  strOrigConfigName = swModel.ConfigurationManager.ActiveConfiguration.Name
                  vConfigNames = swModel.GetConfigurationNames
                  For i = 0 To UBound(vConfigNames)
                      swModel.ShowConfiguration2 vConfigNames(i)
                      ChangeLightSourceProps swModel
                  Next i
                  
                  swModel.ShowConfiguration2 strOrigConfigName
              End Sub
              
              Private Sub ChangeLightSourceProps(swModel As SldWorks.ModelDoc2)
                  Dim i As Integer
                  Dim dblAmbientVal As Double
                  
                  For i = 0 To swModel.GetLightSourceCount - 1
                      If InStr(swModel.GetLightSourceName(i), "Ambient") > 0 Then
                          dblAmbientVal = swModel.LightSourcePropertyValues(i)(15)
                          If dblAmbientVal < 0.3 Then boolstatus = swModel.SetLightSourcePropertyValuesVB(swModel.GetLightSourceName(i), 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.75, 0, 0, False)
                          If dblAmbientVal > 0.29 Then boolstatus = swModel.SetLightSourcePropertyValuesVB(swModel.GetLightSourceName(i), 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, False)
                      End If
                  Next i
              End Sub
              

               

              Keith

              SolidWorks API Training and Services