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 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;
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];
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; myStyle.applyTo(myFrame);
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]
My apologies. I didnt test that before I sent it. Change the second line to this:
var myRange = app.activeDocument.textFrames.textRange;
I suppose the issue could be with applying the style to the first textframe of the collection using textFrames. 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.textRange; myStyle.applyTo(myFrame);
That works great.
Thanx a million Manan Joshi!
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?