This will delete all direction lights from a part:
Sub main() Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc Do While swModel.GetLightSourceCount > 1 swModel.DeleteLightSource 1 Loop End Sub
The light source index starts at 1. The Ambient light, which is undeletable, is index 0. Whenever you delete a directional light, any remaining directional lights drop down in the index, so you can't crawl forward with a For loop and instead must use a Do Loop like above.
If, for some reason, a directional light can't be deleted, then this code will result in an infinite loop. For safety reasons you might include a counter that eventually triggers leaving the loop if the counter hits a certain value.