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

How to access different character styles in a single text frame.

Contributor ,
May 11, 2015 May 11, 2015

Hi All,

I am trying to get the multiple character styles applied to the single selected text frame. Let's say, there is a text frame with contents "ABC XYZ", ABC have different character style and XYZ have different.

What I am doing here is iterating through each character and getting its character styles. So its taking a lot of time.

Is there any other way of getting number of character styles in a text frame?

Thanks for any help.

TOPICS
Scripting
972
Translate
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
Adobe
Guide ,
May 11, 2015 May 11, 2015

‌cheaking each word may be a bit faster.

Translate
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
Contributor ,
May 11, 2015 May 11, 2015

What if single word have different styles like "ABCD"?

Translate
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
Guide ,
May 11, 2015 May 11, 2015

‌im not near a computer so only tossing ideas.

if you duplicated a text frame in a new doc. Would it bring with it the styles used?

then you might be able to cycle through the new documents styles.

Translate
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 ,
May 11, 2015 May 11, 2015

AI_learner,

Can you post a plausible example, please? Why do you need different styles in one word?


Translate
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
Contributor ,
May 11, 2015 May 11, 2015

All I need to get the different styles in a single textframe. No one stop you to apply different styles in a single word, it's just a case (although even I wonder why people need this ).. If you see in Indesign, there is a property "textStyleRanges" which gives the array of different text style ranges, we don't have to iterate through character by character or word by word.

So All I am looking for some better script to get the character styles I did try something like this,

var textRangeLength = textFrame.textRanges.length;

for (var i = 0; i < textRangeLength; i++)

{

     var noOfCharacterStyles = textFrame.textRanges.characterStyles.length;

     ----------------------------
}

By executing above code, what happening is as follows,

Suppose we have a textFrame with content "ABCD EFGH CD"..

then textRangeLength becomes 12.. and its calculating character attributes applied on each character.

And w
hat I am looking for, it should return the characterStyle as,

First style object will be "A"

Second style object will be "B"

then third will be "C"

then fourth will be "D EFGH "

and then "C" again...

I hope it makes sense. Thanks for any help..

Translate
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
Guide ,
May 13, 2015 May 13, 2015

another Hack workaround, but it might help...

if you copy a text frame and paste in a new doc, it brings with it the used CharStyles.

from there you can just get the documents CharStyles then close the new doc without saving.

var doc = app.activeDocument;

app.executeMenuCommand ('copy');

var newDoc = app.documents.add();

newDoc.activate();

app.executeMenuCommand ('paste');

Translate
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
Contributor ,
May 14, 2015 May 14, 2015

Thanks Qwerty,
I got the idea from your previous reply. But I dont want to open a new doc, the reason is all open/close new doc process will be visible. Is there any other work around so that I don't have to open a new doc and all the things will be done in the same doc?

Translate
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
Guide ,
May 14, 2015 May 14, 2015
LATEST

‌again I'm not at a computer so only tossing ideas.

without any visible happening I would be back to cycling through each char.

the only other thing that may be worth exploring is maybe minamizing illustrator all together.

never even thought about it so not sure if it's even possible.

But it should be quite fast to create new doc grab info and close that you should only get a bit of a flicker.

i'll have a play tomorrow and see what I can come up with.

if its for use on a PC I may be able to get a different hack working. But mac would be out of luck.

Translate
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