Skip to main content
Inspiring
November 24, 2023
Answered

Images is not Visible

  • November 24, 2023
  • 1 reply
  • 216 views

Hi

 

I used the script to move the images from the top of the page to the bottom of the page. In that, I can't able to view the images placed at the bottom of the page. Please guide me on this...

 

 

var xOffset = 150;
var yOffset = 37.5;
var pageWidth = 480;
var pageHeight = 540;
var frameX = 60;
var frameY = 640;
var frameWidth = 50;
var frameHeight = 50;

var doc = app.activeDocument;
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;

// Iterate through each page
for (var pageIndex = 0; pageIndex < doc.pages.length; pageIndex++) {
    var page = doc.pages[pageIndex];
    var currentPageHeight = page.bounds[2] - page.bounds[1];

    // Check if the page contains text frames
    if (page.textFrames.length > 0) {
        // Iterate through each text frame on the page
        for (var frameIndex = 0; frameIndex < page.textFrames.length; frameIndex++) {
            var textFrame = page.textFrames[frameIndex];

            // Check if the text frame has the specified XML markup tag
            if (textFrame.associatedXMLElement && textFrame.associatedXMLElement.markupTag.name == 'family_name') {
                // Move the text frame to the bottom of the page
                // Move the text frame to the bottom of the page
textFrame.move([textFrame.geometricBounds[1], currentPageHeight - textFrame.geometricBounds[2]]);

                
                // Iterate through associated image frames
              // Iterate through each text frame on the page
for (var frameIndex = 0; frameIndex < page.textFrames.length; frameIndex++) {
    var textFrame = page.textFrames[frameIndex];

    // Check if the text frame has the specified XML markup tag
    if (textFrame.associatedXMLElement && textFrame.associatedXMLElement.markupTag.name == 'family_name') {
        // Move the text frame to the bottom of the page
        textFrame.move([textFrame.geometricBounds[1], currentPageHeight - textFrame.geometricBounds[2]]);
        
        // Iterate through associated image frames
        for (var itemIndex = 0; itemIndex < textFrame.parentPage.allPageItems.length; itemIndex++) {
            if (textFrame.parentPage.allPageItems[itemIndex] instanceof Image) {
                var imageFrame = textFrame.parentPage.allPageItems[itemIndex];
                imageFrame.visible = true;
                textFrame.visible = true;
                var imageFrameHeight = imageFrame.geometricBounds[2] - imageFrame.geometricBounds[0];
                var newY = currentPageHeight - imageFrameHeight - 100; // Adjust this value based on your layout
                var newX = imageFrame.geometricBounds[1];

                // Move the image frame to the specified position on the page
                if (newY >= page.bounds[1] && newY <= page.bounds[2]) {
                    imageFrame.move([newX, newY]);
                }
            }
        }
    }
}

            }
        }
    }
}

 

 

 

In the attached screenshot the text frame is at the top of the page but the image gets placed at the bottom of the page..

 

 

This topic has been closed for replies.
Correct answer Robert at ID-Tasker

Because your script moved image - contents of the frame / container - and not the frame / container. 

 

After this comment 

 

// Iterate through associated image frames 

 

You are iterating through allPageItems - which includes containers and their contents - so when you find image - you need to get its parent - and then move this parent. 

 

1 reply

Robert at ID-Tasker
Robert at ID-TaskerCorrect answer
Legend
November 24, 2023

Because your script moved image - contents of the frame / container - and not the frame / container. 

 

After this comment 

 

// Iterate through associated image frames 

 

You are iterating through allPageItems - which includes containers and their contents - so when you find image - you need to get its parent - and then move this parent.