can someone script this please?

Hi there, I need to change the X,Y and Z image mapping properties of about 200 objects to “2”. I have heard thats scripts can make changing multiple objects properties a lot easier so can someone advise how to do this? I’d love either a ready made script or a good tutorial on scripts that doesnt waffle on too muchy!

Straightforward enough. Change values once, copy those lines from the info editor, put them in a loop, change them to affect the loop object, select objects (in this case), run.


import bpy

offset = 2

for obj in bpy.context.selected_objects:
    # bpy.context.object.active_material.texture_slots[0].offset[0] = 2
    
    obj.active_material.texture_slots[0].offset[0] = offset
    obj.active_material.texture_slots[0].offset[1] = offset
    obj.active_material.texture_slots[0].offset[2] = offset

How do you select text from the info section? The mouse isnt doing a thing?

Also, how would one perhaps add in a conditional IF statement, like “If obj.active_material.name<>“Spandex” then …” So the script is only executed if the objects material is not known named “spandex”.

Right mouse button selects, ctrl+C to copy.

Almost right. The operator is != or a word “not”, needs colon at the end, and indentation after that

if obj.active_material.name != "spandex":
    do stuff

Ahh right iv got that, I’m using:

import bpy

for obj in bpy.context.selected_objects:
# bpy.context.object.active_material.texture_slots[0].offset[0] = 2

bpy.context.object.active_material.texture_slots[0].scale[0] = 2
bpy.context.object.active_material.texture_slots[0].scale[1] = 2
bpy.context.object.active_material.texture_slots[0].scale[2] = 2</b>

but it’s not working, its just applying the attributes to the LAST selected object, not all the other selected objects. How would i make it apply the change to ALL objects in the scene (so in future i dount have to “unhide” tons of objects in the viewport).

I don’t have any trouble reading so you don’t have to write words in uppercase.

Those are copied straight from the info window which affects one (active) object and not the objects that the loop goes through.

You can check all objects like this. Would still be good idea to put in some limiting factor, like type, name, or exclude camera and lights.

for obj in bpy.context.scene.objects:
    if(obj.type == 'MESH'):
        print(obj.name)

@crazycrincle: You’re missing last step to get it going: set selected obj active as a first thing inside FOR loop

bpy.context.scene.objects.active = obj

As soon as you do this, all will get changes you want.
One more: since FOR operates on obj you need to write:


import bpy
for obj in bpy.context.selected_objects:
    bpy.context.scene.objects.active = obj   
    obj.active_material.texture_slots[0].scale[0] = 2
    obj.active_material.texture_slots[0].scale[1] = 2
    obj.active_material.texture_slots[0].scale[2] = 2