Bryan Woods
Forum Replies Created
-
Thank you Dan, this works really well. I took some time to pull it apart to see what you had done. It looks like I was fairly close, but the order at which I was doing things was wrong. The process however for checking whether there were keyframes present before running the loop I had no clue how to start, so thank you for throwing that in. I think I understand the process, I just needed to see it in front of me to connect the dots.
One thing I noticed is that if the layer has an inpoint that is different from its origin (like it was trimmed up to a certain point), a keyframe is still made at the beginning of the layer, regardless of its trimmed inpoint. Do you know why that is? I notice in the beginning of the process you delete the keyframes created by activating timeremap, so i’m not sure why a keyframe still gets made for a layer with a trimmed inpoint. But this is a minor issue. I just wanted your thoughts on why that might be happening.
Thank you again for your time and patience troubleshooting this with me! You’re helping me and many weary traditional 2D animator out in a big way because of this script!
-
Hi Dan, I still have not been successful including the curTime variable into “t”. I can’t figure out how I should add it in. The closest I’ve come is the code below. But this shifts all but the first keyframe ahead of the playhead, but not by any defined amount I can tell.
{{
//Set Undo Group
app.beginUndoGroup("xsheet_remap");//Define project and active items
var activeItem = app.project.activeItem;
var selectedLayer = activeItem.selectedLayers[0];
var curTime = activeItem.time;//testing variables
var numFrames = 10 //parseFloat(prompt("Number of Frames"));
var holdLength = 10 //parseFloat(prompt("Frame Hold Length"));//Meat and Potatoes
if (! selectedLayer.timeRemapEnabled) selectedLayer.timeRemapEnabled = true;
for (var f=1; f <= numFrames; f++){
var t = f*holdLength*activeItem.frameDuration+curTime;
selectedLayer.timeRemap.setValueAtTime(t,f*activeItem.frameDuration);
selectedLayer.timeRemap.setInterpolationTypeAtKey(f, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);}
selectedLayer.timeRemap.removeKey(numFrames+1);
app.endUndoGroup();}
}
-
Well, I’ve tried adding it, multiplying it, dividing it, etc. and I’m not getting the right result. Some of the keyframes are moving, but the first one stays where it is. The second on are moved a certain amount, so there’s a large gap forming between the first and second keyframes. So i’m not sure how I should be adding the curTime variable into my var for t.
-
I guess what I’m not understanding is how to utilize my variable curTime. curTime was a variable left over from trying to test timing, but I couldn’t figure out how to get it to work for me. How do I use my var curTime to start my current loop at the current playhead time? just putting “curTime;” at the beginning of the loop doesn’t do anything. The script runs, but starts from the start of the comp, not where my playhead is.
-
I can’t seem to find any documentation on how to control the current time in script. I’m assuming it may have something to do with nearestKey() + time or something, but how do I say to start where the playhead is currently? I’m not sure how to capture that result and set it as a variable. But I know it will be have to be a combination of checking for previous keyframes, and if so, add the total number of keys and add 1 to the value of the next key placed (and then add 1 from there on).
Also, would I need to embed a loop checking for keyframes inside the main loop adding initial keyframes?
-
Hey Dan, I went back and messed with it a little and finally got the result I was looking for! Below is the code I’m using. I had to change the second input to f*activeItem.frameduration to get the incremental frame number value.
Now, the big question to get this working as I need it to, how can I have this script run from where the playhead is? If I run this script once from the beginning, then run it again, from the middle of the comp, the script should add keyframes from the playhead, starting from the number of the last keyframe +1. So if I ran the script, and the last keyframe is 5, and I run the script again somewhere later in the timeline, that first keyframe made by running the script a second time should read “6”, and continue from there. Does that make sense?
Thank you for your help!
{{
//Set Undo Group
app.beginUndoGroup("xsheet_remap");//Define project and active items
var activeItem = app.project.activeItem;
var selectedLayer = activeItem.selectedLayers[0];
var curTime = activeItem.time;//testing variables
var numFrames = 10;
var holdLength = 5;//Meat and Potatoes
if (! selectedLayer.timeRemapEnabled) selectedLayer.timeRemapEnabled = true;for (var f=1; f <= numFrames; f++){
var t = f*holdLength*activeItem.frameDuration;
selectedLayer.timeRemap.setValueAtTime(t,f*activeItem.frameDuration);
selectedLayer.timeRemap.setInterpolationTypeAtKey(f+1, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);}
selectedLayer.timeRemap.removeKey(numFrames+1);
app.endUndoGroup();}
}
-
This causes the first hold keyframe at frame 1 to be “30”, the second keyframe on frame 10 to be “60”, etc.
Again, very close, but we’re still not getting what I’m looking for. Is there a way to calculate how many keyframes are currently on the time remap effect and then add 1 to the next keyframe placed? So if there’s already 4 hold keyframes, the next hold keyframe set will be the 5th, reading “0005” on the time remap effect.
This is more accurate I feel because eventually, I would like to be able to run this script from the current point my timeline indicator is, not necessarily from the beginning of a comp or layer. So if I ran this script and my timeline playhead was in the middle, this whole script would start from the middle. But it needs to be aware of keyframes that might be present before the script started laying down new ones.
-
Still not there, but we’re really close. The issue still is that each hold keyframe is taking on the numeric frame value of its point in time. So lets say the second hold keyframe in the comp has a value of “0005”, because it is at the 5th frame of the comp. But what it should be reading is “0002”. Because its the second keyframe set in the comp.
Would it be easier to run a loop that counts how many keyframes have been previously put in, and then add one to the next keyframe’s value? Kind of like using index+1 or something similar? Thats the final piece of this. Each keyframe needs to represent its own index within all the other keyframes of the time remap effect. I’m thinking multiplying the numFrames variable by the selected layer’s frame duration might not be the right answer. Or, “setValueAtTime” is overriding our initial result with the current frame number.
-
Hi Dan, this does not seem to change my result with the previous code I applied. Each hold keyframe, while spaced properly, does not reflect the proper value in the time remap effect. Each hold keyframe displays “0”. I need each keyframe to represent one frame of the image sequence. Hold keyframe 1 should read “1”, as in 1 frame on the time remap effect. Hold keyframe 2 should read “2” in time remap, etc. up to the numFrames variable originally set (which will later turn into a user defined variable with a prompt to put in a custom number). I’m not certain, but your latest code just looks like you put in a shorter version of identifying whether time remap is hidden or not and to enable it.
There’s also the issue that I have one keyframe at the very end of my layer. Its just a lone linear keyframe, and I’m not sure where that’s coming from.
-
Ok, we’re getting closer, but I still can’t get each hold keyframe to increase by one frame. the first keyframe set should be 1, the second 2, the third 3, etc. Right now, I”m getting this strange occurrance where there is a linear keyframe at the start and end of the layer, and in between I’m getting the proper number of keyframes.
Also notice where the playhead is and its reading “5”, but it should read “3”.
Here’s my code so far:
{//Set Undo Group
app.beginUndoGroup("xsheet_remap");//Define project and active items
var activeItem = app.project.activeItem;
var selectedLayer = activeItem.selectedLayers[0];
var curTime = activeItem.time;//testing variables
var numFrames = 5;
var holdLength = 5;//Meat and Potatoes
for (var f=0; f<=numFrames; f++){
if (selectedLayer.timeRemapEnabled == false){
selectedLayer.timeRemapEnabled = true;
}else{
var myKeyIdx = selectedLayer.timeRemap.addKey(f*holdLength*activeItem.frameDuration);
selectedLayer.timeRemap.setInterpolationTypeAtKey(myKeyIdx, KeyframeInterpolationType.LINEAR, KeyframeInterpolationType.HOLD);
}
}app.endUndoGroup();
}

