djmisterjon

It would be nice to have a button to auto open and import in spine software.
djmisterjon
  • Posts: 74

Nate

We tried adding that. Photoshop is able to run external programs, but it doesn't work well. File execute runs a file with the associated program, but you can't pass arguments. app.system seemed promising, but it doesn't handle quotes correctly, and so would fail if paths had any spaces. Sadly this means we don't have a reliable way of running Spine from the Photoshop script.

If you want to try, here is some code that runs Spine to import the JSON into a .spine project file, then runs Spine again to open the project file:
var spineExe = new File("C:\\Program Files (x86)\\Spine\\Spine.exe");
var spineCom = new File("C:\\Program Files (x86)\\Spine\\Spine.com");
if (!spineExe.exists || !spineCom.exists) spineExe = spineCom = new File("/Applications/Spine/Spine.app/Contents/MacOS/Spine");
if (spineExe.exists && spineCom.exists) {
var name = jsonFile.name;
if (endsWith(name, ".json")) name = name.slice(0, -5);
var projectFile = new File(jsonFile.parent + "/" + name + ".spine");
if (!projectFile.exists) {
app.system('"' + spineCom.fsName + '" -i "' + jsonFile.fsName + '" -o "' + projectFile.fsName + '" -r');
app.system('"' + spineExe.fsName + '" "' + projectFile.fsName + '" -r');
}
}
User avatar
Nate

Nate
  • Posts: 9491

djmisterjon

hum, i don't know how scripting in a photoshop sdk environment but first test with my spine batch convert bat script seem work fine to be executed and also await correctly!

How do you feel, maybe like the logo.png, add a spineExecutable.bat in same dir

Also i think we can create new file in jsx like this.
var bat = new File("C:/ps_test.bat");
bat.execute();
Am not sure why you say it not possible ?
I can see many way to proceed.
On my side i success pass arg like this from the bat
cd %~dp0
node spineConvertor.js %~dp0
cmd /k
and with node
exec("${SPINE_EXE}" -u ${VERSION} ${_input} ${_output} ${_export},
djmisterjon
  • Posts: 74

Nate

The problem is that the executable and the parameters may contain spaces, in which case quotes are needed, eg:
app.system('"path to/something.bat" "param with space"');
When I tried using quotes like this, app.system doesn't interpret the quotes correctly. For example, it says it can't execute path.
User avatar
Nate

Nate
  • Posts: 9491

djmisterjon

Nate wrote:The problem is that the executable and the parameters may contain spaces, in which case quotes are needed, eg:
app.system('"path to/something.bat" "param with space"');
When I tried using quotes like this, app.system doesn't interpret the quotes correctly. For example, it says it can't execute path.
this is weird, it look fine on my side.
I test this
app.system('...path\\test.bat "1param with space" "2param with space"')
And arguments passed seem handle spaces and quotes correctly !

Do you have the photoshop 2020 ? It can be a bug from old versions?
Or maybe am not understand ? this intrigue me.
djmisterjon
  • Posts: 74

Nate

I think your test should be:
app.system('"C:\\path with spaces\\test.bat" "1param with space" "2param with space"');
I usually try first with older versions, but I can try again on newer.
User avatar
Nate

Nate
  • Posts: 9491

djmisterjon

Nate wrote:I think your test should be:
app.system('"C:\\path with spaces\\test.bat" "1param with space" "2param with space"');
I usually try first with older versions, but I can try again on newer.
Ok i succeed to open a existing project with photoshop.
Am busy now so i will write a code for create new file projets and auto-open maybe tonight. :D
But it work fine on my side, i just need to do more testing to find the best solution.

---

Nate wrote:
Ok here my friend, i pull a request here
https://github.com/EsotericSoftware/spine-scripts/pull/7

you just have to integrate a checkBox and test on the environment macos and linux.
Work 100% on my side (WINDOW).
So if project exist, it open projet only.
If not , it build a project and open.
if('open spine Checked'){
function makeBash(){
var str = '';
for (var i = 0, l = arguments.length; i < l; i++) {
var key = arguments[i];
str+=key;
}
return str;
}
var Q = '"' ; //Quote
var SQ = '" '; // SpaceQuote for arguments space
var spineExe = new File("C:\\Program Files (x86)\\Spine\\Spine.exe");
var spineCom = new File("C:\\Program Files (x86)\\Spine\\Spine.com");
var projectFile = new File(jsonFile.parent + "/" + name + ".spine");

var bashExe = makeBash(
'\n',
'start ',
Q+spineExe.fsName+SQ,
Q+projectFile.fsName+SQ,
'\n',
);
var bashCom = makeBash(
'\n',
'start ',
'/W /D ',
Q+spineCom.fsName.split('Spine.com')[0]+SQ,
'Spine.com ',
'-i ',
Q+jsonFile.fsName+SQ,
'-o ',
Q+projectFile.fsName+SQ,
'-r ',
'\n',
);

var tempBat = new File(jsonFile.parent+"/temp.bat");
tempBat.open("w");
tempBat.write('@echo off');
if(!projectFile.exists){
tempBat.write(bashCom);
}
tempBat.write(bashExe);
tempBat.write('cmd /k');
tempBat.close();
tempBat.execute()
//tempBat.remove(); // comment this to debug the bash script
}
}
The temp output for the batch script look like this
@echo off
start /W /D "C:\Program Files (x86)\Spine\" Spine.com -i "C:\Users\InformatiqueLepage\Desktop\Sans titre-1.json" -o "C:\Users\InformatiqueLepage\Desktop\Calque 0.spine" -r

start "
C:\Program Files (x86)\Spine\Spine.exe" "C:\Users\InformatiqueLepage\Desktop\Calque 0.spine"
cmd /k
I can't code the photoshop button because am coding blindly without the photoshop sdk, and i don't know where to find it, i sot succeed to find it on adobe forum.
djmisterjon
  • Posts: 74


Return to Editor