首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Bridgetalk - adobe脚本使用变量保存,正确引用,在字符串脚本中用变量替换字符串

Bridgetalk - adobe脚本使用变量保存,正确引用,在字符串脚本中用变量替换字符串
EN

Stack Overflow用户
提问于 2022-02-24 20:57:13
回答 2查看 187关注 0票数 0

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

完整脚本:

代码语言:javascript
复制
#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部分工作(字符串替换无效):

代码语言:javascript
复制
#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();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-03-03 20:55:43

代码语言:javascript
复制
#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();
票数 0
EN

Stack Overflow用户

发布于 2022-02-26 13:17:57

只是猜测而已。

也许在这里...'action set name'),app.activeDocument...应该是;而不是,

代码语言:javascript
复制
var script = "app.doScript('action name', 'action set name'); app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71258164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档