Action to Javascript - problem with text

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

kcp

Action to Javascript - problem with text

Post by kcp »

Thank you xbytor for the excellent scripts in xtools! They are awesome!

I have a whole bunch of actions I'm trying to convert to scripts. They each go through a series of actions.... and at the end a text layer is added.

Scripts converted with your ActiontoJavascript work great up to the point where text is added.

Another problem (at first) was - everywhere the script coded a \r it had a carriage return in the actual script --- which caused an error. I figured that one out on my own but I have not been able to figure out what the problem is when it gets to the text...

Can anyone help?

The last line of the code section below is where photoshop cs2 says is the error...

Code: Select all// Make
  function step132(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(PSClass.Layer);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(PSKey.Name, "TEXT");
    desc2.putEnumerated(PSKey.Color, PSKey.Color, PSKey.Blue);
    desc1.putObject(PSKey.Using, PSClass.Layer, desc2);
    executeAction(PSEvent.Make, desc1, dialogMode);
  };
xbytor

Action to Javascript - problem with text

Post by xbytor »

kcp wrote:Scripts converted with your ActiontoJavascript work great up to the point where text is added.
Can anyone help?

The last line of the code section below is where photoshop cs2 says is the error...


The code looks fine.

Another problem (at first) was - everywhere the script coded a \r it had a carriage return in the actual script --- which caused an error. I figured that one out on my own but I have not been able to figure out what the problem is when it gets to the text...


Can you put together an action or two that has both of these problems? It will speed things up a bit since I haven't see either of the problems.

-X
kcp

Action to Javascript - problem with text

Post by kcp »

thanks for the reply....

OK - while trying to make you demo files --- had a new problem ---

I start ActionToJavascript.jsx, select the action file I want to convert, and it generates a script for some other action file that is loaded.

I deleted the atn file it was converting and tried again. It then converted another one, another seemingly random choice from the actions currently loaded in my PS CS2 action bin...

I then emptied all actions from the bin and loaded up the test action I made for you - when it is the only one in there, it now converts the proper file.

The converted code brings up the errors I mentioned originally. I can fix the lines that have a carriage return after the \r and then it gets to the text layer and I don't know what is wrong there.

I am going to email you my files so you can test yourself.

Thanks very very much!!!
xbytor

Action to Javascript - problem with text

Post by xbytor »

Sorry about the delay. I couldn't reproduce the problem with my local copy of the script. You action translates and the new script runs fine.

I've refreshed the CVS tree on sourceforge and attached the latest rev of the script.

-X
kcp

Action to Javascript - problem with text

Post by kcp »

YES! Everything seems to be working fine for me now too... maybe I just had an older version of your script? But the new one seems to work perfectly.

Well... not everything works perfect... There is still the issue of ---
if I have multiple actions sets loaded, it seems to pick one at random to code. I select one, it converts a different one.

But if I empty the bin of all but the one I want to convert to jsx, it works fine.

I can work around that.... so it's not a problem really. Just reporting!

I want to thank you again for sharing your talent, skills and scripts! This helps me do things with automation that I never dreamed of being able to do before. THANK YOU!
xbytor

Action to Javascript - problem with text

Post by xbytor »

kcp wrote:Well... not everything works perfect... There is still the issue of ---
if I have multiple actions sets loaded, it seems to pick one at random to code. I select one, it converts a different one.

I haven't seen this happen, but I will take another look.


But if I empty the bin of all but the one I want to convert to jsx, it works fine.

A better and easier work-around is to save the action set to an action file (manually) and then use ActionFileToJavascript to generate the code from the atn file. It's the route I frequently take.

-X
kcp

Action to Javascript - problem with text

Post by kcp »

I tried running an atn file through ActionFileToJavascript... but am having lots of troubles with the converted scripts ---

ActionToJavascript is making me very happy though....!

.....I am having a new problem. I made a new script from a rather long action. All the actions/scripts I am making start out with the first step of creating a new blank document. The latest script gives me the following error message:



The odd thing (to me) is that that first block of code works absolutely perfectly in the previous scripts I have made with ActionToJavascript. Other than the name of the document, the code looks identical.

Why would it work in one and not the other? These are the first 27 lines of code from the each javascript. One works, one doesn't.

Could it be something afterwards?

Here is the code that won't work:
Code: Select all//
// Generated Wed Apr 30 2008 21:27:58 GMT-0500
//

//
//==================== START! ==============
//
function START() {
  // Make
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var desc2 = new ActionDescriptor();
    desc2.putString(PSKey.Name, "0408.mirror.001");
    desc2.putClass(PSKey.Mode, PSClass.RGBColorMode);
    desc2.putUnitDouble(PSKey.Width, PSUnit.Distance, 864);
    desc2.putUnitDouble(PSKey.Height, PSUnit.Distance, 864);
    desc2.putUnitDouble(PSKey.Resolution, PSUnit.Density, 300);
    desc2.putDouble(PSString.PixelScaleFactor, 1);
    desc2.putEnumerated(PSKey.Fill, PSKey.Fill, PSEnum.Transparent);
    desc2.putInteger(PSKey.Depth, 8);
    desc2.putString(PSString.profile, "sRGB IEC61966-2.1");
    desc1.putObject(PSKey.New, PSClass.Document, desc2);
    executeAction(PSEvent.Make, desc1, dialogMode);
  };


And here is the same block of code from another script that DOES work:
Code: Select all//
// Generated Tue Apr 29 2008 18:25:13 GMT-0500
//

//
//==================== START ==============
//
function START() {
  // Make
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var desc2 = new ActionDescriptor();
    desc2.putString(PSKey.Name, "0408_sixpic.001");
    desc2.putClass(PSKey.Mode, PSClass.RGBColorMode);
    desc2.putUnitDouble(PSKey.Width, PSUnit.Distance, 864);
    desc2.putUnitDouble(PSKey.Height, PSUnit.Distance, 864);
    desc2.putUnitDouble(PSKey.Resolution, PSUnit.Density, 300);
    desc2.putDouble(PSString.PixelScaleFactor, 1);
    desc2.putEnumerated(PSKey.Fill, PSKey.Fill, PSEnum.Transparent);
    desc2.putInteger(PSKey.Depth, 8);
    desc2.putString(PSString.profile, "sRGB IEC61966-2.1");
    desc1.putObject(PSKey.New, PSClass.Document, desc2);
    executeAction(PSEvent.Make, desc1, dialogMode);
  };


Those blocks of code appear to be identical to me - except for Line 16 where the name of the file is designated.

What do you think...?
xbytor

Action to Javascript - problem with text

Post by xbytor »

kcp wrote:Those blocks of code appear to be identical to me - except for Line 16 where the name of the file is designated.

What do you think...?

The code looks fine. Something is going wrong somewhere else.

BTW, it turns out that there is a bug in PS that causes apparently random actions getting chosen when you do a 'ActionToJavascript' run. It turns out that if you have more than one action with the same name in your palette, it will apparently always choose the first one when you try to create a droplet from JS, which I do internally.

The only work-around I could do in code is to (instead) automatically save the action to a temporary .atn file, then run ActionFileToJavascript on that and delete all the unneeded parts.

-X