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
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 = ''
...
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);
};
}
}
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
Copy link to clipboard
Copied
Just set the cell.label to ""
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?
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?
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?
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.
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);
};
}
}
Copy link to clipboard
Copied
In ExtendScript/jsx you could use
extractAllLabels()
Copy link to clipboard
Copied
I don't see the extractAllLabels() function in the ES object model, @luis_guimaraes
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.
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...
Copy link to clipboard
Copied
That's great, many thanks.