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

Text with no stroke returning '1' / reading stroke weight when stroke is applied to 'Type'

Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hi,

I have a double question regarding strokes on text/items:

 

1. I am trying to read the stroke weight of x2 text frames, one with no stroke and one with a 0.75pt stroke. The script is returning '1' for the text frame with no stroke, and it returns 0.75 for the text frame that has a 0.75pt stroke. The text frame with the stroke is returning what I would expect but the text frame with no stroke that returns '1' seems to be odd, should this not return '0' instead (see below for the script and 'Stroke_Weight_Return' screenshot for what I am seeing)?

 

2. Is there a way to read the stroke weight if the stroke is applied to the 'Type' rather than the 'Characters' i.e. if using a graphic style with multi strokes on (see screenshots of stroke set to type and stroke set to characters)?

var doc = app.activeDocument;
var objectStroke1 = doc.textFrames["Text_Test_1"].textRange.characterAttributes.strokeWeight;
var objectStroke2 = doc.textFrames["Text_Test_2"].textRange.characterAttributes.strokeWeight;
alert([objectStroke1,objectStroke2]);

Stroke_Weight_Return.png

Stroke_Set_To_Characters.png

Stroke_Set_To_Type_(Using_Graphic_Styles).png

  

TOPICS
Scripting

Views

517

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
Adobe
Community Expert ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Check the "stroked" property. From memory I think the default strokeWidth is 1.0, even for an item that isn't stroked. Does that help with question 1? In other words, it doesn't matter what the strokeWidth is, if the item's stroked is false;

 

Question 2 short answer is that scripting doesn't give us access to multiple strokes and fills; only the first of each. ☹️

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hi, thanks for the quick response.

 

Regarding question 1, to be honest, I just need to be able to read if it is true or false that the object has a stroke, so I would need to alter the script accordinglly to give me that answer rather than giving me the stroke weight?

Out of curiosity, why would an object with no stroke default to 1, is that giving the answer 'false' (and true would be '0')?

 

Regarding question 2, again, I just need to know if it has a stroke but it does not seem to read the stroke when applied to the 'Type' rather than the 'Characters', I just wnated to know if there is a way to access a stroke set to the 'Type'.

 

Hope this makes sense.

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hi, does this work?

 

var object1HasStroke = doc.textFrames["Text_Test_1"].textRange.characterAttributes.stroked;

Unfortunately it might not help with anything but a simple appearance.

 

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Thanks, I will take a look and get back to you, just on with something else at the moment but will get to look at this soon. Appreciate your help.

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 ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied


@glibshaft wrote:

Out of curiosity, why would an object with no stroke default to 1 ... ?



Illustrator objects keep their strokeWeight even when they aren't stroked. If it wasn't this way, turning off a stroke and then back on would reset strokeWeight to default of 1. For this reason, strokeWeight and stroked are totally separate properties.

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Ok, I have looked at this and can get it to work using '.stroked' but only on non text items. Funnily enough this is a stage I had already gone through to get the return data I required but could not get it to work when I first tried it. Example below has the cancelled out script that returns correct results for a path and the active part of the script is the part that just returns 'No Stroke' even if the text has a stroke.

// if (app.activeDocument.pageItems["Path_Test_2"].stroked == true){
// alert("Stroke");
// }
// else {
// alert("No Stroke");
// }

if (app.activeDocument.textFrames["Text_Test_2"].textRange.characterAttributes.filled == true){
alert("Stroke");
}
else {
alert("No Stroke");
}



Should '.stroked' work on text items or am I doing something incorrectly?

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Just realised 'textRange.characterAttributes.stroked' line should contain '.stroked', not ',filled' but it still doesn't work.

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
Valorous Hero ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

It only works on the non-added-appearance fills or strokes, the one you get when you type in with a T caret into a text frame and then set a stroke in some stroke-related panel. To read appearance stuff you'd have to duplicate a temp copy of your item, select it and do app.executeMenuCommand("expandStyle") to break it apart for analysis by script. You'd get a bunch of path items and compound paths and groups to try and work with.

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

Hi,

 

The irony is that I wanted to pick up the text if it had a stroke to then be able to use the 'app.executeMenuCommand("expandStyle")' do do what I need to with the rest of the script.

 

Mmmmmm, I may need to think on with this one.

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
Participant ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

I couldn't get the '.stroked' to work for the text applied to the 'characters', but I have a work around using  'CharacterAttributes.strokeColor' (see below).

 

This still doesn't get around the issue of colour applied to the 'Type' i.e. graphic styles though. Guess I will need to keep working on that:

if (app.activeDocument.textFrames["Text_Test_2"].textRange.characterAttributes.strokeColor == "[NoColor]"){
alert("No Stroke");
}
else {
alert("Stroke");
}

 

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