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

Parsing a txt file to create a rotating null object

New Here ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

Hello everyone,

I have a txt file representing rotation values (in Radians) with the following structure:

0.00,0.00,0.15,0.50,1.02 .....

And I wish to create a null object and set its rotation to these values (each value = 1 frame).

i.e: frame 1 - rotation = 0 (Rad), frame 3 - rotation = 0.15 (Rad), etc...

Can it be done? If so - can you please tell me how? If not - is there any workaround I could use so I won't have to assign the values manually for each frame?

Thanks,

Omri.

TOPICS
Scripting

Views

1.3K

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
Participant ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

Hi Omri

You could do that with an expression or with a script.

A script would parse the file and create keyframes for each frame.

An expression would read the file on every frame and get the value.

Any ideas in which direction you wanna go?

Cheers

Henrique

Henrique \\ TMMW
Clips Exporter | Text Replacer | Selector for Premiere Pro | Thumbs Up

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 ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

Since you asked so nicely I wrote one for you [repost to use radians instead of degrees]

To use the script, first select the layer whose rotation you want to set, then run the script. The script will prompt you for a filename, then set keyframes for each value in the file.

(function() { // wrap entire script in an anonymous function to create a private scope within AE's global namespace

    function loadCommaDelimitedTextFileIntoArray(textFile) {

        textFile.open("r");

        var i, line, arrayValues = [];

        while ((line = textFile.readln()) != "") {

            line = line.split(',');

            for (i=0; i<line.length; i++)

                arrayValues.push(line);

        }

        textFile.close()

        return arrayValues;

    }

    function setPropValueFromArray(prop, fps, arrayValues) {

        var frameNumber;

        for (frameNumber=0; frameNumber < arrayValues.length; frameNumber++)

            prop.setValueAtTime(currentFormatToTime(frameNumber.toString(), fps, false), arrayValues[frameNumber]);

    }

    //

    // script entry point

    //

    var i, activeComp, fps, layer, textFile;

    // get comp and layer we'll be operating on

    if ((activeComp = app.project.activeItem) == null) {

        alert("There is no active composition or the composition window is not selected");

        return;

    }

    if (activeComp.selectedLayers.length == 0) {

        alert("There is no selected layer to operate on");

        return;

    }

    layer = activeComp.selectedLayers[0];

    // get text file selection from user

    if ((textFile = File.openDialog("Select file with comma-delimited rotation values")) == null)

        return;

    // read contents of file into array

    var arrayValues = loadCommaDelimitedTextFileIntoArray(textFile);

    if (arrayValues.length == 0) {

        alert("No values were read from text file");

        return;

    }

    // convert values in array from radians to degrees

    for (i=0; i<arrayValues.length; i++)

        arrayValues = arrayValues * (180 / Math.PI);

    // set rotation keyframes from values in array

    app.beginUndoGroup("Set Rotation from Text File");

    setPropValueFromArray(

        layer.property("Transform").property("ADBE Rotate Z"),

        activeComp.frameRate,

        arrayValues

    );

    app.endUndoGroup();

})();   // end of anonymous function that encapsulates entire script

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
Advisor ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Omri - just make sure your target layer is set to 3D.

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 ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Hi Mike,

The layer doesn't have to be 3D - the Z-axis is the rotatable axis for 2D layers as well.

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
Advisor ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Horshack,

That's interesting - I'm an experienced Ae guy (instructor) - but trying to develop my scripting skills, so I was learning from and studying your code

I mocked up a datafile and ran the script - but it didn't work for me. Then I noticed that you'd used ("ADBE Rotate Z") as the matchname for the rotation, so I guessed that matchname may be specific to a 3D layer. So, I set my layer to 3D and everything worked fine.

I realise of course that standard 2D rotation is on the Z axis - but should that matchname work for 2D layers as well?

If so - it must have been my operator error...

Keep up the good and generous work, I always enjoy reading your posts and studying your code : )

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 ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Hi Mike,

That's interesting. On my system I get the opposite - the only axis that works for rotation on 2D layers for me is the Z-axis; all three axis are exposed as properties but only the Z-axis is settable. I'm seeing the same rotation match names for both 2D and 3D layers. Can you try it again on a 2D layer and report what error you're seeing? I'd like to make sure there's not something specific to my setup.

Also, can you try my property-dumping script (https://forums.adobe.com/thread/2317720) and see what match name values it reports for rotation fields on a simple null layer?

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
Advisor ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Definitely my operator error... 

I ran it again with a 2D layer and everything was fine. Sorry for any confusion caused.

This sort of thing normally happens to my wife... who sometimes calls me over for 'tech support' and then reports "it didn't do that whenpressed that button!" Ha!

Yes - your script, which is very helpful BTW, reports the same match name:

2D null layer :  [1-10] matchName: "ADBE Rotate Z", name: "Rotation"

3D null layer :    [1-10] matchName: "ADBE Rotate Z", name: "Z Rotation"

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
Advocate ,
Aug 25, 2017 Aug 25, 2017

Copy link to clipboard

Copied

Hey Mike_Abbott​, if you are ever in doubt - always check redefinery.com: rd: Gimme Prop Path  script - it's a must have script if you're scripting for AE.

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
Advisor ,
Aug 25, 2017 Aug 25, 2017

Copy link to clipboard

Copied

LATEST

Tomas - thanks for the heads up. Yes, I'm now using Gimme Prop Path - very useful : )

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