Skip to main content
Inspiring
July 13, 2022
Answered

Find label remove text style

  • July 13, 2022
  • 3 replies
  • 313 views

Hello I'am looking for a script that find a label and change the text style to none.

I get a xml file like [abc[BBB]abc]

The label with abc has text style with icon. The label BBB must have text style none.

 

Kind regards,

Patrick

This topic has been closed for replies.
Correct answer Laubender

Hi @patrickbcm ,

do you mean that character style [None] should be applied?

How about local style overrides? Should they be removed as well? Yes?

And is that "label" an XML Tag? If yes, the script code below could work.

 

Before you start the script code select one character in that BBB area of text.

The script needs that selection to find the associated XML Element.

 

// Get the applied XML Element of the selected character between the tags you want to clear the styles:
var appliedXmlElement = app.selection[0].texts[0].associatedXMLElements[0];
var tagName = appliedXmlElement.markupTag.name;

/*
	If you already know the tag name do it that way:
	
	var tagName = "MyTagName"; // Insert the name between the quotes.
*/

var doc = app.documents[0];
var noCharStyle = doc.characterStyles[0];

var xmlElementsArray = doc.xmlElements[0].evaluateXPathExpression("//"+tagName );

for( var n=0; n<xmlElementsArray.length; n++ )
{
	xmlElementsArray[n].texts[0].applyCharacterStyle( noCharStyle );
	xmlElementsArray[n].texts[0].clearOverrides( OverrideType.CHARACTER_ONLY );
};

 

Save the document before you run the script so that you can revert to the saved state of the document.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

3 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
July 16, 2022

Hi @patrickbcm ,

do you mean that character style [None] should be applied?

How about local style overrides? Should they be removed as well? Yes?

And is that "label" an XML Tag? If yes, the script code below could work.

 

Before you start the script code select one character in that BBB area of text.

The script needs that selection to find the associated XML Element.

 

// Get the applied XML Element of the selected character between the tags you want to clear the styles:
var appliedXmlElement = app.selection[0].texts[0].associatedXMLElements[0];
var tagName = appliedXmlElement.markupTag.name;

/*
	If you already know the tag name do it that way:
	
	var tagName = "MyTagName"; // Insert the name between the quotes.
*/

var doc = app.documents[0];
var noCharStyle = doc.characterStyles[0];

var xmlElementsArray = doc.xmlElements[0].evaluateXPathExpression("//"+tagName );

for( var n=0; n<xmlElementsArray.length; n++ )
{
	xmlElementsArray[n].texts[0].applyCharacterStyle( noCharStyle );
	xmlElementsArray[n].texts[0].clearOverrides( OverrideType.CHARACTER_ONLY );
};

 

Save the document before you run the script so that you can revert to the saved state of the document.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Kasyan Servetsky
Legend
July 15, 2022

Your question is incorrect so most probably it will never be answered.
A label is a little bit of text attached to a page item via the 'Script Label' panel which helps a script to find the correct object. It has nothing to do with the XML structure.
I guess you want to find a specific XML element -- e.g. bbb inside abc -- and apply the character style 'None' to its (placed) contents.

Rishabh_Tiwari
Community Manager
Community Manager
July 14, 2022

Hi @patrickbcm ,

 

Thanks for reaching out. I found a similar discussion from which you can take reference https://community.adobe.com/t5/indesign-discussions/find-items-via-script-label/m-p/10228841#M124829 

 

In case that's not what you were looking for, I am leaving this discussion open for expert suggestions.

 

Regards

Rishabh

Inspiring
July 15, 2022

I saw this discussion allready, but this is not were i looking for.