I have written up some pieces of code and put them together. I wanted to know where I am going wrong and if there are other ways I can make an object move in a circle (orbit). Here is a piece of code that I attempted to do using key frames.
EARTH = bpy.ops.mesh.primitive_ico_sphere_add(location=(10.0, 0.0, 0.0))
# first and last frame index
nfirst = bpy.context.scene.frame_start
nlast = bpy.context.scene.frame_end
for i in range(nfirst,nlast,10):
period = (2 * math.pi * math.pow(1.5 * math.pow(10, 11), 3 / 2)) / math.pow(GRAVITATIONAL_CONSTANT * MASS_OF_THE_SUN, 1 / 2)
total_frames = period * FRAMES_PER_SECOND
# Multiply by minus one so we orbit counter-clockwise
radians_per_frame = -1 * (2 * math.pi) / FRAMES_PER_SECOND
# Set frame like this
bpy.context.scene.frame_set(i)
# Set current location like this
#EARTH.set.location.x = 0
#EARTH.set.location.y = 0
#EARTH.set.location.z = 0
EARTH.keyframe_insert(data_path="location")
Thank you for your help, I hope I was more specific in my question this time!
print(EARTH)above will yield{"FINISHED"}the status set of the operator. Instead after the op useEARTH = context.object. This is how operators work, they set the context. Also usingob.keyframe_insert(datapath, frame=i)removes the need to set the frame on the scene. – batFINGER Dec 11 '19 at 02:53