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

Can't read or write files in ScriptUI Folder

Community Beginner ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

Hi all, I am having trouble with a dockable script that I am doing.

 

My error was when I finished it and tried to put the ScriptUI folder to test it and see that it didn't work, I tried it before without any icon applied and it worked fine.

 

Assuming Allow script access to script files is enabled, if I run the script from the desktop it works perfectly and there are no problems creating or reading files, but in ScriptUI Folder it is impossible to do so. I recreate the problem by creating a simple user interface with a binary icon that creates a folder for the temporary image and other things that I need to put in my actual script.

 

What am I doing wrong?

Why can't I read or write files to the ScriptUI folder and yes to the desktop or another folder?

 

 

 

function myScript(thisObj){

function myScript_buildUI(thisObj){
  var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "test", undefined, {resizable: true, closeButton: true});

  var resMain = "group{ orientation:'column', \
                          main_panel: Group { type: 'group', orientation: 'column', \
                              but_img: IconButton { preferredSize: [30,30] },\
                          },\
                }";


    var imgNRM = "\u0089PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00\x00\x00\x19\x00\x00\x00\x19\b\x06\x00\x00\x00\u00C4\u00E9\u0085c\x00\x00\x01\x15IDATH\u0089\u00ED\u0093=NBA\x14\u0085\u009F$\u00C6\u00C2P[\u00DA\u00DA\u00D8\u00D3\u00B8\x01\x12(\u00E8\u00F0)F\x13\u008AW\x00\r;\u00B0\u00A2\u00A3t\x05\u00AE\u00C0\r\u00B8\x00\x12z\n\n\x13\u00B5\u00B2\u00B01\u0082\u00E43\x13\x0E\u00C9-\u00DE\u00BB\u00A3\t\u00E5\u009Cn\u00CE|g\u00CE\u00FCd\u00B2\u00A4\u00A4\u00A4\u00FF\x0Bh\x03\u00AF\u00C0\u00B5\x17\x06\x1E\u0081\x0F\u00E0$\u00B0\u00CA\u00B4\u00A3\u0085@\x17X\u00B1\u00D5\u00A5\u00C3\u00DD\u0088y\x03\u00EA\u0081\u00D58d\u00BB^A\u00D8\u00CDFp\u00E1p\u00A7\u00C0\u00A7\u00B8\u00A6\u00F1\x0Bya\u008D\u00AB\u00B2\u00A0\x05n\u009D\u0082\x1A\u00F0,\u00F6\u00A1d\u00FE\u00AEt\u00A3\u00C0\u00C8\x14\u00E4\u0095G\u00DD\u00B2c\u00B1\x0B\u00E0\u00B8\u0082\u00C9M\u00D1hg\u00AEeL#\x05\u00E7\u00C07\u00F0\x034\"\u00ECTk\u00AEwF\x11;\tp\x04\u00CC\u00C5\u00DDG\n\u00F2\u00AA+\u00EBkbS\u00F6\u00E8\u00C0D\u00A1\x19p\u00E8\x14\x14f\u009D~l\x07\x03\u00E3_\u00C8\u00FF\x02\u00CE\u009C\u0082\u00C1\u009F\u00DE\x16\u00E8\u0098\x7F\u00D2\u00D35-5\x1E:\u00B9\u009E\u00F9'\u009D\u00CA\x02\x13h\x01/:Y\u00F8h\u00EF\u00C0\x13p\u00E0dreZ\u00D1\u0082\u00A4\u00A4\u00FD)\u00CB\u00B2_y\u00AF\u00C50\u00E5\u00BC\u0081\u00DE\x00\x00\x00\x00IEND\u00AEB`\u0082";
    myPanel.grp = myPanel.add(resMain);

    var myScriptFilePath = File($.fileName).path; // the URI of the folder that contains the script file
    //var myScriptFilePath =  "~/Desktop/";
    var myScriptFolderPath = myScriptFilePath + encodeURI("/tempFolder"); // the URI of the folder script resources
    var myFolder = new Folder(myScriptFolderPath);
    if ( ! myFolder.exists ) {
        myFolder.create();
    }

    var myFile = new File(myScriptFolderPath + encodeURI("/tempImage.png"));
    myFile.encoding = "BINARY";
    myFile.open( "w" );
    myFile.write( imgNRM );
    myFile.close();

    var butImg = myPanel.grp.main_panel.but_img;
    butImg.image = ScriptUI.newImage (myFile);

    butImg.onClick = function () { alert("bye"); myPanel.close(); }
    myPanel.onShow = function () { alert("Hello World"); }

    return myPanel;
}

// load, check and show the panel
var myScriptPal = myScript_buildUI(thisObj);

if (myScriptPal != null && myScriptPal instanceof Window){
       myScriptPal.center();
       myScriptPal.show();
}

}
myScript(this);
}

 

 

 

 

Hope someone can bring me light on this, thanks in advance!

TOPICS
Error or problem , How to , Scripting

Views

487

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
Community Beginner ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

For complete the issue im trying with AE 2019 and AE 2020 on windows 10.

Know that sounds like noob question or strange behavior but any answer that can orient me to right way will be grateful.

Im stuck trying creating folder and files in Scripts Folder, either Scripts and ScriptsUI, either images or files, this only recreates the simplest error that i had but the big problem is writing files and read them in that folder, outside like desktop works perfect... Thanks

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
Community Expert ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

It is not a good idea to create your image files in the same folder as the script itself. The Script UI Panels folder is inside the Applications folder and this is not writable for average users.

Best store your custom files in Folder.userData. So create a subfolder in Folder.userData (something like the name of your script) and then store all your files there.

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

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
Community Beginner ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

Very very grateful Mathias, i already imagined that it was due to writing permission problems and that what you are telling me was the simplest solution.

 

I have used many scripts that used files located in a folder within ScriptUI Panels and understood that there had to be a way to do it.

 

I will have no choice to do it this way but if there was any way to get it it would be great to know how

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
Community Beginner ,
Jul 01, 2020 Jul 01, 2020

Copy link to clipboard

Copied

LATEST

If i write and read files in other folder works fine like before in desktop but im having an strange issue when i try to load an onShow event for myPanel if its in dockable panel. I edited the code for testing, how i can launch some operations when script is showing if myPanel.onShow doesnt work?

 

I hope you Mathias or someone elsecan help me , thanks again for all your help.

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