Skip to main content
New Participant
January 24, 2023
Question

Data Merge + Object Styles. Possible? Or workaround with Script?

  • January 24, 2023
  • 5 replies
  • 4109 views

PART ONE: Data Merge capabilities

I have a couple thousand records in a spreadsheet I'm using to create signs. Name, description, picture, fine print, etc. One of the identifiers on each sign is a colored border to visually indicate which one of five categories the sign belongs in. There are two identical signs on each page.

 

Is it possible to specify a value in the Data Merge source file that would set the value of a specific object's border, whether specifiying in the spreadsheet "green", "C=75 M=0 Y=100 K=10", or some other HSB/HEX/LAB color?  

 

My guess is no, since Data Merge is basically to pull info IN, not to set values within a doc. I realize I could create an image for each of the border colors and specify the path in the Data Merge, but I'd really rather avoid that route. It makes the spreadsheet pretty clunky.  Which leads me to...

 

PART TWO: Solving by script

If the border color can't be set during the Data Merge, my next thought was to create a script. I could include an invisible/non-printing text box to hold an imported a string value when the data merge happens (Green, Red, Orange, etc.)  Write a script that would read the value on each page and set the two border objects on that page to the corresponding already-defined object style.  Step and repeat for all the pages in the generated document.

 

I've checked out several similar threads (Here and here from 2018, and this one from 2021) which leads me to believe it's possible. Unfortunately I'm not much of a code-person. While I've downloaded VS Code, I'm struggling to piece something together because... well, I'm not a coding savant.

 

Anyone care to help?

This topic has been closed for replies.

5 replies

New Participant
January 31, 2024

I wasn't able to get the script @M.Hasanin (so very kindly!) provided when I originally posted. Due to a time crunch, I solved last year  by clunkily using an image file/path.  But this is a task I have to revisit every year.  Here are some additional images to how I've set up the document based on the feedback I've received from this thread.  As you can see, I have multiple text boxes and I only want one of them to have the frame style applied.

 

I imagine I need to somehow "name" the text/graphic box I'm trying to apply the border to.  I know I can do that with Interactive > Buttons & Forms, then setting my desired text/graphic box to Type: text field so I can set Name:[my name]... but I'm not sure if DataMerge will interact with Buttons & Forms.

 

Suggestions appreciated. (And holy cow! @Loic.Aigon wasn't kidding about what amazing things Colin Flashman has done. If you're picking up this thread long after it's gone silent, def see if https://colecandoo.com/ is still around and maybe it'll give you ideas/hope too.)

Robert at ID-Tasker
Brainiac
January 31, 2024

But it looks like this object is part of your template - can't you just apply ObjectStyle from the start?

 

And if you want to "name" object for futere use in scripts - you should use "label" - Windows > Utilities > Scripting Label. 

 

New Participant
January 31, 2024

 

 

In my Excel file (::CSV) I have thousands of entries, each with one of five color designations. Because they're different, I'm trying to apply the appropriate object style (frame color) during the data merge.  In all, I have tens of thousands of line items which have already been split across six Excel files. Splitting them further would complicate the workflow.

M.Hasanin
Inspiring
January 26, 2023

Hi @Plant Girl 

i think this script will do the trick :

 

//Apply Object Style to TextFrame Based on Content
app.doScript(ApplyOSTextFrames, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Apply Object Style Based on Content");

function ApplyOSTextFrames(){    
      var myDoc = app.documents[0];
      var myFrames = myDoc.textFrames.everyItem().getElements();
            for (var n = 0; n < myFrames.length; n++) {      
                myFrames[n].applyObjectStyle(myDoc.objectStyles.item(myFrames[n].contents));
    }
}

 

just make sure that object style names the same of text frame contents :

Object Style Palette

See in Action!:

BestMohammad Hasanin
New Participant
February 1, 2023

Is there a way to remove the "color-words" from the boxes after the object style has been applied?

Robert at ID-Tasker
Brainiac
January 31, 2024

Hi, first of all, thank you for your script. I understand it, but I'm being not able to use it. 

Whenever I run it, it returns an error: unvalid value for parameter 'using' of method 'applyObjectStyle', expected ObjectStyle, but received nothing. It is as if there weren't any object styles created 😞


Are you sure the ObjectStyle you want to apply - exists in your document? 

 

Those scripts expect ObjectStyles to already exist in your document - they do not create them beforehand. 

 

Loic.Aigon
Brainiac
January 24, 2023

Did you know about Colecandoo website. The guy deeply twisted datamerge's arm and shows how to achieve what seems often non accessible with datamerge: https://colecandoo.com/2011/10/16/power-merging-adding-bar-graphs-and-changing-formats-in-data-merge/

Maybe you can find some hint there.

Loic

Brainiac
January 24, 2023
quote

I realize I could create an image for each of the border colors and specify the path in the Data Merge, but I'd really rather avoid that route. It makes the spreadsheet pretty clunky. 

 

 

You can avoid having to put full paths in the spreadsheet if you put the images in the same folder as the data file. In that case, the field only needs to contain the name of the image file.
 

Mike Witherell
Adobe Expert
January 24, 2023

Datamerge can pull text data from a simple spreadsheet and it can also pull images from the images column of a spreadsheet. That being the case, you could make an artfile for just the background border (like an .AI file) and the datamerge would put in the right color for the background border.

https://helpx.adobe.com/indesign/using/data-merge.html#about_data_source_files

There is a subsection about how to put an @971902 in the column header for the filenames.

Mike Witherell