Skip to main content
Inspiring
Dec 20, 2023 9:37 PM UTC
Answered

UXP Script InDesign Remove Labels

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 is closed to new replies. Start a new post to keep the conversation going.
luis_guimaraesCorrect answer
Participating Frequently
Nov 25, 2024 1:08 PM UTC

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

11 replies

Participating Frequently
Nov 25, 2024 11:32 AM UTC

In ExtendScript/jsx you could use 

extractAllLabels()
Translate
Peter Kahrel
Community Expert
Community Expert
Nov 25, 2024 11:43 AM UTC

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

Translate
Participating Frequently
Nov 25, 2024 12:04 PM UTC

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.

Translate
Peter Kahrel
Community Expert
Community Expert
Dec 21, 2023 2:56 PM UTC

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.

 

 

 

Translate
Inspiring
Dec 21, 2023 5:16 PM UTC

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);
        };
    }
}
Translate
brian_p_dts
Community Expert
Community Expert
Dec 20, 2023 9:44 PM UTC

Just set the cell.label to ""

Translate
Inspiring
Dec 20, 2023 9:47 PM UTC

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?

Translate
brian_p_dts
Community Expert
Community Expert
Dec 20, 2023 10:13 PM UTC

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?

Translate