1
$\begingroup$

i have a tiny problem to set a keyframe by active object only in python console.

my problem is now i have in "Object Mode" any objects select, and i try to set a keyframe by a active object (Cube) only.

my attempts have become all selected objects a keyframe :(

it's doable to do this in python ?

my Objects i apologize for my english skills :/

best regards -DevilSam

$\endgroup$
  • $\begingroup$ Please edit your question and try to explain what you mean in more detail. You can avoid mistakes that are universal in most languages like capitalizing the first word of your sentences, I am sure the community here at Blender Stack Exchange will help you with the rest, so don't worry about it, but further clarification is needed. What are you trying to do? What kind of key frames are you trying to set and how? I assume you are trying to animate only the active object, is that correct? Why do you need other objects to be selected at the same time? $\endgroup$ – Martynas Žiemys Dec 22 '18 at 1:21
2
$\begingroup$

Use the API method rather than an operator.

Making the assumption that if all selected objects are being keyframed, you are using an operator to set keyframes.

Much easier to use keyframe_insert(data_path, index=-1, frame=bpy.context.scene.frame)

Index default is -1 for all components (eg x, y and z of a location) or 0, 1, 2, 3, (location.x ==> location[0])

The method returns True if the keyframe has been successfully added.

An example of adding all location keyframe to the active object. Set the location, then insert the keyframe(s).

import bpy
ob = bpy.context.object
ob.location = (1, 2, 4)
# add this as keyframe at frame 10
ob.keyframe_insert("location", frame=10)

Take z up to 19 at frame 100

ob.location.z = 19
ob.keyframe_insert('location', index=2, frame=100)
$\endgroup$
  • $\begingroup$ Thanks "batFINGER" for nice answer <3 $\endgroup$ – DevilSam Dec 22 '18 at 11:22

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