1
$\begingroup$

When using this code, I've an error, I think it's about tuples being immutable, but I can't understand why. I'm looking to resize the cube just created:

# Create new cube
def create_cube(name, cornerPos, size):
    # Set cursor position for the current brick
    bpy.context.scene.cursor_location = cornerPos

    # Add a cube primitive
    bpy.ops.mesh.primitive_cube_add()

    # Get its reference via the active object, and rename
    theBrick = bpy.context.active_object
    theBrick.name = name

    # Set size        
    bpy.ops.transform.resize(value=(1.0, 1.0, 1.0))
    bpy.ops.object.transform_apply(scale=True)

    # Return the object
    return theBrick

The error message:

TypeError: 'tuple' object does not support item assignment

Any help appreciated.

$\endgroup$
1
$\begingroup$

Works fine here, maybe that's an error from a previous state in your script. It does not come from this snippet.

import bpy

def create_cube(name, cornerPos, size):
    # Set cursor position for the current brick
    bpy.context.scene.cursor_location = cornerPos

    # Add a cube primitive
    bpy.ops.mesh.primitive_cube_add()

    # Get its reference via the active object, and rename
    theBrick = bpy.context.active_object
    theBrick.name = name

    # Set size        
    bpy.ops.transform.resize(value=size)
    bpy.ops.object.transform_apply(scale=True)

    # Return the object
    return theBrick


create_cube("woop", (0,1,2), (1, 2, 1))

The error message

TypeError: 'tuple' object does not support item assignment

is something you might get if you have the following code

>>> some_tuple = (0, 1, 2)
>>> some_tuple[2] = 4  #  <-- you can't do this in tuples
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

tuples are immutable, if you want to modify an individual element's value then you use a list.

>>> some_list = [0, 1, 2]
>>> some_list[2] = 4
>>> some_list
[0, 1, 4]
$\endgroup$
  • $\begingroup$ Thanks for your time. The problem wasn't actually on this line, my mistake. I'll select your answer because this may actually help someone else with this error message. $\endgroup$ – mins Jan 3 '16 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.