• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Combinig sampleImage and valueAtTime

Engaged ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

Hi

I have a layer which scale is using sampleImage to set it's value. So it samples the color from a different layer and sets it's scale values accordantly.

I then have a script which loops through every frame, gets the value using valueAtTime and sets it as a keyframe. Essentially baking the transformation to keyframes.

This doesn't work. If I have any other expressions it works. So it seems it is a problem with the sampleImage. It's like it doesn't have time to sample the image before it runs valueAtTime.

I tried moving the playhead to the given time before calling valueAtTime. This works a little better. But still only about half of the frames will sample the right value.

Last I tried caching all frames first. Still, no luck.

Any ideas how to solve this?

Thanks,

Jakob

TOPICS
Scripting

Views

553

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 29, 2016 Sep 29, 2016

Copy link to clipboard

Copied

Yes this is an annoying bug that came along with CC 2015 I think. A couple of things you can try:

- Add a $.sleep(1000); line in the loop where you move the playhead and read each valueAtTime to give it a chance to calculate the sampleImage value on each frame.

- Use the following command to bake the sampleImage results to keyframes before you read them. You'll have to be careful about getting the script to select that property in an open comp before this will work.

app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));

I found the second option to be quicker but you could always try both and use $.hiresTimer to test how long each method takes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

Thank you Paul. The app execute looks like it might be a solution. However, I can't figure out how to select the property with a script.

I have to loop through a lot of layers and properties, so manually selecting them is not really possible.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

I can actually do it like this:

layer.transform.position.setValueAtTime(0,[0,0,0]);

layer.transform.position.setSelectedAtKey(1, true);

$.sleep(1000); // still have to add this or the first frame will be wrong. This might be fixed if I didn't had to create a keyframe to select a property.

app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));

Just seems a little wierd to set a keyframe just to select a property.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

Off the top of my head, you'll probably need to loop through selectedProperties and selectedLayers first, setting layer/property.selected to false, then just do the same to make the chosen property selected.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

This works:

deselectAllLayers();

layer.selected = true;

layer.transform.position.selected = true;

$.sleep(500);

app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes"));

layer.transform.position.expression = "";

If I do not add this line: $.sleep(500);

It will still work except from the very first frame. All other frames will work. I would really like to find a way around using the sleep, because it's really slowing down my script. (50 layers with four properties on each layers, will add an 100 sek wait)

So any suggestions getting rid of that are very welcome. If not then thanks a lot for the help so far.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

I'm pretty sure I had that same issue where the frame at the current time failed to calculate correctly when baking expressions without the sleep so I think you're going to have to settle for that.

Please do file a bug report with Adobe about this: Feature Request/Bug Report Form

I did last year, but if more people bring it up there's a better chance they might eventually fix it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

LATEST

OK. Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines