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

Run script, from another script

Explorer ,
Feb 10, 2011 Feb 10, 2011

Copy link to clipboard

Copied

Hello everybody. I try learn to use a scripts in AE. And I have some trouble. But first of all this:

var AEPanel = this;
myBTN = AEPanel.add("button", [10, 10, 120, 40], "Apply");
myBTN.onClick = onScriptButtonClick;
function onScriptButtonClick()
{
var scriptFile =  File("Support Files/Scripts/Change Render Locations.jsx");
scriptFile.open();
eval(scriptFile.read());
scriptFile.close();
}

I put this script in ScriptUI Panels folder. Panel appear normally. But! Then i click on the button, nothing happens.

And in the debugging I see that the path to the script is identified correctly. It is true instead of spaces in the tooltip I see these the symbols:
%20

Pleas help me. How to properly run a script?

TOPICS
Scripting

Views

1.9K

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

correct answers 1 Correct answer

Enthusiast , Feb 11, 2011 Feb 11, 2011

I'm no expert on how the file stuff works, but the problem is that you're assuming the default starting path is the AE app folder, but this isn't (always? ever?) the case. If you don't already have it, google "Javascript Tools Guide" to find and download Adobe's PDF that covers all the file related stuff.

I found this in the guide under "Specifying paths":

A relative path name in URI notation is appended to the path of the current directory, as stored in the globally available current property of

...

Votes

Translate

Translate
Enthusiast ,
Feb 10, 2011 Feb 10, 2011

Copy link to clipboard

Copied

This should work. I've also left in some alerts to show how I tested it.

I start with this script's file object File($.fileName), then find the parent (ScriptUI Panels), then that folder's parent (Scripts), then add the additional "ChangeRender..." filename to that path.

%20 is just how space characters are encoded and doesn't matter (see the File.decode line for a way to see them as spaces)

var AEPanel = this;

myBTN = AEPanel.add("button", [10, 10, 120, 40], "Применить");

myBTN.onClick = onScriptButtonClick;

function onScriptButtonClick()

{

var scriptFile = File(File($.fileName).parent.parent.absoluteURI + "/Change Render Locations.jsx");

alert(scriptFile.absoluteURI);

alert(File.decode(scriptFile.absoluteURI));

alert("the file exists = " + scriptFile.exists);

scriptFile.open();

eval(scriptFile.read());

scriptFile.close();

}

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 ,
Feb 10, 2011 Feb 10, 2011

Copy link to clipboard

Copied

Thank you Paul!

%20 is just how space characters are encoded and doesn't matter

Ye, I know this,.. it`s was my just suggestion...

So. The solution in this string:

var scriptFile = File(File($.fileName).parent.parent.absoluteURI + "/Change Render Locations.jsx")

Everything else is identical, in my script and in your. Of course except alerts. I remove them, and now i have just my button which works fine....

And may be you can suggest, why does not work "my" method of running the script?

Thanks again!

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
Enthusiast ,
Feb 11, 2011 Feb 11, 2011

Copy link to clipboard

Copied

I'm no expert on how the file stuff works, but the problem is that you're assuming the default starting path is the AE app folder, but this isn't (always? ever?) the case. If you don't already have it, google "Javascript Tools Guide" to find and download Adobe's PDF that covers all the file related stuff.

I found this in the guide under "Specifying paths":

A relative path name in URI notation is appended to the path of the current directory, as stored in the globally available current property of the Folder class.

By trying this code, I could see that my current path was the root folder of my boot drive (i.e. MacintoshHD):

var currentFiles = Folder.current.getFiles();

     for (x = 0; x < currentFiles.length; x++) {

     alert(currentFiles.name);

}

And when I change the name to a file I know is in the root folder, it finds it ok:

var scriptFile = File("theNameOfAFileInMyMacintoshHDRootFolder");

alert("the file exists = " + scriptFile.exists);

In the PDF if you look for "Folder Class Properties" you'll find a variety of ways to get a starting point for a path, but I've found that starting from $.fileName (the path + name of the running script) and navigating from there works best.

Feel free to keep asking questions, but you may want to mark this thread as 'answered'.

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 ,
Feb 11, 2011 Feb 11, 2011

Copy link to clipboard

Copied

LATEST

Thank you! Thank you! Thank you!

I just started learn a scripting, and I not good in english. This is make a some trouble for me....

Anyway thank you!!!

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