Bridgetalk - adobe 脚本保存变量、正确引用、用字符串脚本中的变量替换字符串

发布于 2025-01-09 18:08:13 字数 2776 浏览 0 评论 0原文

我在保存文件时遇到问题,并且不知道为什么它不起作用。这是原始代码。我相信我错误地注释了变量或者 adobe 语法不正确。有人有这方面的经验吗? (损坏的部分: ,app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";)。报价变体很重要,否则无法正确发送到插画家

#target photoshop
//run action in photoshop
app.doAction ("action name", "action set name");
//get path of the open document
var psdpath = activeDocument.path.fsName;
//get directory name of psd, to use in filename later
var parentdirectory = activeDocument.path.name;

//start bridgetalk
var bt = new BridgeTalk;
//targets version 25. v26 crashes if window isnt active at run
        bt.target = "illustrator-25";
//run action in illustrator (which opens an eps w/linked file and performs certain tasks) and then save the document
        var script = "app.doScript('action name', 'action set name'),app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
//the entire action must be within double quotes        
//     var script = alert("test", "this sends alert to photoshop");
//     var script = "alert('test', 'this sends alert to illustrator'),alert('"+psdpath+"', '"+psdpath+"')"; //psdpath is properly sent to illustrator
        bt.body = script;
        bt.send();

更新 03/03/2022。 部分工作(字符串替换不起作用):

#target photoshop
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
app.doAction ("Photoshop Action Name", "Photoshop action Set");
var strScript = """
app.doScript("Illustrator Action Name", "Illustrator Action Set"); 
var doc = app.activeDocument;  
if (documents.length > 0){    
    var saveOpts = new EPSSaveOptions(); 
    saveOpts.embedLinkedFiles = embedImage = false;
    saveOpts.embedAllFonts = embedFont = true;
    saveOpts.includeDocumentThumbnails = false;
    saveOpts.saveMultipleArtboards = false;
        fullDocName = doc.fullName;
        for (i=0; i<doc.layers.length; i++){
            if (i-1<0) doc.layers[i].visible = true;
            else {
                doc.layers[i-1].visible = false;
                doc.layers[i].visible = true;
            }
            if (doc.layers[i].locked == false) {    
                docName = doc.layers[i].name+".eps";    
                var saveName = new File ( psdpathh + "/" + parentdirectoryy + ".eps");
                doc.saveAs( saveName, saveOpts );
            }
        }
    }
""";
var editedScript = strScript.replace("psdpathh", psdpath);
var editedScript2 = editedScript.replace("parentdirectoryy", parentdirectory);
BridgeTalk.bringToFront("illustrator"); 
var bt = new BridgeTalk;
        bt.target = "illustrator-25";
        bt.body = editedScript2;
        bt.send();

I'm having an issue with saving a file and I can't tell why it's not working. This is original code. I believe I'm commenting out the variables incorrectly or adobe syntax is incorrect. Does anyone have experience with this? (part that is broken: ,app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";). Quote variations are important otherwise it doesn't properly send to illustrator.

Full script:

#target photoshop
//run action in photoshop
app.doAction ("action name", "action set name");
//get path of the open document
var psdpath = activeDocument.path.fsName;
//get directory name of psd, to use in filename later
var parentdirectory = activeDocument.path.name;

//start bridgetalk
var bt = new BridgeTalk;
//targets version 25. v26 crashes if window isnt active at run
        bt.target = "illustrator-25";
//run action in illustrator (which opens an eps w/linked file and performs certain tasks) and then save the document
        var script = "app.doScript('action name', 'action set name'),app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
//the entire action must be within double quotes        
//     var script = alert("test", "this sends alert to photoshop");
//     var script = "alert('test', 'this sends alert to illustrator'),alert('"+psdpath+"', '"+psdpath+"')"; //psdpath is properly sent to illustrator
        bt.body = script;
        bt.send();

UPDATE 03/03/2022
Partially working (string replace does not work):

#target photoshop
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
app.doAction ("Photoshop Action Name", "Photoshop action Set");
var strScript = """
app.doScript("Illustrator Action Name", "Illustrator Action Set"); 
var doc = app.activeDocument;  
if (documents.length > 0){    
    var saveOpts = new EPSSaveOptions(); 
    saveOpts.embedLinkedFiles = embedImage = false;
    saveOpts.embedAllFonts = embedFont = true;
    saveOpts.includeDocumentThumbnails = false;
    saveOpts.saveMultipleArtboards = false;
        fullDocName = doc.fullName;
        for (i=0; i<doc.layers.length; i++){
            if (i-1<0) doc.layers[i].visible = true;
            else {
                doc.layers[i-1].visible = false;
                doc.layers[i].visible = true;
            }
            if (doc.layers[i].locked == false) {    
                docName = doc.layers[i].name+".eps";    
                var saveName = new File ( psdpathh + "/" + parentdirectoryy + ".eps");
                doc.saveAs( saveName, saveOpts );
            }
        }
    }
""";
var editedScript = strScript.replace("psdpathh", psdpath);
var editedScript2 = editedScript.replace("parentdirectoryy", parentdirectory);
BridgeTalk.bringToFront("illustrator"); 
var bt = new BridgeTalk;
        bt.target = "illustrator-25";
        bt.body = editedScript2;
        bt.send();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生不灭 2025-01-16 18:08:13

作为猜测。

也许这里 ...'操作集名称'),app.activeDocument... 应该是 ; 而不是 ,

var script = "app.doScript('action name', 'action set name'); app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";

As a guess.

Perhaps here ...'action set name'),app.activeDocument... should be ; instead of ,:

var script = "app.doScript('action name', 'action set name'); app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
甚是思念 2025-01-16 18:08:13
#target photoshop
app.doAction ("ps action name", "ps action set"); //replace w your action details
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
var strScript = """
app.doScript("illustrator action name", "illustrator action set"); //replace w your action details
var doc = app.activeDocument;
if (documents.length > 0){
    // Create the illusrtratorSaveOptions object to set the AI options
    var saveOpts = new EPSSaveOptions();
    // Setting IllustratorSaveOptions properties. 
    saveOpts.embedLinkedFiles = embedImage = true;
    saveOpts.embedAllFonts = embedFont = true;
    saveOpts.includeDocumentThumbnails = true;
    saveOpts.saveMultipleArtboards = false;
        fullDocName = doc.fullName;
        for (i=0; i<doc.layers.length; i++){
            if (i-1<0) doc.layers[i].visible = true;
            else {
                doc.layers[i-1].visible = false;
                doc.layers[i].visible = true;
            }
            if (doc.layers[i].locked == false) {    
                docName = doc.layers[i].name+".eps";    
                var saveName = new File ( "%1/%2 -- suffix.eps"); //replace " -- suffix" to whatever, keep .eps 
                doc.saveAs( saveName, saveOpts );
            }
        }
    }
""";
var editedScript = strScript.replace("%1", psdpath).replace("%2", parentdirectory);
BridgeTalk.bringToFront("illustrator-25"); // switch view to illustrator to prevent crashing 
var bt = new BridgeTalk;
//declare your illustrator version
bt.target = "illustrator-25";         
bt.body = editedScript;
bt.send();
#target photoshop
app.doAction ("ps action name", "ps action set"); //replace w your action details
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
var strScript = """
app.doScript("illustrator action name", "illustrator action set"); //replace w your action details
var doc = app.activeDocument;
if (documents.length > 0){
    // Create the illusrtratorSaveOptions object to set the AI options
    var saveOpts = new EPSSaveOptions();
    // Setting IllustratorSaveOptions properties. 
    saveOpts.embedLinkedFiles = embedImage = true;
    saveOpts.embedAllFonts = embedFont = true;
    saveOpts.includeDocumentThumbnails = true;
    saveOpts.saveMultipleArtboards = false;
        fullDocName = doc.fullName;
        for (i=0; i<doc.layers.length; i++){
            if (i-1<0) doc.layers[i].visible = true;
            else {
                doc.layers[i-1].visible = false;
                doc.layers[i].visible = true;
            }
            if (doc.layers[i].locked == false) {    
                docName = doc.layers[i].name+".eps";    
                var saveName = new File ( "%1/%2 -- suffix.eps"); //replace " -- suffix" to whatever, keep .eps 
                doc.saveAs( saveName, saveOpts );
            }
        }
    }
""";
var editedScript = strScript.replace("%1", psdpath).replace("%2", parentdirectory);
BridgeTalk.bringToFront("illustrator-25"); // switch view to illustrator to prevent crashing 
var bt = new BridgeTalk;
//declare your illustrator version
bt.target = "illustrator-25";         
bt.body = editedScript;
bt.send();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文