Copy link to clipboard
Copied
Hello Scripters,
Is it possible to preserve the formatting, when I remove an applied cell style with the following code?
“MyCellStyle.remove(app.activeDokument.cellStyles.firstItem());”
How can I get access to this feature in my script? (see also screenshot->red arrow)
Thanks for hints.
Roland
Roland:
You could iterate through all your cells with the applied cell style, select the cells one after another and apply a menu action to break the link to the style ("Break Link to Style" / "Verknüpfung mit Format aufheben").
Then you can remove the cell style without loosing any formatting.
To invoke the menu action you could use this code. For security reasons I wrapped it up with a "try/catch":
...//Disconnect the cell with the applied cell style (option in the cell styles panel of the UI: "Break
Copy link to clipboard
Copied
It looks to me like it's missing. File a feature request...
To simulate the funtionality, you'll probably have to grab the properties of the style, and then loop through the doc, find every cell that has the style applied, and apply the styling manually...
Good luck!
Harbs
Copy link to clipboard
Copied
I already feared it. Well, I must try another way.
Many thanks for your answer.
Kind regards
Roland
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The problem is this:
I want to convert the formatting from one cell to another (in a different table). After this, the formatting of the new cell should be retained, but the cell Style is to be deleted.
So I remove the generated cell style and replace it with cellStyle:[None] but there is also no option to reserve formatting via script.
For ChararacterStyle it’s the same: there is no option like in the GUI
void remove([replacingWith: CharacterStyle])
Now I try to work with the properties of the cell.
Kind regards
Roland
Copy link to clipboard
Copied
Roland:
You could iterate through all your cells with the applied cell style, select the cells one after another and apply a menu action to break the link to the style ("Break Link to Style" / "Verknüpfung mit Format aufheben").
Then you can remove the cell style without loosing any formatting.
To invoke the menu action you could use this code. For security reasons I wrapped it up with a "try/catch":
//Disconnect the cell with the applied cell style (option in the cell styles panel of the UI: "Break Link to Style" / "Verknüpfung mit Format aufheben"):
try{app.scriptMenuActions.itemByID(132129).invoke()}catch(e){};
Uwe
Copy link to clipboard
Copied
Good point.
Harbs
Copy link to clipboard
Copied
Yes, great! It works. Thanks Uwe.
That avoids a lot of detours ...
Kind regards
Roland
Copy link to clipboard
Copied
Roland wrote:
For ChararacterStyle it’s the same: there is no option like in the GUI
void remove([replacingWith: CharacterStyle])
There we have a different opportunity. We can do that without using menu actions.
As Peter Kahrel pointed out at another thread recently, just apply [None] (myDoc.characterStyles[0]) to the texts using that character style, then you can remove the character style savely. Surprisingly the formatting is preserved after doing so:
http://forums.adobe.com/message/4073431#4073431
Uwe
Copy link to clipboard
Copied
Yes, you're right. But if you use the GUI, this is not the case. Strange ...
What I was referring to is: I can't control this behavior with the command "remove".
Kind regards
Roland