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

How to Set Alignment in Script

Participant ,
Jul 26, 2021 Jul 26, 2021

Here is First Image, Each layer is different place i want to set alignment each layer "Second Image" in script, 

01.JPG02.JPG

TOPICS
Actions and scripting
3.4K
Translate
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
Adobe
Community Expert ,
Jul 26, 2021 Jul 26, 2021

The trouble I see is letting the script know which layer is going to be put in which order? How do you let the script know how many columns or rows?  

Translate
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
Participant ,
Jul 27, 2021 Jul 27, 2021

It Depends on only row,

1:- Select All Layer

2:- To Set the Aligment Row Wise in script

Translate
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
Participant ,
Jul 27, 2021 Jul 27, 2021

@r-bin  Could you solve it 

Translate
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 27, 2021 Jul 27, 2021

Again, how are you going to let the script know how many columns and rows?  Your first screen shot shows rectangles all over the canvas. You second screenshot shows 2 columns and 4 rows. How is the script to know you want 4 rows and not 3? You said to select all the layers. Which order do they go in in the aligned image: first and second layers in the first row or in the first column? The mechanics of aligning is fairly simple, but first you have to decide what order the layers are placed in the aligned image.

Translate
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
Participant ,
Jul 28, 2021 Jul 28, 2021

Could you modify the script ,In this script Just copy a Layer No. Of Rows And No. Of Colums, But I want Select All Layer And Set the alignment ??

1:- Select All Layer

2:- Set the Alignment //According Row and column in script

var rows = 2;
var clms = 2;

var gap_h = UnitValue(1, "mm");
var gap_v = UnitValue(2, "mm");

var layer0 = activeDocument.activeLayer;

var dx = layer0.bounds[2]-layer0.bounds[0] + gap_h.as(layer0.bounds[0].type);
var dy = layer0.bounds[3]-layer0.bounds[1] + gap_v.as(layer0.bounds[0].type);

for (var r = 0; r < rows; r++)
    {
    for (var c = 0; c < clms; c++)
        {
        if (!r && !c) continue;

        var layer1 = layer0.duplicate();
        
        layer1.translate(dx*c, dy*r);
        }
    }
Translate
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
Participant ,
Jul 28, 2021 Jul 28, 2021

@Chuck Uebele  Check it

Translate
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 28, 2021 Jul 28, 2021

Normally if you want images layout on a canvas sized to a particular aspect ratio size and shape.  You create a Photo Collage template that you them populate with your various images.  If you keep the collage template you can write various scripts to populate a template various ways,  interactively, automatically and even batch populate them. The script could even add file name stamps on the image and style the text and image layers.  The script need to have some way to know where images are, their size, their shape and order.    Alpha channel could be used to map  up to a 53 image for a collage template. You design you layout then populate.  Keep the template simple so you can automate their modulation.  You could even prototype a layout manually with 6 images like you have on a canvas. Lay them out the images either way you show. Then create collage templates automatically with a script that create Photo collage templates.  It is what I did.

Free Photoshop Photo Collage and mockup Toolkit 

 

 

Do all the layers have the same layers bounds.  When tiles will they fit on canvas or does the script  add canvas.  How are you going to  communicate with the script to set  rows  column, spacing, margins etc.  What have you coded so far.

 

You may want to look at my Paste Image Roll script to get some ideas for scripting what you want. Paste Image Roll

JJMack
Translate
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
Participant ,
Sep 08, 2021 Sep 08, 2021

Did't not work for me @JJMack 

Please check the script ?

			var copies=2;
            var pasted=0
            		var width=4;
                    var height=4;
                    var whitespace=10;
                    var borderspace=10;
                    var currrow=0;
                    var cols=2;
                    var rows=2;
                    var res=300;
                    // Document Cell width in pixels inches*res
                    var doc = app.documents.add((width+whitespace)*cols-whitespace+2*borderspace, (height+whitespace)*rows-whitespace+2*borderspace, res);

    
    for (var n=0;n<copies;n++) {					// number of copies				
				var x =pasted*(width+whitespace)+borderspace;
				var y =currrow*(height+whitespace)+borderspace;
				var selectedRegion = Array(Array(x,y), Array(x+width,y), Array(x+width,y+height), Array(x,y+height));
				doc.selection.select(selectedRegion);
				//doc.paste(true); 							//paste image into masked layer your document
			//	doc.activeLayer.name=imageName;				//label layer with image file name
				doc.selection.select(selectedRegion);
				align('AdCH'); align('AdCV');
				doc.selection.deselect();
				pasted++
                }
    
    function align(method) {
        app.activeDocument.selection.selectAll();
	var desc = new ActionDescriptor();
	var ref = new ActionReference();
	ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
	desc.putReference( charIDToTypeID( "null" ), ref );
	desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
	try{
		executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
	}catch(e){}
       app.activeDocument.selection.deselect();
}
Translate
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 ,
Sep 08, 2021 Sep 08, 2021

It look like you look at my script and tried to extract some code but missed some important things and dropped out code. and wound up creating a script the may create a small new document and may fail to align the background to a selection.  The background layer does not support transparency its contents can not be repositioned. You do not seem to understand what is going on.

JJMack
Translate
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
Participant ,
Sep 08, 2021 Sep 08, 2021

I have tired for this, @JJMack 

Step 1:- Select All Layer

Step 2:- Set the Alignment According Row

 

Just One thing is needed ?

Translate
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 ,
Sep 08, 2021 Sep 08, 2021

What layers? I did  not even try your script it does not add layer that can be aligned. The document would have more white space the content.  4px by 4px tiles with 10px white space around them. I'll run it not.

Capture.jpg

It worked like I read the code. It creade a document with a white backgrond layer 38 px by 38 px.  No layer were added

JJMack
Translate
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
Participant ,
Sep 08, 2021 Sep 08, 2021

Please try to understand my question ?

I have asked , I have 5shape Layers in a document i want to set the alignment all selected layer like above the image 

Translate
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 ,
Sep 08, 2021 Sep 08, 2021

You seem to want other to work for you. You want then to design and code photoshop scripts for you.   These forum are made available by Adobe funding, staffing  and maintaining this site. The Site is provided by Adobe  so Adobe user can help  each others out  with using Adobe Products. How to use Products, How approach different types of work. How to resolve problems.  How get around Adobe issues etc.  

 

The I have no problem understanding your question.   I also have no intention of working for you.  I know you want to align layers.  Photoshop has features to for that I do it all the time. So I point you to one of my script that Align layers to selections.  A standard Photoshop feature.  Simple Action Manager code made into a javascript function.  It Simple to use. Yet you changed it to align to the document's canvas.  You also did things in Pixel units not in inches like I did by multiplying by resolution..  You need to learn to read and understand javascript code better then you now do.   I do not know JavaScript but I can read most Photoshop javascript scripts code and make some sense of what is going on and can hack at the code.  I find some code written by Javsscript experts hard to follow because of the advance programming style they employ.  It hard for be to decipher what some of their code does.    If I write the script you want for you learn nothing and it is a lot of work for me because I can not type. I hunt and peck and hit many wrong keys.  If I have code that does tings similar to want you want to do I can easily point you at that code. IMO you need to improve your ability to read Photoshop scripts written JavaScript code and learn how to adapt and modify code to do the processing you want to do.  I'm not going to design and code a custom script for you. That is your job.  If you can not hack it pay someone to work for you.

 

Now you state you have shape layers so again will  ask  are all shape layer the same size, When tiled will they fit on canvas.  How do you want  them spaced, You need toe address the questions put to you.  There thing you need to address in your script.

JJMack
Translate
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
Participant ,
Sep 08, 2021 Sep 08, 2021
LATEST

Thanku so much @JJMack  You have alredy understood my question I want to align layers..

I will try this

Translate
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