Highlighted

How to align images side by side via script?

Participant ,
Aug 20, 2020

Copy link to clipboard

Copied

Hey everone, 

 

I've a new challage and I'm wondering if it's possiable. 

First of all, I read data from excel sheet (images) and save it in variable (array) . Then i loop through the array and place the images. This is the code:

for (var s = 0; s <= tempArr2.length - 1; s++) {
				
var rect = doc.pages[pageIdx].textFrames.add({
									geometricBounds: arrayOfSize[counterFrame1]
								});
									rect.place(tempArr2[s])
									rect.fit(FitOptions.PROPORTIONALLY)
									rect.select(SelectionOptions.ADD_TO)
								

							}

 

And the final results looks like this; placinf the images llike a stack

img0.png

Anyhow, I want to place the images align to each other! are there any function can do that?

align like the below image;

img1.png

I'm using javascript.

And thanks all.

Topics

Activation billing and install, Bug, EPUB, Feature request, How to, Import and export, InCopy workflow, Performance, Print, Publish online, Scripting, SDK, Server developers, Sync and storage, Type

Views

69

Likes

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

How to align images side by side via script?

Participant ,
Aug 20, 2020

Copy link to clipboard

Copied

Hey everone, 

 

I've a new challage and I'm wondering if it's possiable. 

First of all, I read data from excel sheet (images) and save it in variable (array) . Then i loop through the array and place the images. This is the code:

for (var s = 0; s <= tempArr2.length - 1; s++) {
				
var rect = doc.pages[pageIdx].textFrames.add({
									geometricBounds: arrayOfSize[counterFrame1]
								});
									rect.place(tempArr2[s])
									rect.fit(FitOptions.PROPORTIONALLY)
									rect.select(SelectionOptions.ADD_TO)
								

							}

 

And the final results looks like this; placinf the images llike a stack

img0.png

Anyhow, I want to place the images align to each other! are there any function can do that?

align like the below image;

img1.png

I'm using javascript.

And thanks all.

Topics

Activation billing and install, Bug, EPUB, Feature request, How to, Import and export, InCopy workflow, Performance, Print, Publish online, Scripting, SDK, Server developers, Sync and storage, Type

Views

70

Likes

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
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

Hi,

You have to play with the geometricBounds, and calculate coordinates using page top, left and margins. Try following snippet. This is not exact answer to your question. But below script show how to draw textframes side by side (grid view). More handling needs to be required if page get full. I am not sure whether that is required by you or not. Give it a try

var doc = app.activeDocument;

var pageWidth = doc.pages[0].bounds[3] - doc.pages[0].bounds[1];
var pageMarginPreferences = doc.pages[0].marginPreferences;
var actualWidth = pageWidth - (pageMarginPreferences.left + pageMarginPreferences.right);

var x = pageMarginPreferences.right;
var y = pageMarginPreferences.top;
var width = 50;
var height = 100;

for (var s = 0; s <= 10; s++) {
    var rect = doc.pages[0].textFrames.add({
        geometricBounds: [y, x, (y + height), (x + width)]
    });
    // rect.place(tempArr2[s])
    // rect.fit(FitOptions.PROPORTIONALLY)
    // rect.select(SelectionOptions.ADD_TO);
    if((x+(width*2)) > actualWidth){
        x = pageMarginPreferences.right;
        y = y + height
    }else{
        x = x + width;
    }
}

I have commented your code for now where you are placing an image inside the frame just to show how frames can be aligned side by side. I hope this gives you an idea and you can implement those changes in your script.

Best regards

Likes

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
Reply
Loading...
rob day LATEST
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

If you want to make a matrix of frames you can use the modulus operator—%—

to create rows and columns. Here’s an example:

 

 

 

app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;
app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES;

//page and its bounds
var ap = app.activeDocument.pages[0]
var b = ap.bounds;

//number of columns and rows
var col = 3; var row = 4;

//the margin around the matrix
var mar = 1;

//space between the frames
var gut = .25

//the matrix width and height
var pw = (b[3]-b[1])-mar*2;
var ph = (b[2]-b[0])-mar*2;

//a tile’s width and height
var fw = ((pw+gut)/col)-gut;
var fh = ((ph+gut)/row)-gut;

//the starting x and y position
var xoff = mar;
var yoff = mar;

//make matrix
for (var i = 1; i < (col*row)+1; i++){
    ap.rectangles.add({geometricBounds:[yoff, xoff , yoff+fh, xoff+fw]});
    //place an image
    //ap.place(File("...image.psd"));
    //ap.fit(FitOptions)
    if (i % col > 0) {
        xoff = xoff + fw + gut;
    }else{
        xoff = mar;
        yoff = yoff + fh + gut;
    }
};   

 

 

 

 

Screen Shot 2.png

Likes

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
Reply
Loading...