10 Replies Latest reply: Feb 12, 2014 6:39 AM by zipkiev RSS

    get data from expression to script and move layers(up/down)

    zipkiev Community Member

      guys what way better used for getting data from expression variables and put them to script variables (i only know how get all expression string, but if only need date from one or two variables?)

       

      for example

      Expression part:

      x=transform.position[0];

      y=transform.position[1];

      x=x+x;

      y=y+y;

      [x,y]

       

      script part:

      var expression_x_value="and here don't know what i must do to get X expression data"

      var expression_y_value="and here don't know what i must do to get Y expression data"

       

      alert(" x= "+expression_x_value+ " y= "+expression_y_value);

       

      also i need move layer up or down i try do this with but not work

       

      var myProj = app.project;

      var myComp = myProj.activeItem;

      var CurlayIndex=myComp.selectedLayers[0].index;

      ..........

      if(myComp instanceof CompItem)

                                      {

                                      var importOptions = new ImportOptions("some file");

                                      var importImg = myProj.importFile (importOptions);

                                      var imported_file_for_move = myComp.layers.add(importImg);

                                      }

                           alert(CurlayIndex); // check index of layer , to this layer index i want move my imported layer

                           alert(imported_file_for_move.name); //for get name

                           alert(imported_file_for_move.index); //for get  index

        imported_file_for_move.moveAfter(CurlayIndex);  // i think line this not work

       

       

      thx

       

       

       

       

       

       

       

       

       

        • 1. Re: get data from expression to script and move layers(up/down)
          David Torno Community Member

          var expression_x_value="and here don't know what i must do to get X expression data"

          var expression_y_value="and here don't know what i must do to get Y expression data"

          I don't believe you can retrieve specific expression variable data directly. The resulting output to the layer property is what is accessible. So since x and y are the resulting values you would simply grab the position property value from the layer via your script.

           

          myComp.layer(index).property("ADBE Transform Group").property("ADBE Position").value[0];     //Returns X value

          myComp.layer(index).property("ADBE Transform Group").property("ADBE Position").value[1];     //Returns Y value

          myComp.layer(index).property("ADBE Transform Group").property("ADBE Position").value[2];     //Returns Z value

           

           

           

            imported_file_for_move.moveAfter(CurlayIndex);  // i think line this not work

          The moveAfter method requires a layer obj, not an layer index number. The reason for this is when you add a new layer, the index values of each layer will change, so you need to save the layer object for it.

           

          imported_file_for_move.moveAfter(CurlayIndex);

           

          should be...

           

          imported_file_for_move.moveAfter(myComp.layer(CurlayIndex));

          • 2. Re: get data from expression to script and move layers(up/down)
            zipkiev Community Member

            Hi David, thx for your help, i successful fix  error on moving layer... but in question about getting data from x y i mean how transfer data from variables in expression to script variables, for easy understanding i choose simple example with position X Y, in fact i need help for get sampleImage() data, i want use this expression for find alpha on layer

            Something like this:

            1 loop trough all pixels

            2 find RGB pixels and store data in expression variable

            3 and hear i need somehow transfers data with RGB pixels coordinates from expression variable  to script variable

            4 receive data from expression and then calculate size of future precomp and create it

            5 render file from this precomp

            6 import it back

             

             

            PS i try do something like autocrop script, i need this for trim my PNG files

            PS2 sorry for bad English

            • 3. Re: get data from expression to script and move layers(up/down)
              Dan Ebberts Community Member

              I think I'd have the script:

               

              • add a Point Control to the layer
              • add the sampleImage expression to the Point Control
              • read the value of the point control
              • repeat as necessary (if you need to harvest values for top, bottom, left, and right, for example)
              • remove the point control

               

              Dan

              • 4. Re: get data from expression to script and move layers(up/down)
                zipkiev Community Member

                thx Dan for your help, i think its what i need... i try to do with this algorithm...

                 

                Ps don't want to create new tread for easy question .... maybe some one answer here  how used hot keys in ae script?

                 

                for example if i click 5 on keyboard script run my code. thx

                • 5. Re: get data from expression to script and move layers(up/down)
                  David Torno Community Member

                  The shortcuts document can be used to assign the first 20 scripts in your "Scripts" folder, not the "ScriptUI Panels" folder unfortunately.

                   

                  AECC on mac:

                  Adobe After Effects 12.1 Mac en_US Shortcuts.txt

                   

                  Just search for "ExecuteScript". You can assign them there. Just make sure the shortcut key you choose is not being used anywhere else in the document.

                  Screen Shot 2014-02-07 at 1.52.55 PM.png

                   

                  If you are wanting shortcut keys within your scriptUI, then you can add window event callback called "onShortcutKey" on PC. The JavaScript Tools Guide CC.pdf has info on...

                   

                  Pg. 113

                  shortcutKey     The key sequence that invokes this window’s onShortcutKey callback (in Windows only).

                   

                  Pg. 122

                  onShortcutKey     (In Windows only) Called when a shortcut-key sequence is typed that matches the shortcutKey value for this window.

                  • 6. Re: get data from expression to script and move layers(up/down)
                    zipkiev Community Member

                    Hi David, can u please write small example because i don't have " The JavaScript Tools Guide CC.pdf"(try use google, but also not find it), i have a JavaScriptToolsGuide_CS5.pdf and  find shortcutKey and onShortcutKey, but i don't understand how use it, where i must write combination of keys?(ctrl + A, shift+f2 and etc)
                    for example:
                    button7=myPanel.add("button", undefined, "key test");
                    button7.onClick=some_function; //this for example, how i click on button by mouse
                    button7.onShortcutKey(); //and here i don't understand what i must write to execute "some_function"

                     

                    Thx

                     

                     


                     


                    • 7. Re: get data from expression to script and move layers(up/down)
                      David Torno Community Member

                      i have a JavaScriptToolsGuide_CS5.pdf and  find shortcutKey and onShortcutKey

                      Same description for them as the AECC pdf. It is lacking as far as samples go.

                       

                       

                      I don't have a PC nearby to test the proper syntax, but I did find this post that may help you with it.

                      http://forums.adobe.com/thread/864279

                      • 8. Re: get data from expression to script and move layers(up/down)
                        zipkiev Community Member

                        thx David, i try your link, it work only when script palette selected(but i need working in all ae, for example if i select layer in time line and press Alt+f1 script done something), and now i don't know this is problem in my script(and example from link) or all scripts(include mac ) cant gets pressed buttons in full AE window and i must better forget about hot keys?

                         

                         

                        for now i have

                          button7=myPanel.add("button", undefined, "test");

                          button7.onClick=somecode;

                          button7.shortcutKey = 'w'; //set key w

                          button7.onShortcutKey =button7.onClick;

                         

                         

                        PS super easy thing, but on this Extended script always cant find examples for such simple tasks(for example in visual studio this can be done vary easy...), i totally don't understand "AE java script guide" examples for shortcutKey, and google also cant find interesting for me information, i see only Dan and David write examples for people..., and again thx guys

                         

                         

                         

                         

                        PS2 lazy adobe do super extended scripting guide for noobs....

                        • 9. Re: get data from expression to script and move layers(up/down)
                          David Torno Community Member

                          As far as I know script shortcut keys are only active when in that script's window. Otherwise a single shortcut key could be assigned to multiple scripts and a lot of things would fire off at once.

                          • 10. Re: get data from expression to script and move layers(up/down)
                            zipkiev Community Member

                            thx David... to bad hear that... maybe in far future ae has this feature...