Skip to main content
Inspiring
December 20, 2023
Answered

UXP Script InDesign Remove Labels

  • December 20, 2023
  • 3 replies
  • 1339 views

Hello, 

 

I am looking for a UXP scripting solution that would allow me to remove all labels from a cell in a table that I have created in Adobe Indesign. I am currently using the insertLabel() function for cell to insert any information that I want attached to a cell, and I am extracting that information using extactLabel(). However, there is a use case where I may want to remove the contents of the cell, and with that all the labels associated with it. However, I do not see a way of doing this without knowing each individual key of every inserted label. This will require a lot of manual checks for labels, which is not practical or extensible. Is there a developer friendly solution for this? 

Another idea I had was removing the cell all together and reinserting the cell in the same index. However, this also seems to be tricky, and I am not sure if UXP has a way of cell insertion in a table. All I see is cell.remove()

Please let me know if you can think of anything,

Mahmood

This topic has been closed for replies.
Correct answer luis_guimaraes

I was exactly that, I found the solution I used then. Extracting from the XML. I simply had it tweaked and renamed to ExtractAllLabels().

https://community.adobe.com/t5/indesign-discussions/is-there-a-way-to-retrieve-all-labels-inserted-in-an-object/m-p/3847233#M241725

3 replies

Participating Frequently
November 25, 2024

In ExtendScript/jsx you could use 

extractAllLabels()
Peter Kahrel
Community Expert
Community Expert
November 25, 2024

I don't see the extractAllLabels() function in the ES object model, @luis_guimaraes 

Participating Frequently
November 25, 2024

Then maybe I made that function but can't remember what went inside it.
I'm trying to contact my previous job to see if I can get the script.

Peter Kahrel
Community Expert
Community Expert
December 21, 2023

It's not possible to determine whether any labels were inserted at cells (or indeed at any ID object). You have to know the keys that were used. (There is a very convoluted way of extracting all key-value pairs from IDML.)

 

An alternative is to use the cell.label property that Brian mentioned. This is a single string, but you could insert a JSON string there or any kind of home-brewn key-property pairs string. You can later parse the labels, or to reset them all, using Brians cell.label = ''

 

removing the cell all together and reinserting the cell in the same ind

 

That's not possible. The only way to insert cells is to add a row or a column.

 

UXP uses virtually the same object model as ExtendScript. A few things were changed -- can't remember which, and it changes from time to time, UXP is still developing.

 

 

 

Inspiring
December 21, 2023

I ended up just making a loop and storing all of the keys in another file called labels. For those who are curious, see the following: 

const removeLabels = (inDesignElement) => {
    for (const key in labels){
        const labelValue = inDesignElement.extractLabel(labels[key]);
        if (labelValue !== ""){
            inDesignElement.insertLabel(labels[key], constants.EMPTY_STRING);
        };
    }
}
brian_p_dts
Community Expert
Community Expert
December 20, 2023

Just set the cell.label to ""

Inspiring
December 20, 2023

I don't think cell.label is a function, i see cell.insertLabel, which requries two parameters: a key and a value to insert. I know that the value to insert should be an empty string "" like you said. My issue comes from the key. Is there a way to set every key in a cell with "" without actually knowing each individual key and calling insertLabel for every label?

brian_p_dts
Community Expert
Community Expert
December 20, 2023

I'm not too deep into UXP, but cell.label is a property, not a methof, in JSX. So it would be cell.label = ""; 

Does that not work in UXP?