嵌入式..通过photoshop脚本(Javascript) [英] Place Embedded.. through photoshop scripting (Javascript)

查看:109
本文介绍了嵌入式..通过photoshop脚本(Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究Photoshop脚本。

我正在尝试将image / psd / ai文件放入活动文档中。



我到目前为止最接近的是下面的代码,它在一个单独的文档中打开文件,将其复制并粘贴到最初活动的文档中。



但是,众所周知,复制和粘贴会对图层进行栅格化处理。



有没有办法呢?

(仅限Javascript)



谢谢



I'm currently researching on Photoshop scripting.
I'm trying to place an image/psd/ai file into an active document.

The closest I got to so far is the code below, which opens the file in a separate document, copies and pastes it into the originally active document.

However, as you all know copy and pasting rasterizes the layer.

Is there a way to do place it?
(Javascript only)

Thanks

var docRef = app.activeDocument;
file = app.openDialog();//opens dialog,choose one image

if(file[0]){ //if you have chosen an image
   app.load(file[0]); //load it into documents
   backFile= app.activeDocument; //prepare your image layer as active document
   backFile.resizeImage(200,200); //resize image into given size
   backFile.selection.selectAll();
   backFile.selection.copy(); //copy image into clipboard
   backFile.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes
   docRef.paste(); //paste selection into your document
   docRef.layers[0].name = "BackgroundImage"; //set your layer's name
}

推荐答案

解决了这个问题并将其放在这里供其他人使用。使用scriptListener来完成它。



目前使用 openDialog 进行文件选择,但是总是可以在变量<$ c中放置路径$ c> selectedFile 。



Solved this and put it up here for other people. Used a scriptListener to do it.

It currently uses openDialog for file selection, however one can always place a path in the variable selectedFile.

var idPlc = charIDToTypeID( "Plc " ); 
var desc11 = new ActionDescriptor();  
var idnull = charIDToTypeID( "null" );
 
var selectedFile = app.openDialog();
//opens dialog to select file

desc11.putPath( idnull, new File(selectedFile) );
var idFTcs = charIDToTypeID( "FTcs" ); 
var idQCSt = charIDToTypeID( "QCSt" );   
var idQcsa = charIDToTypeID( "Qcsa" ); 
desc11.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );     
var desc12 = new ActionDescriptor();     
var idHrzn = charIDToTypeID( "Hrzn" );    
var idPxl = charIDToTypeID( "#Pxl" );      
desc12.putUnitDouble( idHrzn, idPxl, 0.000000 );     
var idVrtc = charIDToTypeID( "Vrtc" );    
var idPxl = charIDToTypeID( "#Pxl" );    
desc12.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc11.putObject( idOfst, idOfst, desc12 );
executeAction( idPlc, desc11, DialogModes.NO );


这篇关于嵌入式..通过photoshop脚本(Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆