0
$\begingroup$

I am having a "python script fail" on my project that I am working on and I do not know why. my script is programmed to turn on one lamp at a time and render an image with a different lamp turned on for each render.

import bpy, bgl, blf,sys
sceneKey = bpy.data.scenes.keys()[0]
filepath = "G:\rtitrial2"
# Loop all objects and try to find the Lamps
print ('Looping Lamps')
l=0
# first run through all of the lamps turning them off
for obj in bpy.data.objects:
    if ( obj.type =='LAMP'):
        obj.hide_render = True
        l = l + 1
print('You have hidden ' + str(l) + "lamps")

# now we can go through and
# individually turn them on
# and render out a picture
for obj in bpy.data.objects:
    if ( obj.type =='LAMP'):
        print (obj.name)
        obj.hide_render = False
        bpy.data.scenes[sceneKey].render.image_settings.file_format = 'JPEG'
        bpy.data.scenes[sceneKey].render.filepath = filepath + '//lamp_' + 
str(obj.name)
        # Render Scene and store the scene
        bpy.ops.render.render( write_still=True )
        obj.hide_render = True
$\endgroup$
4
  • $\begingroup$ Please indent your entire script with four spaces. That will format your question properly. $\endgroup$
    – dr. Sybren
    Commented Sep 15, 2017 at 21:14
  • $\begingroup$ the forward slash is what solved it. Thank you very much. $\endgroup$
    – JackG
    Commented Sep 16, 2017 at 1:49
  • $\begingroup$ I've moved my comment to an answer so you can mark this question as answered. $\endgroup$
    – dr. Sybren
    Commented Sep 16, 2017 at 10:12
  • $\begingroup$ All the lamps in the scene with list comprehension lamps = [o for o in scene.objects if o.type == 'LAMP'] can be iterated with for lamp in lamps: and has len(lamps) members. $\endgroup$
    – batFINGER
    Commented Sep 16, 2017 at 17:33

1 Answer 1

1
$\begingroup$

Instead of using bpy.data.scenes[sceneKey], just use bpy.context.scene to access the current scene. You also don't need the parentheses around conditions (it's Python, not C or Java). More important is the string assigned to filepath, though. \r means "carriage return". Just use forward slashes, Windows can handle those too.

Alternatively you can use \\r.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .