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

get translate/positioning to target all animation frames?

Explorer ,
Aug 04, 2015 Aug 04, 2015

Copy link to clipboard

Copied

Hello, we are attempting to vertically center dynamic text with a script for automating large batches of web banners. Sometimes the text occupies one line, and sometimes two (and ideally we will also be able to change font sizes for some banners).

We were having success with converting text to a shape, then using coordinates and translate to aligning the layer to an underlying invisible shape layer. However, when we do this in animation frames, only the text in the first frame is correctly re-aligned if that first frame was selected when we run the script... or only the last frame is correctly aligned if we selected the last frame at run time.

Has anyone got any ideas of how to work around this and get all frames to respect the new position? We've tried putting the alignment elements in a group-which usually works across animation frames for on/off layers, but no joy. We are targeting activeLayer, but we do this on other parts of the script that replace content, change colors, etc., and those seem to work. Any help would be greatly appreciated.

The script we used to vertically align is below:

     // BUTTON
     editLayer = activeDocument.layerSets["group_btn"].artLayers["txt_btn"];

    if (editLayer.textItem && editLayer.textItem.contents != "") {
        
          newText = editLayer.textItem.contents.replace (/.+/, currentBanner.txt_btn);
          editLayer.textItem.contents = newText;
          editLayer.textItem.convertToShape();

          // position text and resize
          app.activeDocument.activeLayer = editLayer;
          activeLayer = activeDocument.activeLayer;

          var txt_btn_Width      = activeLayer.bounds[2]-activeLayer.bounds[0];
          var txt_btn_Height      = activeLayer.bounds[3]-activeLayer.bounds[1];
          var txt_btn_Bounds      = activeLayer.bounds;
          var txt_btn_X           = txt_btn_Bounds[0].value;
          var txt_btn_Y           = txt_btn_Bounds[1].value;

          // get dimensions and position of btn text position guide
          app.activeDocument.activeLayer = activeDocument.layerSets["group_btn"].artLayers["txt_btn_position_guide"];
          activeLayer = activeDocument.activeLayer;

          var txt_btn_BgWidth      = activeLayer.bounds[2]-activeLayer.bounds[0];
          var txt_btn_BgHeight      = activeLayer.bounds[3]-activeLayer.bounds[1];
          var txt_btn_BgBounds      = activeLayer.bounds;
          var txt_btn_BgX           = txt_btn_BgBounds[0].value;
          var txt_btn_BgY           = txt_btn_BgBounds[1].value;

          // make text active layer and position it
          app.activeDocument.activeLayer = activeDocument.layerSets["group_btn"].artLayers["txt_btn"];
          activeLayer = activeDocument.activeLayer;

          var newTextX = (txt_btn_BgWidth / 2) - (txt_btn_Width / 2);
          var newTextY = (txt_btn_BgY + (txt_btn_BgHeight / 2)) - (txt_btn_Height / 2);

          var deltaX = newTextX - txt_btn_X;
          var deltaY = newTextY - txt_btn_Y;          

          activeLayer.translate (deltaX, deltaY); 
     }
TOPICS
Actions and scripting

Views

305

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
Adobe
Enthusiast ,
Aug 04, 2015 Aug 04, 2015

Copy link to clipboard

Copied

"Right" answer should be to have layers in group and translate the group. What happens when you did that?

Alternative is to just loop through all layers and translate them one by one. I suggest you don't change active layer (translate does not require it) as that slows it down.

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
Explorer ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

Matias,

We previously had all the elements being translated and aligned in a single group and that did not work, but you make a good point, and we may try nesting elements in groups for the next iteration... So the text layer is in a group by itself and the alignment shape is in a group of its own, and have translate work on the groups. For now we are working around this by using differently positioned text boxes for content on two lines, and where that's not going to solve everything (like where sizes of text are likely to change), we were using a snippet of code copied from script listener action recording while selecting the target frame, selecting and converting text layer to a shape, shift-selecting the alignment shape, and clicking the vertical align button in the application window. This is also not ideal for all situations, because we are selecting a frame... and we may run across trials where the text needing to be centered is bugging out in more than one frame. I'll post any further findings here, but for now thanks so much for your solve!

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
Explorer ,
Aug 13, 2015 Aug 13, 2015

Copy link to clipboard

Copied

LATEST

Update: Passing on a couple of tips that might help troubleshoot animated frames and dynamic content. We found it was problematic to have ANY layer selected when importing the script, (seems to override "app.activeDocument.activeLayer" instructions, causing random errors and unexpected results).

Also, using activeLayer in the script seems to affect the ability to target objects across multiple frames. If you aren't able to transform (outline, position, etc.) text or shapes in a specific frame, try explicitly targeting that frame just before your line of code that transforms objects.

Example: We had placeholder text in a group that was hidden for all frames except frame number 3. With a script, we replaced the text, outlined the layer and centered the new shape (outlined text) over a zero-opacity background shape. The text shape was correctly vertically centering in frame 1 (or whichever FRAME was selected at the time we ran the script) but not in frame 3 where it was visible. The script involved centering several things on several frames, so selecting one correct frame before running the script wasn't getting all things positioned right. As you might have read above, you should deselect all layers before running any script to avoid bugs. But it is impossible to deselect all frames. One frame is always selected. You can select all frames (the thumbnails in the timeline all get highlighted thick light gray borders), but only one frame is truly "selected"... the timeline thumbnail that is outlined with a thin contrasting white line.

Ended up recording the singular action of selecting a FRAME...using scriptingListenerJS, and copying that action script into the existing javascript anywhere a frame needed to be targeted (just before each line of code that would change text, position it, etc. for a specific frame). You can then see the number of the frame you selected at the time you recorded the script... and change that in every instance to the frame you wish to target for any transformation.

I ended up with a lot of copied code from different sources, but it appears the frame number recorded by scriptingListenerJS was zero-index for some things (like deleting a frame), and 1-index at other things (like targeting the frame for transformations). If that's just javascript functions vs. actionscript, I am sorry for the red herring. I am a scripting newbie.

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