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

Using ImagestoCSV104.jsx

Enthusiast ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

For years now I've used this script to create photo albums, but lately have been having problems with it on two of my three computers. Here's how it works. 

 

Run the script - point it to a directory and it will create a csv file with a list of images in that directory. But the images are out of order in the csv file, so I open it in Open office, sort the rows A-Z, save and close. Then go to the data merge menu in ID, select that csv file as the data source, and ID will create a page for each image, giving me a photo album that I then save as a PDF or ebook. 

 

Problem is, I'm starting to get this error, and can't figure it out. The Data Merge stops, and I get an error sayiing "data missing or some rows are empty". But on one computer it still works. No idea why that one works and the others don't. But I need to find a solution. 

 

Does anyone else use this? Any ideas on what's causing that error? ID 2024 and ID 2025 give the same error. 

TOPICS
Scripting

Views

271

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
community guidelines

correct answers 1 Correct answer

Enthusiast , Nov 05, 2024 Nov 05, 2024

Robert

thanks very much. You were close but I kept getting a javascript error. So I ran it through ChatGPT and it gave me the correct answer, and now I get a csv file that's already sorted. 

 

Screenshot 2024-11-05 at 3.18.28 PM.png

Votes

Translate

Translate
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

Tell us about your different computers. What OS on each? What version of ID on each?

Mike Witherell

Votes

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
community guidelines
Enthusiast ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

The computer on which it works is a Mac Studio Pro running Ventura 13.4.x and running now ID 2025 (just updated it moments ago), and even on the new ID, it works. On one of the machines where it does not work, it is a Mac Pro laptop M1, running ID 2024. On another machine where it doesn't work, I'm using Windows 10 and ID 2024. 

 

That's what I can't figure out. On the laptop, for example, when I try and run the Data Merge, I get the error, but on the Mac Studio Pro, with the same OS, Same OS version, same ID version and same Open office, I get the error. On a windows machine I also get the same error. 

 

The error occurs when I sort the data. If I don't sort the data in Open Office, I can run data merge and it's fine, but of course it's out of order. I know it's odd. I can't see what's causing it to think there's an empty data on two machines but not the other. 

Votes

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
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

@bellevue scott

 

Then it looks like something is wrong with Open Office - not InDesign? 

 

Votes

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
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

quote

The computer on which it works is a Mac Studio Pro running Ventura 13.4.x


By @bellevue scott

 

Before anything else, update your Ventura to the latest version. You can run into all kinds of issues on anything before 13.5 (although not necessarily related to your problem).

Votes

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
community guidelines
Explorer ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

The computer on which it works is running ventura. So ventura is not the problem. I'm always one OS behind for very good reasons. Apple always introduces new problems with every single OS. But rgardless, the computer on which it does work is running ventura. So no, I won't do this. I think I'll try the Imagecatalog script suggested below. Thanks. 

Votes

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
community guidelines
Community Expert ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

quote

The computer on which it works is running ventura. So ventura is not the problem. I'm always one OS behind for very good reasons. Apple always introduces new problems with every single OS. But rgardless, the computer on which it does work is running ventura. So no, I won't do this.

By @Scott_BFAR

 

I understand your policy. I also understand that your script works there, and that's what's most important for your question. Although you said that you get the error "with the same OS, Same OS version" so I'm not sure what OS you're using where as you don't mention any other macOS versions.

 

However, in this particular case, the issues of InDesign problems on pre-13.5 versions of Ventura are widely documented, and there were countless discussions on the forum about it back then. In particular, many users weren't able to launch InDesign at all. Just keep it in mind if you ever run into this issue.

Votes

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
community guidelines
Enthusiast ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

Thanks Leo. Didn't know that ID had issues with pre 13.5 versions of Ventura, but that's not surprising. 

Votes

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
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

@bellevue scott

 

Have you tried included ImageCatalog script?

 

Votes

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
community guidelines
Enthusiast ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

No but I'm willing. Is that part of ID already?

Votes

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
community guidelines
Community Expert ,
Oct 31, 2024 Oct 31, 2024

Copy link to clipboard

Copied

quote

No but I'm willing. Is that part of ID already?


By @bellevue scott

 

Yes, it's included for free with InDesign. 

 

Votes

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
community guidelines
Enthusiast ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

Posting as a top level comment. Here's what I've found.

Upgraded one of my Macs to Sequoia 15.1 and In Design to 2025 (ver 20.0) problem still persisted. 

 

What I ultimately found was that the version of Open Office was the culprit. I have found that version 4.1.14 works with this script. Mac's numbers program does not. I don't know if a paid version of Office 365 would work or not. 

 

This step is important, because otherwise the images are not imported in order. For this to work, you run the script, which creates a csv file. You open that file, and sort it, and then go to the data merge window in In Design, select the csv file and do the data merge, and your images will get imported in the correct order. 

 

I had forgotten about about the ImageCatalo.jsx script that's included with InDesign, and I had forgotten why it doesn't work. It reformats the pages, which is a problem, but more importantly, it imports the images in a random order. This is where creating the csv file and sorting it comes in. I need these images to get imported in the correct order, and ImagestoCSV104.jsx does this. 

 

The versions of Open Office that didn't work were 4.1.3. And again, I don't know if MS Office will sort the file without adding whatever was causing the errors, but OpenOffice 4.1.14 does appear to work. 

Votes

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
community guidelines
Community Expert ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

@bellevue scott 

 

Glad you found the culprit - pretty much what I've suggested yesterday.

 

Also, I'm sure you don't have to do this workaround with Open Office to sort things - it can be done in JavaScript. 

 

array.sort();

Votes

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
community guidelines
Enthusiast ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

Where might I put that array.sort(); ?

 

Array.prototype.inArray = function(obj){ var arrMax = this.length-1; for(var i=arrMax; i>=0; i--){ if(this[i]===obj){ return true; } } return false; } var csvParser = (function(){ var csvFile; return{ create:function(fo){ csvFile=File(fo+"/"+fo.name+".csv"); }, write:function(csvContent){ csvFile.open('w'); csvFile.encoding="UTF-8"; csvFile.write(csvContent); csvFile.close(); }, execute:function(){ csvFile.execute(); }, getCSV:function(){ return csvFile; } } })(); function imagesToCSVthenChoose(){ var doc, fo, fis, fiMax, fi, fiName, fiPath, imgFormats=["eps","jpg","tif","psd","pdf","png","ai","bmp","jpeg"], imgFormatMax = imgFormats.length-1, imgOk = [], csvContent = [], ext, csvLine=[], csvSep=","; if(app.documents.length==0){ alert("No documents open !"); return } doc=app.activeDocument; fo = Folder.selectDialog("Please choose a folder with images"); if(!fo) return fis = fo.getFiles(); fiMax=fis.length; for(var i=0; i<fiMax; i++){ fi=fis[i]; ext = fi.name.match(/\.([a-z]+)$/i); if(ext==null) continue; ext = ext[1].toLowerCase(); if(!imgFormats.inArray(ext)) continue; fiName = decodeURI(fi.name); fiPath=decodeURI(fi.fsName); csvContent.push(fiName+csvSep+fiPath); } csvContent = "Name"+csvSep+"@images\r"+csvContent.join("\r"); csvParser.create(fo); csvParser.write(csvContent); /* doc.dataMergeProperties.selectDataSource(csvParser.getCSV()); var myMenuAction = app.menuActions.item("$ID/DataMergePanelName"); myMenuAction.invoke(); */ } array.sort(); imagesToCSVthenChoose();

Votes

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
community guidelines
Community Expert ,
Nov 01, 2024 Nov 01, 2024

Copy link to clipboard

Copied

Before marked part:

 

RobertatIDTasker_0-1730508025351.png

 

 

csvContent.sort();

 

 

So you should have something like this:

 

 

csvContent = "Name"+csvSep+"@images\r"+csvContent.join("\r"); csvContent.sort(); csvParser.create(fo);

 

 

Votes

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
community guidelines
Enthusiast ,
Nov 05, 2024 Nov 05, 2024

Copy link to clipboard

Copied

LATEST

Robert

thanks very much. You were close but I kept getting a javascript error. So I ran it through ChatGPT and it gave me the correct answer, and now I get a csv file that's already sorted. 

 

Screenshot 2024-11-05 at 3.18.28 PM.png

Votes

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
community guidelines