Page 1 of 1

simple function code from jsx script not working

Posted: Mon Dec 26, 2016 3:16 pm
by Chris_Kalmar
Photoshop cc 2015.00
Eclipse + extension builder 3

First I create basic folder structure for the project
css
img
lib
host
js
jsx

and call all scripts and stylesheets in index.html like this:

<head>
<script src="lib/CSInterface-4.0.0.js"></script>
<script src="lib/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="js/main.js"></script>

<!-- styles for this extension -->
<link href="css/stylesheet.css" rel="stylesheet">

<title>test</title>
</head>


opennewdocument.jsx-----------------

#target photoshop


cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
//==================== open new document ==============
//
function opennewdocument() {
// Make
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putString(sTID("preset"), "Clipboard");
desc1.putObject(cTID('Nw '), cTID('Dcmn'), desc2);
executeAction(cTID('Mk '), desc1, dialogMode);
};

step1(); // Make
};



//=========================================
// opennewdocument.main
//=========================================
//

opennewdocument.main = function () {
opennewdocument();
};

opennewdocument.main();

// EOF

"opennewdocument.jsx"
// EOF


Then, I put opennewdocument.jsx (above) script into jsx folder and connect it's path in the main.js file (below)
(the .jsx is converted from simple action that opens a new document)

main.js
function loadJSX() {
var csInterface = new CSInterface();
var fileName = "opennewdocument.jsx";
var extensionRoot = csInterface["getSystemPath"](SystemPath.EXTENSION) + "/jsx/";
csInterface["evalScript"]("$.evalFile(\"" + extensionRoot + fileName + "\")")
}


Then i make a button that need to open document on click like so:

<button onclick="opennewdocument()" type="button" class="new-doc"></button>


and nothing :/
:o

Re: simple function code from jsx script not working

Posted: Mon Dec 26, 2016 3:50 pm
by Chris_Kalmar
architecture.jpg
architecture.jpg (271.83 KiB) Viewed 7649 times
Here is a graphical view too.

I'm really frustrated with this because i can't get anything to work correctly.
First I can't get simple alert to work, and after I reinstalled Photoshop to a newer version everything magically started to work.

Now I'm having problem with calling simple functions from jsx,
I just need to evalScript on button click - nothing complicated

If it's a bug again
think I'll give up until some better time when extensions for Photoshop will use more
consistent and more logical code.


C

Re: simple function code from jsx script not working

Posted: Tue Dec 27, 2016 7:43 am
by ApWizard
Hello!
Don't connect the JSX through the main.js, it is supposed to be "linked" via the manifest (e.g.: https://github.com/adobe-photoshop/gene ... nifest.xml)

Code: Select all

<Resources>
<MainPath>./renamelayers.html</MainPath>
<CEFCommandLine>
<Parameter>--enable-nodejs</Parameter>
</CEFCommandLine>
<ScriptPath>./host/RenameLayers.jsx</ScriptPath>
</Resources>
this one line does it: <ScriptPath>./host/RenameLayers.jsx</ScriptPath>

Re: simple function code from jsx script not working

Posted: Tue Dec 27, 2016 12:54 pm
by Chris_Kalmar
Hi again ApWizard,
Buon Natale

Ah I see, you are right, but what if I have multiple .jsx files (converted from actions)
How to connect them and to call them on click?

I'm confused about it.
In extension that I study from I see that they solved things in other way.
They declare just one jsx file in manifest script path but then they put about 20 other .jsx
files into host folder.

Then they just call onclick() on html element for various functions. It'looks very simple!
I can't see what is inside their main.jsx pointed in manifest.xml because it is JSXbin file.

Thank you
ApWizzard

C

Re: simple function code from jsx script not working

Posted: Tue Dec 27, 2016 2:19 pm
by ApWizard
Hi Chris!
Merry Christmas to you too :)
It seems like...we are almost the 2 of us online here :lol:

So, you are correct indeed: having the jsx-loader-function is needed. I got distracted :( :|

You're almost there, as I previously said in another thread you don't call it directly. JS can interact with the JSX "space" only via evalScript:
main.js

Code: Select all


csInterface = new CSInterface();

function callJSXFunction(whichOne){
csInterface.evalScript(whichOne);
}
html:

Code: Select all


<button onclick="callJSXFunction(opennewdocument.main)" type="button" class="new-doc"></button>
this should work.

edit: for future reference, when you'll be dealing with callbacks and events, evalScript is asynchronous.