Copy link to clipboard
Copied
Hi,
I created a script which generate predefined section of an image, each section on a separate layer.
Now I need to cycle those layers, select each and copy to a new image.
I searched this forum and others and the related methods i found, do not work, probably the code does not fir any longer.
My question:
Once I have a selection, how do I copy the selection to a new document with the same settings as the current doc?
Thanks,
Dan
I got it thanks to this: Photoshop Script Crop Resizes Image, Does Not Crop
and I used this:
var bounds = [splitSize.x0,splitSize.y0,splitSize.x1,splitSize.y1];
app.activeDocument.crop(bounds);
Copy link to clipboard
Copied
The selection itself –
or the contents of the selection?
Copy link to clipboard
Copied
say i have 3 layers: split_1 split_2 & ims2split.
split_1&2 are above img2split and they are a rectangle shape layer.
I select, e.g. split_1 shape using:
function selectSplitByLayerName(lName){
var x0;
var x1;
var y0;
var y1;
//select lName layer
//app.activeDocument.activeLayer = app.activeDocument.layers.itemByName(lName);
app.activeDocument.activeLayer = app.activeDocument.artLayers.getByName(lName);
var layer = app.activeDocument.activeLayer;
// Calculate length and width based on the rectangular bounds of the selected layer
x0 = layer.bounds[0].value;
y0 = layer.bounds[1].value;
x1 = layer.bounds[2].value;
y1 = layer.bounds[3].value;
var shapeRef = [ [x0,y0], [x0,y1], [x1,y1], [x1,y0] ];
var sel=app.activeDocument.selection.select(shapeRef);
return sel;
}
once i have the selection i make img2split active.
And now i want to copy only the selected content of img2split content, same as CTRL+J
Copy link to clipboard
Copied
Ctrl+j is like copy a layer selection to the Clipboard then Paste it into the dociment. Ctrl+C Ctrl+V you could also do a Copy Merge Paste. Shift+Ctrl+C Ctrl+V. You can do the same in a script copy from one document and paste into a second document. If yoy want in in a new document create a new document Clipboard size before the paste.
Copy link to clipboard
Copied
I would use scriptListener to generate some action manager code:
Once you make you selection you can copy it, the use AM code to open a new document that is sized to the clipboard contents. Then past into the new document.
You could also use ctrl-J to create a new layer then record using alt-click to turn all the other layers' visibility off, then create a copy of the document and use, merge visible.
Copy link to clipboard
Copied
Thank you all,
i guess there is no strait command for it.
so i think i will duplicate the entire doc and delete the redundant layers and then crop to the selection size.
I tried using the below but the crop is not working.
what should i set it to work properly to fir the cropped image to the selection?
var splitSize = getSelectionSize(sel)
app.activeDocument.crop(x0,y0,width,height]);
where the parameters come from here:
function getSelectionSize(sel){
var size = new Object();
var x0;
var x1;
var y0;
var y1;
x0 = sel.bounds[0].value;
y0 = sel.bounds[1].value;
x1 = sel.bounds[2].value;
y1 = sel.bounds[3].value;
size.x0 = x0;
size.y0 = y0;
size.x1 = x1;
size.y1 = y1;
size.width = x1-x0;
size.height = y1-y0;
return size;
}
Copy link to clipboard
Copied
I got it thanks to this: Photoshop Script Crop Resizes Image, Does Not Crop
and I used this:
var bounds = [splitSize.x0,splitSize.y0,splitSize.x1,splitSize.y1];
app.activeDocument.crop(bounds);