Link in Zwischenablage kopieren
Kopiert
Hello, would be happy if someone may point out how to run a script from a floating panel button.
below fails to be able to run the script once the button is hit.
The script it is talking to runs perfectly fine on its own, but the button script is failling to call it correctly.
The script says there is no document but i have one open...
Many thanks
Smyth
//@target illustrator
//@targetengine "persistent"
//@strict on
// Suppress warning
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
var win = new Window('palette', 'Run Custom Script', undefined, { closeButton:true });
win.alignChildren = ['fill', 'top'];
var runBtn = win.add('button', undefined, 'Run Grids V2.jsx');
runBtn.onClick = function() {
var scriptPath = "C:/Program Files/Adobe/Adobe Illustrator 2021/Presets/en_US/Scripts/Grids V2.jsx";
var scriptFile = new File(scriptPath);
if (!scriptFile.exists) {
alert("Script not found at:\n" + scriptFile.fsName);
return;
}
try {
$.evalFile(scriptFile);
} catch (e) {
alert("Could not execute script:\n\n" + e);
}
};
win.center();
win.show();
Hi @SmythWharf, persistent floating palettes are more complicated to code than modal dialogs, because you need to communicate between Illlustrator and the palette in the same way you would communicate between Illustrator and, say, Photoshop... via BridgeTalk.
I wrote a demo script here showing a minimal set up. It is a palette that shows the currently selected raster item's scale and rotation. That should get you started.
- Mark
Link in Zwischenablage kopieren
Kopiert
Hi @SmythWharf, persistent floating palettes are more complicated to code than modal dialogs, because you need to communicate between Illlustrator and the palette in the same way you would communicate between Illustrator and, say, Photoshop... via BridgeTalk.
I wrote a demo script here showing a minimal set up. It is a palette that shows the currently selected raster item's scale and rotation. That should get you started.
- Mark
Link in Zwischenablage kopieren
Kopiert
Hello,
I see, I am afriad the link is not working. May this be updated.
Best,
Smyth
Link in Zwischenablage kopieren
Kopiert
Sorry! Fixed now.
Link in Zwischenablage kopieren
Kopiert
Thank you very much
Link in Zwischenablage kopieren
Kopiert
#target illustrator
#targetengine main
// --------------- CONFIG ---------------
var scriptsFolder = Folder("C:/Program Files/Adobe/Adobe Illustrator 2021/Presets/en_US/Scripts");
// --------------------------------------
// Create floating panel (ScriptUI palette)
var panel = new Window('palette', 'Scripts Runner');
panel.orientation = "column";
panel.alignChildren = ["fill", "top"];
// List scripts and create buttons
if (scriptsFolder.exists) {
var scriptFiles = scriptsFolder.getFiles("*.jsx");
if (scriptFiles.length === 0) {
panel.add("statictext", undefined, "No .jsx scripts found!");
}
for (var i = 0; i < scriptFiles.length; i++) {
(function(scriptFile) {
var btn = panel.add("button", undefined, scriptFile.name);
btn.onClick = function() {
// Defensive: make sure a document is open
if (app.documents.length === 0) {
alert("No document open!");
return;
}
try {
scriptFile.open('r');
var scriptContent = scriptFile.read();
scriptFile.close();
// Use BridgeTalk for robust context
var bt = new BridgeTalk();
bt.target = "illustrator";
bt.body = scriptContent;
bt.send();
} catch (e) {
alert("Failed to run script: " + scriptFile.name + "\n\n" + e);
}
};
})(scriptFiles[i]);
}
} else {
panel.add("statictext", undefined, "Scripts folder not found!");
}
panel.center();
panel.show();
yup seems to work many thanks
Smyth
Link in Zwischenablage kopieren
Kopiert
Good work! 🙂
Link in Zwischenablage kopieren
Kopiert
Any hints on how to run just one script form a location, I keep running into issues of scripts saying no document, when I try something, yet it is fine in the document above?
Thank you
Link in Zwischenablage kopieren
Kopiert
Oh it get's worse
when running scripts through the script runner, those scripts cannot read the xml file sitting in my documents. Running the script direcrly from Ilustrator is fine, so there is something in the script runner script which prevents the scripts it runs from seeing where it needs to see?
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen