How do I turn on Ray Shadow via Python script

I am trying to turn on ray shadow for a bunch of lights in my sceen with a python script.

I tried to use the class variable .Modes(‘Shadows’)

This, however, didn’t do it.

I have gotten the other modes to work such as .Modes(‘OnlyShadows’)

I am using the lastest blender_python api as a reference.

How do I turn on Ray Shadow, using python script, for my lights or is there another way to mass edit my lights???

Change one lamps settings. Select the other lamps and select last the one that you made changes to.

Then press Ctrl+L. Choose Lamp data.

It also works with materials.

When I tried this, all of my lights assumed the properties of the one I changed. This includes energy and light color.

I need to have all of my lights be switched to “Ray Shadow” on, but keep their individual color and energy.

Is there a way to do this within a Python script, other than using .Modes(“Shadows”) as this doesn’t enable “Ray Shadow”???

Is there a way to mass edit only one feature of a light within blender???

Looks to me it is time for a bug report: https://projects.blender.org/

If I try this code after selecting one of the lamps created by your script:

import Blender
lamp = Blender.Object.GetSelected()[0].getData()

print lamp.getModes()
print lamp.Modes

For the first result, 0 is returned if ray shadow is off and 8192 if ray shadow is on. Even 1 can be returned right after creating the lamp (a lamp lamp can’t have buffer shadows).

Lamp.Modes prints:

{‘Shadows’: 1, ‘Layer’: 4, ‘Square’: 128, ‘OnlyShadow’: 32, ‘NoSpecular’: 4096, ‘Negative’: 16, ‘Sphere’: 64, ‘Quad’: 8, ‘NoDiffuse’: 2048, ‘Halo’: 2}

Which means there is no entry in the modes for ray shadow! “NoSpecular” is not in the docs!

added rayshadow and nodiffuse to the bpydocs. will be there for 2.4

Thanks for all of the help. I guess I will just have to be patient for now.

For the first result, 0 is returned if ray shadow is off and 8192 if ray shadow is on.

Is there a way to use setData to set the value 8192 and turn ray shadow on?

I have tried this with no luck.

Its best just to use binary operators.

la.mode |= Lamp.Modes[‘RayShadow’] # Enables Ray Shadow
la.mode &= ~Lamp.Modes[‘RayShadow’] # Disables Ray Shadow.

This of course works for all other mode settings also.

  • Cam

Lamp.Modes prints:

{‘Shadows’: 1, ‘Layer’: 4, ‘Square’: 128, ‘OnlyShadow’: 32, ‘NoSpecular’: 4096, ‘Negative’: 16, ‘Sphere’: 64, ‘Quad’: 8, ‘NoDiffuse’: 2048, ‘Halo’: 2}

From the above, there is no Mode “RayShadow”.

I did find a workaround though


l.mode |= ~Lamp.Modes['OnlyShadow']      # Enables all except Only Shadow

l.mode &= ~Lamp.Modes['Shadows']         #Disables Shadows
l.mode &= ~Lamp.Modes['Quad']            #Disables Quad
l.mode &= ~Lamp.Modes['Sphere']          #Disables Sphere
l.mode &= ~Lamp.Modes['Layer']           #Disables Layer
l.mode &= ~Lamp.Modes['Negative']        #Disables Negative
l.mode &= ~Lamp.Modes['NoDiffuse']       #Disables No Diffuse
l.mode &= ~Lamp.Modes['NoSpecular']      #Disables No Specular
l.mode &= ~Lamp.Modes['Halo']            #Disables Halo

The first line Enables everything except “OnlyShadow”

The other lines disable everything except for “RayShadow”

My work around only works for the blender internal renderer :frowning: . If Yafray GI is used, both Ray Shadow and Buf. Shadow are on at the same time.

So back to my original question

Is there a way to enable “RayShadow” without using modes?

I am very close to finishing this script and could use just a little more help.

Please be patient with me as this is my first python script. Also, I am new to programming.

Is there someone out there who could please answer my last question?

Last reply from me to this post.

I guess everything I had been asking in my last few questions is a mute point now. I just installed blender 2.4 and “RayShadow” is included in the lamp modes.

Added a lamp mode modifying example to BPY docs, heres the cvs build.
http://members.iinet.net.au/~cpbarton/ideasman/BPY_API/index.html