Selected Object Index as a variable?

Hi all,
New to writing python scripts and hoping there’s an easy fix to this issue. The code below is meant to take all selected objects, add 2 location keyframes for a basic animation, and then offset the key frames as defined by the offset. How do I add a variable that references the index number of the selected objects, so that I can multiply this by the offset? For example if I’ve selected 50 objects, I’d like the animation of first object to be offset by 10, the second by 20, the third by 30, and so on. The current code offsets all objects by 10.

Any help would be greatly appreciated.

import bpy


objects = bpy.context.selected_objects


offset = 10


for object in objects:    
    bpy.context.scene.frame_current = 100 
    bpy.ops.anim.keyframe_insert(type='Location')
    
for object in objects:  
    object.location[0] += -100
    bpy.context.scene.frame_current = 1 
    bpy.ops.anim.keyframe_insert(type='Location')
  
for object in objects:    
    
    animData = object.animation_data
    action = animData.action
    fcurves = action.fcurves
    for curve in fcurves:
        keyframePoints = curve.keyframe_points
        for keyframe in keyframePoints:
            keyframe.co[0] += offset 
            keyframe.handle_left[0] += offset 
            keyframe.handle_right[0] += offset 


A couple of possible solutions:

  • Inside the for-loop that goes over the fcurves, just add 10 to offset after each pass
    or
  • Change the for-loop to something like “for index in range(0, len(fcurves):” Then you have an index number you can multiply ‘offset’ by but you have to manually get the ‘curve’ with curve = fcurves[index]
    or
  • Add a loop counter that you increment by 1 for each curve that you have processed and multiply ‘offset’ by that counter.

Thank you! I knew it must be a simple fix - for now I’m sticking with the first solution of adding to the offset after each pass, as I’m still learning the syntax. The only problem now is that it’s offsetting each of the location keyframes [x,y,z] separately. Is there a simple way to have the xyz keyframes offset together as an array?

Ok, I misunderstood. All you should have to do is move where you add 10 to ‘offset’ to after your loop on the fcurves instead of inside the loop on the fcurves.

That fixed it - thanks for your help!

Admin, thread solved, thanks

Evans, grown up slippers. I love my Aristocrat Scuff. Available online or at finer retailers… As the years continued on. I found my beautiful wife! She,Isabel Marant Sneakers, too,??? ?, is a prolific reader. Some of our most enjoyable afternoons were spent in bookstores. Enter SolePower. Using a basic shoe insert, SolePower allows users to charge mobile electronics simply by walking. In capturing the kinetic energy of footsteps, SolePower’s shoe insert converts energy into electrical power that is stored in a battery for later use. Abused starved and unloved. Don want an abortion don have one but I believe that a woman has rights,Louboutin Online. It is her body and should be able to decide what happens to it and her egg,??? ???. We separate by state so we can track the sun with our maintenance windows,??? 1. At 5 pm we can update for Queensland and two hours later for WA,??? ??. It also enables us to mitigate risk when rolling out upgrades.". Partial shipwrecks are where you only have half of the boat, either bow or stern. They usually appear to be rotten and ancient and makes the decoration look quite rustic. Being generally smaller in size, they are effective in small aquariums. For big occasions I go to English twin sisters Nina and Clare Hallworth. They’re stylists who take my look,timberland ?, make it better but keep it mellow. Some days, nothing makes you feel better than a big dress. A mortar sound is like a whistle. Listening for such sounds is like [being in] school. I am learning to protect myself.". Coral reefs are home to a quarter of all known fish or 8,prada ???,000 species. Corals are made up of calcium carbonate, which dissolves under acid conditions. And by the way so do shells of shellfish. Confessions and were subjected to psychological torture. International aid is arriving the Solomon Islands following the earthquake and tsunami that hit the region early Monday morning,mcm ??. The UN estimates at least 34 people were killed by the disaster in the south Pacific islands. Eating Healthy. A wellbalanced diet as well as good nutrition is not just good for shedding pounds, it also packs on more energy to the body thus causing women to have a clearer sense of thinking. This could help them in reacting in an eventempered manner when it comes to stress… I end up pulling back and becoming self protective rather than what I would like to be: open and loving. My partner is patient with my insecurities but I know that having to deal with these worries all the time begins to deteriorate even the strongest relationships,prada ??, and it’s just not the way I want to be. (more inside) [more inside]. ???: Four times 000 for a oneperson household or $27 gritty ends we seen in the past. Yessss In fastgrowing Latin America and after 15 minutes of making birds very happy