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

Save .JSON file from HTML Panel Extension

Explorer ,
May 04, 2016 May 04, 2016

I'm developing an extension that creates a range of data as a javascript object. I'd like to allow the user to click a "save" button, navigate to a directory (optional), and save the json file created in the HTML session. I tried a download link (similar to what I'd do on a web page), but that doesn't save out the file. Is there an efficient way for a user to save out txt,json, or xml data from an HTML Panel?

TOPICS
SDK
1.8K
Translate
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

Explorer , May 04, 2016 May 04, 2016

Alright, I've got a working version using jsx:

function saveJSON(txt)

{

    txt=JSON.stringify(txt)

    var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');

   

    var Path = app.activeDocument.path;

    var saveFile = File(Path + "/" + Name +".json");

   if(saveFile.exists)

        saveFile.remove();

    saveFile.encoding = "UTF8";

    saveFile.open("e", "TEXT", "????");

    saveFile.writeln(txt);

    saveFile.close();

}

Reference this post for getting JSON.stringify on the JSX side: HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.

...
Translate
Adobe
Engaged ,
May 04, 2016 May 04, 2016

Maybe you can do it with just javascript, jquery, etc.

What I would do is create a hybrid plugin and pass whatever data you want from the extension back to the C++. There you can use the API to pop a Save as dialog.

Translate
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 ,
May 04, 2016 May 04, 2016

btempleton1982 Thanks for the tip! Does anyone have a simpler solution that doesn't involve hybrid plugins?

Translate
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 ,
May 04, 2016 May 04, 2016
LATEST

Alright, I've got a working version using jsx:

function saveJSON(txt)

{

    txt=JSON.stringify(txt)

    var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');

   

    var Path = app.activeDocument.path;

    var saveFile = File(Path + "/" + Name +".json");

   if(saveFile.exists)

        saveFile.remove();

    saveFile.encoding = "UTF8";

    saveFile.open("e", "TEXT", "????");

    saveFile.writeln(txt);

    saveFile.close();

}

Reference this post for getting JSON.stringify on the JSX side: HTML Panels Tips: #5 passing Objects from JSX to HTML | Photoshop, etc.

Translate
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