• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Create new doc from selection using script.

Engaged ,
Jul 07, 2019 Jul 07, 2019

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

TOPICS
Actions and scripting

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jul 07, 2019 Jul 07, 2019

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);

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

The selection itself –

or the contents of the selection?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 07, 2019 Jul 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2019 Jul 07, 2019

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 07, 2019 Jul 07, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 07, 2019 Jul 07, 2019

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;  

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 07, 2019 Jul 07, 2019

Copy link to clipboard

Copied

LATEST

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines