InDesign Javascript脚本:复制原位粘贴对象后如何将新对象与原选中对象编组
InDesign 脚本修改方案(支持自动编组)
调整逻辑
- 提前存储初始选中的图像引用,避免后续选区变更后无法定位应用了multiply效果的原图
- 原位粘贴后存储新生成的图像引用,将两组对象合并后赋值给
app.selection即可实现同时选中,直接调用编组方法完成操作 - 保留原有全部功能逻辑,仅新增编组相关代码
修改后完整代码
// 存储原始选中的图像对象(后续会应用multiply效果) var originalItems = app.selection.slice(); app.menuActions.item("$ID/Copy").invoke(); var myProperties = { blendMode : BlendMode.MULTIPLY, opacity : 100 }; for (i=0; i<app.selection.length; i++) { try { app.selection[i].images[0].transparencySettings.blendingSettings.properties = myProperties; } catch(e){} } app.menuActions.item("$ID/Paste in Place").invoke(); // 存储刚粘贴的图像对象 var pastedItems = app.selection.slice(); for (j=0; j<app.selection.length; j++) { try { var myPathName = app.selection[j].images[0].clippingPath.photoshopPathNames; var myPath = app.selection[j].images[0].clippingPath; function working() { for (var i = 0; i < myPathName.length; i++) { if (myPathName[i] === "X") { myPath.appliedPathName = myPathName[i]; alert ("X path activated"); return i; } else if (myPathName[i] === "FCP") { myPath.appliedPathName = myPathName[i]; alert ("FCP path activated"); return i; } else if (myPathName[i] === "x") { myPath.appliedPathName = myPathName[i]; alert ("x path activated"); return i; } } alert ("No valid path exists"); } working(); } catch (e) {} } // 同时选中两组对象并编组 if (originalItems.length === pastedItems.length) { app.selection = originalItems.concat(pastedItems); app.activeDocument.groups.add(app.selection); // 脚本结束时选中刚粘贴的图像,符合原需求 app.selection = pastedItems; }
注:原有代码中循环处理粘贴对象时原本固定取
app.selection[0],已调整为app.selection[j]适配多选场景,不影响单选使用。
内容的提问来源于stack exchange,提问作者hellobobbysouza
相关产品推荐
相关产品推荐

