Switch scenes by Macro

Is there any Macro Code to switch between scenes or switch back to dedicated scene? I would like to unify a lot of files with a kind of a Presave- Macro. A lot of users modify scene settings accidently, and we want to keep the Previews at save in a unified shape.

SolidworksApi/macros
Answers 4
DS
DS 2021-04-09 Best Answer

Ricco,

I use the following to force the scene to "plain white".  You just need to know what scene image you want to use and where it is stored.

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.InsertScene("\scenes\01 basic scenes\11 white kitchen.p2s")
boolstatus = Part.EditRebuild3
Part.Save


End Sub

RB
RB 2021-04-09

Thanks, I could fix it . Macro switches now to ambient light: white in Part or Assy:

boolstatus = Part.SetLightSourcePropertyValuesVB("Ambient", 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, False)
boolstatus = Part.LockLightToModel(0, False)

boolstatus = Part.SetLightSourcePropertyValuesVB("Ambient-1", 1, 0, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, False)
boolstatus = Part.LockLightToModel(0, False)

DS
DS 2021-04-09

I'm honestly not sure.  I tried adding your lines above boolstatus = Part.EditRebuild3, but it didn't seem to do anything.

When in doubt, I usually google it.

RB
RB 2021-04-09

Thanks, it works for me, but one problem still is existing. I would further set the ambient light color back to white by the macro. I have the code to reset the ambient light to its values, but the color itself doesn't reset, so I guess that I might need a further command for that. Here-Whith these I reset the ambient light as I need it:

boolstatus = Part.SetLightSourcePropertyValuesVB("Ambient", 1, 1, 16777215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.29, 0, 0, False)
boolstatus = Part.LockLightToModel(0, False)

But I am not sure where to place color informations, within the command or if there is another code for it. Some Ideas what command would fix that?