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

UXP Script InDesign Remove Labels

Explorer ,
Dec 20, 2023 Dec 20, 2023

Copy link to clipboard

Copied

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

TOPICS
Bug , How to , Print , Scripting , UXP Scripting

Views

523

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 3 Correct answers

Community Expert , Dec 21, 2023 Dec 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 = ''

 

...

Votes

Translate

Translate
Explorer , Dec 21, 2023 Dec 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);
        };
    }
}

Votes

Translate

Translate
Community Beginner , Nov 25, 2024 Nov 25, 2024

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

Votes

Translate

Translate
Community Expert ,
Dec 20, 2023 Dec 20, 2023

Copy link to clipboard

Copied

Just set the cell.label to ""

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 ,
Dec 20, 2023 Dec 20, 2023

Copy link to clipboard

Copied

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?

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 ,
Dec 20, 2023 Dec 20, 2023

Copy link to clipboard

Copied

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?

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 ,
Dec 21, 2023 Dec 21, 2023

Copy link to clipboard

Copied

Nope, cell.label for me is already set to an empty string, despite me using insertLabel previously to insert labels into the cell. It seems cell.label is referencing completely different data from cell.extractLabel(key). Does anyone know how I can systematically remove all labels that were inserted using insertLabel(key,value) without keying every value and setting it to an empty string? 

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 ,
Dec 21, 2023 Dec 21, 2023

Copy link to clipboard

Copied

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.

 

 

 

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 ,
Dec 21, 2023 Dec 21, 2023

Copy link to clipboard

Copied

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);
        };
    }
}

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 Beginner ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

In ExtendScript/jsx you could use 

extractAllLabels()

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 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

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

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 Beginner ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

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.

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 Beginner ,
Nov 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

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-i...

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 25, 2024 Nov 25, 2024

Copy link to clipboard

Copied

LATEST

That's great, many 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