Skip to main content
Known Participant
October 10, 2020
Answered

error 55 object does not support the property or method 'paths'

  • October 10, 2020
  • 4 replies
  • 2245 views

hi!

I want to insert an image into a rectangle made of JavaScript fan tools.

 

var i = 0;
for (var p = 1; p <= myPages.length - 1; p++) {
for (var n = 1; n <= 1; n++) {
  if (i <= myOutGroupPics1.length - 1) {
     myPages[p].pahts -> What should I change this place to?
    .item("myOutGroup" + n)
    .place(File(myOutGroupFolder1 + "/" + myOutGroupPics1[i].name));
    i++;
   }
 }
}

This topic has been closed for replies.
Correct answer Manan Joshi

Hi @cafefatbear 

It seems this thread is also related to the one we discussed here, if it is then I suppose you have your answer, and if you say I can merge this thread with the other one.

-Manan

4 replies

rob day
Community Expert
Community Expert
March 8, 2024

Hi @cafefatbear , Not sure if this helps, but you don’t need to construct a a frame for the images, if you place them directly on the page their parent would be a container frame with the same bounds.

 

So you could simplify and add pages as needed (when .isValid returns as false). Something like this:

 

var f = Folder.selectDialog("Select the folder containing the images", ""); 
if(f != null){ 
    var fl = f.getFiles(/\.(jpg|jpeg|eps|pdf|png|indd|tif|gif|psd|ai)$/i); 
}

//the script’s measurement unit
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
var p, img, tf;
for (var i = 0; i < fl.length; i++){
    //add a page if needed
    if (doc.pages[i].isValid) {
        p = doc.pages[i]
    } else {
        p = doc.pages.add()
    }
    //place the image on the page—the image’s container frame would be img[0].parent
    img = p.place(fl[i]);
    //make a text frame below the image with the file name as contents
    tf = p.textFrames.add({geometricBounds:[img[0].geometricBounds[2], 
        img[0].geometricBounds[1], 
        img[0].geometricBounds[2] + 20, 
        img[0].geometricBounds[3]], 
        contents:fl[i].name})
};   

//reset
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
Robert at ID-Tasker
Legend
March 8, 2024

@rob day 

 

This thread is 4 years old - you should take a look at @jeroen358946423v9n's posts.

 

Participant
March 6, 2024

Hello i do not know where to put my question but I also got an error 55. In the below script for automating import images from a folder to pages in indesign i have this line "var page = doc.pages[pageNumber - 1]; "

in my code that gives me an error. my .csv has 2 columns. one with titles and one with numbers 1 till 7

 

Kind regards jeroen

 

 

var csvFilePath = "datasheet.csv";
var imageFolderPath = "OUTPUTFOLDER";

var csvFile = File(csvFilePath);
csvFile.open("r");
var csvData = csvFile.read();
csvFile.close();

var csvRows = csvData.split("\n");

for (var i = 0; i < csvRows.length; i++) {
var rowData = csvRows[i].split(","); 

var fileName = rowData[0]; 
var pageNumber = parseInt(rowData[1]); 

var doc = app.activeDocument;
var page = doc.pages[pageNumber - 1]; 
var imageFile = File(imageFolderPath + "/" + fileName);

if (imageFile.exists) {
var imageFrame = page.rectangles.add(); 
imageFrame.place(imageFile); 
imageFrame.fit(FitOptions.PROPORTIONALLY); 

var textFrame = page.textFrames.add();
textFrame.contents = fileName;
textFrame.geometricBounds = [imageFrame.geometricBounds[2], imageFrame.geometricBounds[1], imageFrame.geometricBounds[2] + 20, imageFrame.geometricBounds[3]];
} else {
alert("Image not found: " + fileName);
}
}

Robert at ID-Tasker
Legend
March 6, 2024

@jeroen358946423v9n

 

Your code isn't checking if there is enough pages in the document.

 

You would have to add check if number of pages in the document is larger or equal to pageNumber and add pages if not - or set number of pages in the document's properties. 

 

Participant
March 7, 2024

Dear Robert Tkaczyk thank you for your answer. Not sure if i understand it but i tried to add this: " while (doc.pages.length < pageNumber) {
doc.pages.add(); " However that failed so now i try to get a workaround that simply indesign puts from a folder automatically withouth a .csv file. 

 

I made the below, but i get no message whatever from indesign. not a fault code nor action that takes place.

the folder is just on my desktop and made path to the folder with images exact, not relative.

 

Thanks in advance for your answer, jeroen

 


var imageFolderPath = new Folder("/C:/Users/xxxx/Documents/Afbeeldingen");

var imageFiles = imageFolderPath.getFiles();


var doc = app.activeDocument;for (var i = 0; i < imageFiles.length; i++) {
var imageFile = imageFiles[i];while (doc.pages.length < i + 1) {
doc.pages.add(); 
}

var page = doc.pages[i]; 

if (imageFile.exists) {
var imageFrame = page.rectangles.add(); 
imageFrame.place(imageFile); 
imageFrame.fit(FitOptions.PROPORTIONALLY);

var textFrame = page.textFrames.add();
textFrame.contents = imageFile.name;
textFrame.geometricBounds = [imageFrame.geometricBounds[2], imageFrame.geometricBounds[1], imageFrame.geometricBounds[2] + 20, imageFrame.geometricBounds[3]];
} else {
alert("Afbeelding niet gevonden: " + imageFile.name);
}
}

Manan JoshiCommunity ExpertCorrect answer
Community Expert
October 13, 2020

Hi @cafefatbear 

It seems this thread is also related to the one we discussed here, if it is then I suppose you have your answer, and if you say I can merge this thread with the other one.

-Manan

-Manan
Sunil Yadav
Legend
October 10, 2020

I am unsure what you are storing in myOutGroupPics1.

Just to place an Image file into an already made rectangle you can do this like this:

var myImagFile = File("~/Desktop/Untitled.png");
var myRectangle = app.documents[0].pages[0].rectangles[0];
myRectangle.place(myImagFile);
myRectangle.fit(FitOptions.CONTENT_TO_FRAME);

Best

Sunil