0 Replies Latest reply on Oct 15, 2014 4:07 AM by Florent Jamet

    Macro VBA for light and camera creation

    Florent Jamet

      Hello,

       

      I need help to create a VBA macro in order to delete all lights of a model and create 3 spot lights.

       

      My test macro is the following,but I have a problem with part.getlightsourcecount I think.

       

      Other problem,how can I define the angle of my spot lights in "part.SetLightSourcePropertyValues ?

       

      ------------------------------------------

      Dim swApp As Object

       

       

      Dim Part As Object

      Dim instance As IModelDoc2

      Dim ID As Integer

      Dim boolstatus As Boolean

      Dim longstatus As Long, longwarnings As Long

       

      Sub main()

       

      Set swApp = _

      Application.SldWorks

       

      Set Part = swApp.ActiveDoc

       

      boolstatus = Part.DeleteLightSource(Part.GetLightSourceCount)

      Part.GraphicsRedraw

       

      boolstatus = Part.SetLightSourcePropertyValuesVB("Ambiante-1", 1, 0, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.3, 0, 0, False)

      boolstatus = Part.LockLightToModel(0, True)

       

       

      Part.GraphicsRedraw

       

       

      boolstatus = Part.AddLightSource("SW#1", 4, "Directionnelle1")

      boolstatus = Part.SetLightSourcePropertyValuesVB("SW#1", 4, 0.3, 16777215, 1, 8.99966801013709, 12.7274525567912, 8.99966801013706, 0, 0, 0, 0, 0, 0, 0, 0.3, 0.3, 0, False)

      boolstatus = Part.LockLightToModel(1, True)

       

       

      Part.GraphicsRedraw

       

       

      boolstatus = Part.AddLightSource("SW#2", 4, "Directionnelle2")

      boolstatus = Part.SetLightSourcePropertyValuesVB("SW#2", 4, 0.3, 16777215, 1, -8.99966801013709, 12.7274525567912, 8.99966801013706, 0, 0, 0, 0, 0, 0, 0, 0.3, 0.3, 0, False)

      boolstatus = Part.LockLightToModel(2, True)

       

       

      Part.GraphicsRedraw

       

       

      boolstatus = Part.AddLightSource("SW#3", 4, "Directionnelle3")

      boolstatus = Part.SetLightSourcePropertyValuesVB("SW#3", 4, 0.3, 16777215, 1, 0, -12.7274525567912, -12.7274525567911, 0, 0, 0, 0, 0, 0, 0, 0.3, 0.3, 0, False)

      boolstatus = Part.LockLightToModel(3, True)

       

      Part.GraphicsRedraw

       

      End Sub

       

      -------------------------------------------------------

       

      I am a beginner in programmation and I'm waiting for answers

       

      Thank you in advance