Skip to main content
Inspiring
August 1, 2019
Question

Include .jsx local libraries in main.jsx

  • August 1, 2019
  • 3 replies
  • 3320 views

Hi,

I am trying to include the file myFunc.jsx which has local functions I created.

It contains e.g:

function getDocName() {

    return app.documents.length ? app.activeDocument.name : "No docs open!";

}

getDocName is used in my main.js file:

function f_DocName() {

var csInterface = new CSInterface();

$("#btnDocName").click(function () {

csInterface.evalScript('getDocName()', function (result) {

$("#folderName").val(result);

});

});

}

I tried to load the jsx in my main.js file like this:

function loadJSX() {

var csInterface = new CSInterface();

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/host/include/";

csInterface.evalScript('$._ext.evalFiles("' + extensionRoot + '")');

  }

And of course I call loadJSX() in my init function.

But getDocName() was not recognized, not unless i defined it in my main.jsx file

What is the right way to include jsx files with local function to be accessed from within main.js ?

Thank you

This topic has been closed for replies.

3 replies

karpiyonAuthor
Inspiring
August 7, 2019

thanks,

i'll give it another go since it's not a critical issue yet.

if that does not work i'll upload it.

Dan

Justin Taylor-Hyper Brew
Community Expert
Community Expert
August 1, 2019

Sounds like your main.jsx isn't evaluating your myFunc.jsx correctly. Can you post the source code to main.jsx, and do some debugging to make sure that file is actually getting evaluated.

karpiyonAuthor
Inspiring
August 1, 2019

i guess it is not being evaluated but i can't find the reason for it.

this is a summery of my main.jsx:

function Initialize() {

document.body.style.backgroundColor = "#" + UIColorToHexString(csInterface.hostEnvironment.appSkinInfo.panelBackgroundColor);

Persistent(true);

Register(true, gRegisteredEvents.toString());

}

(function () {

'use strict';

var csInterface = new CSInterface();

function init() {

loadJSX();

// f_DocName();

f_Browse();

f_create();

setFilePrefix();

getSessionCookies();

toggleText("cbAddWhiteEdge", "etWhiteEdgeSize");

toggleText("cbAddWrap", "etwrapWidth");

toggleText("cbAddWrap", "etwrapOpacity");

$("#mySlider").prop("value", $("#jpegQuality").val());

themeManager.init();

showSliderVal();

}

init();

}());

.......

function loadJSX() {

var csInterface = new CSInterface();

var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/host/include/";

alert(extensionRoot );

csInterface.evalScript('$._ext.evalFiles("' + extensionRoot + '")');

  }

The above alert(extensionRoot) is showing the correct path and i was able to follow it in the debugger as far as i could:

it found my function:

part of myFunc.jsx is this file:

function getFolder() {

    try {

        var defaultFolder = File(app.activeDocument.path);

        alert(defaultFolder);

    } catch (someError) {

        var defaultFolder = File("~");

    }

    mf = function (f) { return /\.ai$/i.test(f.name) },

        f = Folder.selectDialog("Import Folder", defaultFolder)

    if (f != null) {

        return f.fsName;

    } else {

        // if (f) return f.fullName;

        return "";

    }

}

function getDocName() {

    return app.documents.length ? app.activeDocument.name : "No docs open!";

}

but as i said, only when i define getFolder() in my main.jsx will it be evalutaed

Justin Taylor-Hyper Brew
Community Expert
Community Expert
August 1, 2019

Your main.jsx is not written in ExtendScript, it's written in JavaScript. Just to clarify, in Adobe development .js = JavaScript/CEP and .jsx = ExtendScript. You need a main.js file to run your CEP/JavaScript side of things, then call your main.jsx (ExtendScript) with a function like loadJSX(), which will then evaluate your myFunct.jsx file which you can modify and refresh as you work.

Refer to the samples to see how this should be set up, specifically how the PPRO example handles this.

Trevor:
Legend
August 1, 2019

Using JSX.js A Game Changer in Adobe HTML Extensions Development? – Creative-Scripts.com is really simple.

See the examples there and also Shawn posted a sample github repo on the forum here about a week ago.

If you need help with it after reading the link leave a post here.