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();
}
}
}
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
...
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/
Copy link to clipboard
Copied
Copy link to clipboard
Copied
What if you change line 2 in @Disposition_Dev 's snippet to
var myFrame = app.activeDocument.textFrames[0].textRange;
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
Copy link to clipboard
Copied
Using the suggestion given by @femkeblanco it seems to be work for me. See the screengrab here
-Manan
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;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
PERFECT 😄
That works great.
Thanx a million Manan Joshi!
regards G
Copy link to clipboard
Copied
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?