Highlighted

JSX error

New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

Hi, this is my first time posting here, and I wanted ask jsx scripting.

I'm trying to apply the code reading Photoshop JavaScript Reference page 76.

 

// Open the document in the script
var fileRef = new File("/c/myfile")
var docRef = app.open(fileRef)

//Call emboss with desired parameters
emboss( 75, 2, 89 );
//finish the script

//include the function in the script file
function emboss(angle, height, amount )
{
var id32 = charIDToTypeID( "Embs" );
var desc7 = new ActionDescriptor();
var id33 = charIDToTypeID( "Angl" );
desc7.putInteger( id33, angle );
var id34 = charIDToTypeID( "Hght" );
desc7.putInteger( id34, height );
var id35 = charIDToTypeID( "Amnt" );
desc7.putInteger( id35, amnt );
executeAction( id32, desc7, DialogModes.NO );
}

 

But I got the error code:

Error 1233: Expected a reference to an existing File/Folder Line:3
-> var docRed = app.open(fileRef)

 

Could you give me some advice on what to fix this code?

I'm using latest version Photoshop2020.

Hello, welcome. 🙂

 

the first line points to a file on your computer.

var fileRef = new File("/c/myfile")

 If that file does not exist at that location, it cannot be opened.

By changing the fileRef string (that's this part: "/c/myfile") to a file that does exist, it will work.

 

You could for example change it to "c:\mochisan.jpg" or "d:\these\are\folders\picture.png".

If those files exist, the script/photoshop will find them.

TOPICS
Actions and scripting, Problem or error, Windows

Views

102

Likes

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

JSX error

New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

Hi, this is my first time posting here, and I wanted ask jsx scripting.

I'm trying to apply the code reading Photoshop JavaScript Reference page 76.

 

// Open the document in the script
var fileRef = new File("/c/myfile")
var docRef = app.open(fileRef)

//Call emboss with desired parameters
emboss( 75, 2, 89 );
//finish the script

//include the function in the script file
function emboss(angle, height, amount )
{
var id32 = charIDToTypeID( "Embs" );
var desc7 = new ActionDescriptor();
var id33 = charIDToTypeID( "Angl" );
desc7.putInteger( id33, angle );
var id34 = charIDToTypeID( "Hght" );
desc7.putInteger( id34, height );
var id35 = charIDToTypeID( "Amnt" );
desc7.putInteger( id35, amnt );
executeAction( id32, desc7, DialogModes.NO );
}

 

But I got the error code:

Error 1233: Expected a reference to an existing File/Folder Line:3
-> var docRed = app.open(fileRef)

 

Could you give me some advice on what to fix this code?

I'm using latest version Photoshop2020.

Hello, welcome. 🙂

 

the first line points to a file on your computer.

var fileRef = new File("/c/myfile")

 If that file does not exist at that location, it cannot be opened.

By changing the fileRef string (that's this part: "/c/myfile") to a file that does exist, it will work.

 

You could for example change it to "c:\mochisan.jpg" or "d:\these\are\folders\picture.png".

If those files exist, the script/photoshop will find them.

TOPICS
Actions and scripting, Problem or error, Windows

Views

103

Likes

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
Oct 02, 2020 0
Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

Hello, welcome. 🙂

 

the first line points to a file on your computer.

var fileRef = new File("/c/myfile")

 If that file does not exist at that location, it cannot be opened.

By changing the fileRef string (that's this part: "/c/myfile") to a file that does exist, it will work.

 

You could for example change it to "c:\mochisan.jpg" or "d:\these\are\folders\picture.png".

If those files exist, the script/photoshop will find them.

Likes

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
Reply
Loading...
Oct 02, 2020 1
New Here ,
Oct 02, 2020

Copy link to clipboard

Copied

Thank you very much for your help. But the same error is returend😭

Likes

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
Reply
Loading...
Oct 02, 2020 0
Participant ,
Oct 02, 2020

Copy link to clipboard

Copied

I've tested your code this time (instead of just reading it as in my initial reply)

You're right, it does not work as-is.

 

  • the fileRef in the original code is not pointing to a real file
    (you have give new File(...) a string that actually points to a file photoshop can open)
  • the "amount" parameter has a typo inside your function. (it requests amnt instead of amount)
  • in your first post, there is another possible type namely, you're typing docRed there. You should check your code for that. I'm not sure if it's a typo or not, but it's likely to be one.

 

This rewritten code works on my computer:

#target photoshop;

// Open the document in the script
var fileRef = new File("/Users/JB/Desktop/d.jpg"); // <-- change this
var docRef = app.open(fileRef);
emboss( 75, 2, 89 );

//function in the script file
function emboss(angle, height, amount )
{
    var ADEmboss = new ActionDescriptor();
    ADEmboss.putInteger( charIDToTypeID( "Angl" ), angle );
    ADEmboss.putInteger( charIDToTypeID( "Hght" ), height );
    ADEmboss.putInteger( charIDToTypeID( "Amnt" ), amount ); // there was a typo here
    executeAction( charIDToTypeID( "Embs" ), ADEmboss, DialogModes.NO );
}

 

Change the green part > "Users/JB/Desktop/d.jpg" < to a path of a picture stored on your computer and it should work.

Note: You cannot load a picture from the internet this way.

This:

var fileRef = new File("http://www.myawesomepictures.com/images/ForMochisan.jpg");

Does not work. And it gives you the same error as you initially had. 


Lastly, p76 in that pdf talks about channels, nothing related to loading files or Emboss.
Am I missing something?

 

Likes

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
Reply
Loading...
Oct 02, 2020 0
New Here ,
Oct 03, 2020

Copy link to clipboard

Copied

I'm so sorry!  Photoshop Scripting Guide page 76 is right.
Your code works on my computer! Thank you very much!

 

Likes

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
Reply
Loading...
Oct 03, 2020 0
jefbr LATEST
Community Beginner ,
Oct 05, 2020

Copy link to clipboard

Copied

Don't worry about it. We all need to learn from the beginning.

While you are here, you'll find a lot of very helpful people here that have told me the same thing not too long ago. 🙂 I'm happy for you it works, good luck!!!

Likes

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
Reply
Loading...
Oct 05, 2020 0