# How to activate the output of a dynamic paint canvas via python?

I have a bunch of objects that I have converted into a DP canvas. The thing is that I have to activate manually all the outputs for that objects. I have created a small script but it's not working:

import bpy
dynamic = bpy.context.selected_objects
bpy.ops.object.select_all(action='DESELECT')
for i in dynamic:
i.select = True
bpy.ops.dpaint.output_toggle(output='A')
i.select = False


PD: Works with on single object selected. But don´t know why it faill with a broader selection

Try this:

import bpy
dynamic = bpy.context.selected_objects[:]
bpy.ops.object.select_all(action='DESELECT')
for i in dynamic:
i.select = True
bpy.context.scene.objects.active = i
bpy.ops.dpaint.output_toggle(output='A')
i.select = False


The [:] bit at the end of line 2 creates a copy of the list instead of using a reference to the bpy.context.selected_objects, that might be affected by changes in the state of selection of the scene's objects.

The bpy.context.scene.objects.active = i makes each object active as well as selected. Many operators act on the active object only and ignore other selected objects.

• I have tried but doesn´t work – Jorge Losilla Martínez Jan 26 '16 at 10:40
• Sorry I was doing something wron. Worked perfectly – Jorge Losilla Martínez Jan 26 '16 at 10:41