Cleo_helm wrote … Issue #2: How Do I get the text also vertically aligned?--> those three options do not work: paragraphs.item(0).verticalJustification = verticalJustification.centerAlign; paragraphs.item(0).verticalJustification = Justification.centerAlign; paragraphs.item(0).Justification = verticalJustification.centerAlign;
|
Issue #3: How can I color my textbox? fillColor = myColorBunt (I defined it earlier in the script as variable) also doesn't work, the error code says it needs string or swatch (how would a swatch look like, not a variable name?) //define color for color code var myColorBunt = myDocument.colors.add(); myColorBunt.model = ColorModel.PROCESS; myColorBunt.space = ColorSpace.CMYK; myColorBunt.colorValue = [40, 10, 5, 20];
|
Hi Cleo,
let's see in issue 2.
If you search the DOM documention you'll find no verticalJustification on textFrame objects.
Why? See into InDesign's UI. How would you set vertical justification of text in a text frame?
That's an extra dialog with three tabs in CS6.
And an indication that you cannot do it directly on textFrame and have to dig deeper. Object textFrame has also a property textFramePreferences and if you follow the link in documentation, you'll notice that all the properties you see in that extra dialog are waiting here. Have a look into the UI first ( from my German InDesign CS6 ):

Apply the code below and read out textFrameProperties of textFrame in the ESTK.
For ease of use: Select the text frame and work with the selection.
app.selection[0].textFramePreferences.verticalJustification; // returns CENTER_ALIGN in the JavaScript Console
Know, that the returned value is the name of an enumeration value, a special number that is converted by the ESTK to its string representation.
Unfortunately it is only doing this with the last expression on the dot notation, that is necessary to apply it. The full enumeration value is VerticalJustification.CENTER_ALIGN.
So this will work on a selected text frame:
app.selection[0].textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
What also will work is applying the number representation of the enumeration, it's core value, but that's very hard to decipher if looking at code like that:
app.selection[0].textFramePreferences.verticalJustification = 1667591796;
Where did I look up this number?
I followed the links in the documentation.
TextFrame > TextFramePreference > VerticalJustification (enum)
Here we see that verticalJustification has 4 possible values.
And all the 4 values can be expressed by their name or by their value.
Remains the question how we can set this preference at creation time of the text frame with the add() method?
Answer: Apply an object directly. And object is defined by this notation:
{ property1 : value , property2 : value /*, etc.pp.*/ }
Let's try this:
app.documents[0].masterSpreads[0].pages[0].textFrames.add
(
{
geometricBounds : ["85mm","50mm","100mm","100mm"] ,
contents : "Button" ,
textFramePreferences : { verticalJustification : VerticalJustification.CENTER_ALIGN }
}
);
Now for issue 3 where you want to apply a color as value for the fillColor property of your text frame.
Look at your code.
You did not apply a name to your color when using method add().
You did apply some properties after creation time.
You did not apply a value for property name.
So InDesign is applying a name automatically.
And this could be problematic:
If the user selected a not automatically named color in the Swatches Panel, that color's name would be taken for your new color and " Kopie" (German InDesign) is applied to the name. InDesign is always keen to fill in properties that are not set at creation time. By something in preferences. And if the user selected a color in the panel, this is a preference. E.g. for drawing out a new text frame.
Another, but similar scenario:
If no document is open and the user selects a color like [Black] ( German: [Schwarz] ) in the Swatches Panel for fill the user changed a preference. Now you come back to your InDesign days after that and add a new document.
Then the user runs your code:
A color named "Schwarz Kopie" will be added to the Swatches panel.
If the user is doing this on an English version InDesign it will be "Black Copy".
All other properties will be the right ones. But the name of the added color is not.
FWIW: If you already added a new automatically named color to the document successfully you can apply it this way :
textFrame.fillColor = app.documents[0].colors.itemByName(myColorBunt.name);
So it might be better working with name at creation time.
If you are working with existing documents you cannot be sure if the color is there or not.
So the following approach would be better where I am working with a not automatically named color at creation time:
// The name of the color you want to apply:
var colorName = "buttonFill";
// The color CALLED by its name:
var buttonColor = app.documents[0].colors.itemByName(colorName);
/*
At this point, the color could be there or not:
Calling an object by its name is just that, a call.
A shout like "Cleo" where the one who shouts does not know if someone is there to answer.
You are doing nothing with buttonColor at this point.
So no error is thrown, if the color behind buttonColor is not there.
In ExtendScript terms for InDesign: if the color is not valid or as property of color:
buttonColor.isValid
*/
// Ask if the color is there.
// If you look up DOM documentation there is property isValid for a color object ( and for many other objects as well )
// isValid has two possible values, true or false
if(buttonColor.isValid)
{
// Ok. A color by the name stored in colorName exists.
// But you cannot be sure, that all your intended property values for this color are ok.
// So you could apply them here:
buttonColor.properties =
{
colorValue : [ 255, 255 , 150 ] , // 3 number array, could be RGB or Lab
space : ColorSpace.RGB , // Now it's clear, the 3 numbers are meant for RGB
model : ColorModel.PROCESS
};
};
else
{
// isValid obviously returned false
// A color by the name stored in variable colorName is not there:
// So let's add it to the document:
app.documents[0].colors.add
(
{
name : colorName ,
colorValue : [ 255, 255 , 150 ] , // 3 number array, could be RGB or Lab
space : ColorSpace.RGB , // Now it's clear, the 3 numbers are meant for RGB
model : ColorModel.PROCESS
}
);
};
// Then you could use your color that is called by its name as value for fillColor here:
app.documents[0].masterSpreads[0].pages[0].textFrames.add
(
{
fillColor : buttonColor ,
geometricBounds : ["85mm","50mm","100mm","100mm"] ,
contents : "Button" ,
textFramePreferences : { verticalJustification : VerticalJustification.CENTER_ALIGN }
}
);
Regards,
Uwe