Scripting Problem Illustrator Format text

New Here ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

hi everyone,

 

just to make things clear - I'm realy bad in scripting…

I found a script and twealked it a bit to create a textbox and insert some text (fillcolor of selected item).

What I realy can't get to work is to format the text the way I want. I would like to use a predefined ParagraphStyle from the Pallett. Would be great if someone could give me a helping hand on this.

 

What I got so far is this:

 

function doCallOut (inSelection, ref)
{
var i;
var colorName;
var pointTextRef;
var bufferSpace = "10";

var callOutLayer = app.activeDocument.activeLayer;


if (inSelection instanceof Array)
{
for (i=0; i<inSelection.length; i++)
{
colorName = "undefined";
if ( inSelection[i].fillColor.typename == "SpotColor" )
{
colorName = inSelection[i].fillColor.spot.name;
}
if ( inSelection[i].fillColor.typename == "PatternColor" )
{
colorName = inSelection[i].fillColor.pattern.name;
}
if ( inSelection[i].fillColor.typename == "GradientColor" )
{
colorName = inSelection[i].fillColor.gradient.name;
}
    pointTextRef = callOutLayer.textFrames.add();
     
pointTextRef.contents = colorName;

if(inSelection[i].height > 10)
{
pointTextRef.top = inSelection[i].top - (inSelection[i].height + 2);
pointTextRef.left = inSelection[i].left;
}
else
{
pointTextRef.top = inSelection[i].top - (inSelection[i].height - 8);
pointTextRef.left = inSelection[i].left + inSelection[i].width + 5;
}

pointTextRef.name = "CCOUT " + colorName;
pointTextRef.selected = true;
var mySelection = app.activeDocument.selection[i];

redraw();
}
}
}

TOPICS
Scripting

Views

267

Likes

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

correct answers 1 Correct Answer

Adobe Community Professional , Apr 20, 2021 Apr 20, 2021
I suppose the issue could be with applying the style to the first textframe of the collection using textFrames[0]. This was used to just give an example, you will have to get the object referring to the textframe you want the style to apply. For testing use the following code, make a selection of the textframe and then run the code. The code will apply the style to selected textframe. var myStyle = app.activeDocument.paragraphStyles["My Paragraph Style"]; var myFrame = app.selection[0].textRange...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

there is a property of the document object called "paragraphStyles" which is a collection of all the paragraph styles in the doc. You can access them by name,  and then apply them to a textFrame like so:

var myStyle = app.activeDocument.paragraphStyles["My Paragraph Style"];
var myFrame = app.activeDocument.textFrames[0];
myStyle.applyTo(myFrame);

 

for reference:

https://ai-scripting.docsforadobe.dev/jsobjref/ParagraphStyle/

Likes

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
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

hi Dilliam,

 

thanx for the fast reply. tried your suggestion and it lead me to a new Problem

When I add your lines I get a new error stating the following (See screenShot):

»Style can only be applied to a textrange«

Any help appriciated

 

Thanx G

 

Likes

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
Enthusiast ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

What if you change line 2 in @DilliamWowling 's snippet to

var myFrame = app.activeDocument.textFrames[0].textRange;

Likes

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
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

Thanx Femkeblanco,

ok, that is solving the error, but the ParagraphStyle is still not applied to the Frames.

Illustrator is still using the Standard »undefined« Style [Normal Paragraph Style]

 

Thanx G

Likes

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 Professional ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

Using the suggestion given by @femkeblanco it seems to be work for me. See the screengrab here

-Manan

Likes

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 Professional ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

My apologies. I didnt test that before I sent it. Change the second line to this:

 

var myRange = app.activeDocument.textFrames[0].textRange;

Likes

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
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

Thanx to everyone so far…

 

So this seems to work fine in a new Document. Bad Thing - it's not working in my MasterFile.

Is there a way to figure out why? Still using the standard ParagraphStyle instead of the predefined

 

cheers

G

Likes

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 Professional ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

I suppose the issue could be with applying the style to the first textframe of the collection using textFrames[0]. This was used to just give an example, you will have to get the object referring to the textframe you want the style to apply. For testing use the following code, make a selection of the textframe and then run the code. The code will apply the style to selected textframe.

var myStyle = app.activeDocument.paragraphStyles["My Paragraph Style"];
var myFrame = app.selection[0].textRange;
myStyle.applyTo(myFrame);

-Manan

Likes

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
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

PERFECT 😄

 

That works great.

 

Thanx a million Manan Joshi!

 

regards G

Likes

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 Professional ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

LATEST

It's difficult to determine anything from that video. I can't see the code you're using nor the menu/panel selections you made, so i can't know what the expected behavior was at any given time.

 

you're sure there's no typos in your code that could be causing the script to not find your needed paragraphStyle? These names are case sensitive.

 

if you duplicate the textFrame and then try to apply the paragraphStyle to the duplicate, does it work then? Are you only having a problem with that specific paragraphStyle or can you apply other paragraphStyles successfully?

Likes

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