atn2js ActionFile to Javascript translator

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

I though I posted this earlier.
Here's the translator I've been promising. It generates self-contained scripts from Action files. Each Action becomes a function.

This thing needs more testing, but I'd like to get some early feed back, if possible.
Guest

atn2js ActionFile to Javascript translator

Post by Guest »

OK I am lost...where is the translator?
xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

Editted to fix typos in code block.

At the bottom of the file you'll see a 'main' function. It's what I've been using for testing. To make it a bit clearer (or clear at all) here is an edited/commented version of main:

Code: Select allfunction main() {
  // I have all files hardwired. Adding 'File.openDialog' is left as an exercise...
 
  // specify an input file. I've been using Image Effects from Presets
  var infile  = new File("/c/work/Image Effects.atn");


  // Create a new ActionFile object and read in the .atn file
  // Note: this does not load the .atn file into the ActionsPalette
  var actFile = new ActionFile();
  actFile.read(infile);

  // Test 1: Translate the entire action file to JS
  if (true) {
    var jw  = new JSWriter();
    jw.writeScript(actFile, new File("/c/work/Image Effects.jsx"));
  }

  // Test 2: Translate a single action from the .atn file
  if (false) {
    var actionName = "Blizzard";
    var action = actFile.actionSet.getByName(actionName);
    var jw  = new JSWriter();
    jw.writeScript(action, new File("/c/work/" + actionName + ".js"));
  }

  // Test 3: Translate a manually constructed ActionDescriptor to code
  if (false) {
    var jw = new JSWriter();
   
    var desc = new ActionDescriptor();
    desc.putPath( cTID("null"), new File( "C:/work/Template02.psd" ) );
    desc.putBoolean( cTID("T   "), true );
    jw.writeScript(desc, new File("/c/work/jstest.js"));
  }
};


I'll probably throw a UI on it for the next beta release of XToolkit.

I've attached the slightly tweaked output of translating Image Effects.atn. One of the known bugs is I need to convert action names to something that will work as function names.
Andrew

atn2js ActionFile to Javascript translator

Post by Andrew »

Hi X

All these new scripts are great. I will definitely be looking at them closely and working with them, but first I need to finish my own current batching projects for PS and Bridge. I know it can be frustrating to put something out and get no feedback.

Andrew
xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

Andrew wrote:I know it can be frustrating to put something out and get no feedback.

I'm not that worried about it. All of this code I've been writing and releasing this past couple of weeks is based on work I've been doing for several months. I'm glad that I've finally been able to get it out.

I'll still have a few more days of clean, docs, and a bit of coding (conditional Action step extension, for instance) before I release this into a broader beta.
Then, probably another 4 weeks of beta testing and comments before I drop a final version.

Then I can start digging into your scripts and spend a bit more time on my Strat .
Guest

atn2js ActionFile to Javascript translator

Post by Guest »

Well I have posted over in the PS Scripting Forum.
I have not been able to run the script. Yes I loaded the PS action set mentioned by Xbytor but I am running still CS and not CS2.
There is a line with an .jsx this indicates that the script is for CS2. Does it?
On the other hand do I have to premade the folders or the script is making them?

I look at this translater like a good learning tool for scipting. I have no problems writing actions . Scripting is another matter and at age 72 it can be a little daunting.
I know of Script Razor from George Schmid but have not looked into it.
All my friends are computer iliterate so it is very hard to learn. The only way is the forums or perhaps user grup meetings.
Thanks for your time.
xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

I posted this over in adobeforums, but I'll repost it here so that we can keep the thread of discussion over here.

Just change the path to one of your action files and see if that works. The jsx
extension works in both CS and CS2. I don't know of anything CS2 specific in any
of the code. I'll test it out later today with CS and see if there's a problem I
missed.
garek007

atn2js ActionFile to Javascript translator

Post by garek007 »

X,

I tried running it on winxp with cs2 and I got the following error:

Error 22: ActionFile does not have a constructor Line: 10
-> var actFile = new ActionFile();

I could be using it wrong. I copied what you had in Function Main()

I added Main(); to the end of it so it would run and put an action in c/work

My action was called Plan Coloring.atn.

so I replaced the path in your line
var infile = new File("/c/work/Image Effects.atn");
with my path /c/work/Plan Coloring.atn
xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

Judging from the error message and line number, you copied my 'main' function to a new file, modified it with your path info, and tried to run it.

You kinda need the other 9000 lines for the translator to work.

To keep this simple, try doing the following:
1) Comment out the call to main at the end of atn2js. It's at the very bottom of the file. Change it so it looks like this:

Code: Select all// main();

"atn2js.jsx";

// EOF


2) In your new file with your version of main, add something like this to the very top of the file:
Code: Select all//@include "atn2js.jsx"

This will force the JS interpreter to read atn2js at this point. This avoids having to copy that 9000 line chunk of code into your script. You may need to provide a fully qualified path to atn2js.

My next release (this weekend sometime) will have a file selector so going through this process won't be necessary.

Let me know how it goes.
xbytor

atn2js ActionFile to Javascript translator

Post by xbytor »

There are problems with atn2js on CS. The purely syntactic ones I've addressed and will be out with the next rev.

When I do get it to run, it doesn't appear to stop. I'll have to dive into this over the weekend with the debugger when I've got a good block of time to work on it.