bpy.ops.graph.select_all_toggle() / bpy.ops.transform.translate() / coordinates


i have 3 questions:

i create an animation in object mode
and want the interpolation between the keyframes as ‘constant’ so i add


but after these lines i get the following error

Operator bpy.ops.graph.select_all_toggle.poll() failed, context is incorrect

how can i prevent this ?

is there an alternative for

bpy.ops.transform.translate(value=(x, y, z))


instead of translating i would like to move the object to the ‘exact’ coordinate
is there a method for assigning immediately the new coordinates ?

how can i get the current coordinates of an object ?

thanks for your help

Question #1: I don’t know :). Maybe you should look at the python API.

Question #2: For the active object it is: bpy.context.scene.active_object.location = (x, y, z)

Question #3: For the active object it is: bpy.context.active_object.location
For a specific object it is: bpy.data.objects[‘the name of the object’].location

If you want specifically the x, y or z coordinates of an object you simply put .x or .y or .z after .location

Hope it helps!

thanks for answers 2 and 3

concerning question 1 : i can’t seem to find it :slight_smile:

I needed an answer to #1 myself. After a bit of googling and playing around I got this:

# Save old area type
old_type = bpy.context.area.type

# Switch to graph editor
bpy.context.area.type = 'GRAPH_EDITOR'

# Do some graph stuff, e.g.

# Switch back again
bpy.context.area.type = old_type