Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Scripting Problem Illustrator Format text

Nouveau ici ,
Apr 19, 2021 Apr 19, 2021

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();
}
}
}

SUJETS
Scripting
1.3K
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 1 bonne réponse

Community Expert , 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
...
Traduire
Adobe
Community Expert ,
Apr 19, 2021 Apr 19, 2021

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/

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Nouveau ici ,
Apr 20, 2021 Apr 20, 2021

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

 

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Guide ,
Apr 20, 2021 Apr 20, 2021

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

var myFrame = app.activeDocument.textFrames[0].textRange;
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Nouveau ici ,
Apr 20, 2021 Apr 20, 2021

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Apr 20, 2021 Apr 20, 2021

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

-Manan

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Apr 20, 2021 Apr 20, 2021

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

 

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Nouveau ici ,
Apr 20, 2021 Apr 20, 2021

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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
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;
myStyle.applyTo(myFrame);

-Manan

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Nouveau ici ,
Apr 20, 2021 Apr 20, 2021

PERFECT 😄

 

That works great.

 

Thanx a million Manan Joshi!

 

regards G

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Community Expert ,
Apr 20, 2021 Apr 20, 2021
LA PLUS RÉCENTE

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?

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines