Skip to main content
Known Participant
February 19, 2023
Answered

script to move content certain distance

  • February 19, 2023
  • 4 replies
  • 913 views

Hi 

I have an indesign file consists of 2500 pages resulted from data merge process , that file has images in graphic oval frame

I want a script that move content ( images ) certain distance like .1 cm Not moving the oval frame

Thanks in anvance

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer rob day

Hi Eugene, you don’t have to select the image in order to make the move—this might be a bit faster with a long document:

 

    var doc = app.activeDocument;
    var deltaX = 0.5;
    var deltaY = 0.5;
    var ag = doc.allGraphics
    for (var i = 0; i < ag.length; i++){
        if (ag[i].constructor.name == "Image" && ag[i].parent.constructor.name == "Oval") {
            ag[i].move(undefined, [deltaX, deltaY]);
        }
    };

4 replies

Known Participant
February 19, 2023

Nery Great Thanks For your Help

It works as a charm

Thank you

 

Community Expert
February 19, 2023

This script will find all graphics within oval frames and move it a specified amount
The line  bold is the move - if you want to move it sideways.

 

// Define variables
var doc = app.activeDocument;
var ovalFrames = doc.ovals;
var deltaX = 0.5;

// Loop through all oval frames
for (var i = 0; i < ovalFrames.length; i++) {
var ovalFrame = ovalFrames[i];

// Loop through all page items in oval frame
for (var j = 0; j < ovalFrame.allPageItems.length; j++) {
var pageItem = ovalFrame.allPageItems[j];

// Check if page item is an image
if (pageItem instanceof Image) {

// Select image and move it by deltaX
pageItem.select();
pageItem.move(undefined, [deltaX, 0]);
break; // Exit loop after selecting and moving first image
}
}
}

 

 

---------------

You could also add a prompt to insert the distance you want for x and y coords

// Define variables
var doc = app.activeDocument;
var ovalFrames = doc.ovals;

// Prompt user for X and Y distances
var deltaX = parseFloat(prompt("Enter X distance to move images by:", "0"));
var deltaY = parseFloat(prompt("Enter Y distance to move images by:", "0"));

// Loop through all oval frames
for (var i = 0; i < ovalFrames.length; i++) {
var ovalFrame = ovalFrames[i];

// Loop through all page items in oval frame
for (var j = 0; j < ovalFrame.allPageItems.length; j++) {
var pageItem = ovalFrame.allPageItems[j];

// Check if page item is an image
if (pageItem instanceof Image) {

// Select image and move it by deltaX and deltaY
pageItem.select();
pageItem.move(undefined, [deltaX, deltaY]);
break; // Exit loop after selecting and moving first image
}
}
}



rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
February 19, 2023

Hi Eugene, you don’t have to select the image in order to make the move—this might be a bit faster with a long document:

 

    var doc = app.activeDocument;
    var deltaX = 0.5;
    var deltaY = 0.5;
    var ag = doc.allGraphics
    for (var i = 0; i < ag.length; i++){
        if (ag[i].constructor.name == "Image" && ag[i].parent.constructor.name == "Oval") {
            ag[i].move(undefined, [deltaX, deltaY]);
        }
    };
Community Expert
February 19, 2023

Thanks for that - interesting!