Reputation: 105
I want create new layer with image in it. I didn't find anything useful or correct answer for this question.
What I'm doing now is:
var oldActive = app.activeDocument;
app.load(new File(path)); //load it into documents
var tempDoc = app.activeDocument;
// backFile.resizeImage(width, height); //resize image into given size i.e 640x480
tempDoc.selection.selectAll();
tempDoc.selection.copy(); //copy image into clipboard
tempDoc.close(SaveOptions.DONOTSAVECHANGES); //close image without saving changes
oldActive.paste(); //paste selection into your document
Code above opens new document/tab and doing simple logic, then closes new document and brings me back to the old one and pastes image what I need.
I don't like this approach because user can see how documents blinking/opens/closes.
I'm looking for a simple way which allows insert image into current active Document without opening new ones.
Upvotes: 0
Views: 1948
Reputation: 105
Ok guys. So this is correct way to paste image by path into current activeDocument without opening new ones:
var sourceFile= new File(path);
var idPlc = charIDToTypeID( "Plc " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc3.putPath( idnull, sourceFile);
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3.putEnumerated( idFTcs, idQCSt, idQcsa );
executeAction( idPlc, desc3, DialogModes.NO );
Upvotes: 4