Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Apply justification to just added textFrame (indesign script)

Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Hi, 

The target is to add a textFrame with centered page number out under every page. I know can do it with master pages but don't want to affect. It's only for printing proofs.

How to center page number into textFrame?

Can anyone help me to complete this script?

Thanks a lot

 

Mario

 

var doc = app.activeDocument;
var myRuler = doc.viewPreferences.rulerOrigin;
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
doc.documentPreferences.slugTopOffset = 15;
doc.documentPreferences.documentSlugUniformSize = true;
doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
doc.zeroPoint = [0,0];
var vmu = doc.pages[0].bounds[2];
var hmu = doc.pages[0].bounds[3];

for (i = 0; i < doc.pages.length; i++) {
doc.pages[i].textFrames.add().properties = {
geometricBounds : [ (vmu + 5),0,(vmu + 15),hmu ],
strokeWidth : 0,
fillColor : "None",
contents : SpecialCharacters.AUTO_PAGE_NUMBER,
// justification = Justification.CENTER_ALIGN, //no error msg with this line but no result
}
 
};

doc.viewPreferences.rulerOrigin = myRuler;
TOPICS
Scripting

Views

147

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 28, 2021 Apr 28, 2021
Hi Grandeforedit, one can set this up while adding the text frame. Provide an object as argument to method add(). The other trick is to define text formatting with property parentStory, also with an object. Text frame preferences can be done as well. Example: var doc = app.documents[0]; doc.textFrames.add ( { contents : "Hello World!" , geometricBounds : [0,0,"100mm","100mm"], strokeWidth : 0 , strokeColor: "None" , parentStory : { justification : Justification.CENTER_A...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Assign a variable to each created frame, say 'tf', then within your for loop after you've created the frame: 

tf.texts[0].justification = Justification.CENTER_ALIGN;

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
Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Thanks Brian, not sure I understand how to assign a variable to each created frame but you point me to a solution.

Testing it seems to work on the right frame ...I hope

 

thanks again

Mario

 

var doc = app.activeDocument;
var myRuler = doc.viewPreferences.rulerOrigin;
doc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;
doc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
doc.documentPreferences.slugTopOffset = 15;
doc.documentPreferences.documentSlugUniformSize = true;
doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
doc.zeroPoint = [0,0];
var vmu = doc.pages[0].bounds[2];
var hmu = doc.pages[0].bounds[3];

for (i = 0; i < doc.pages.length; i++) {
doc.pages[i].textFrames.add().properties = {
geometricBounds : [ (vmu + 5),0,(vmu + 15),hmu ],
strokeWidth : 0,
fillColor : "None",
contents : SpecialCharacters.AUTO_PAGE_NUMBER,
}
doc.pages[i].textFrames[0].texts[0].justification = Justification.CENTER_ALIGN;
}

doc.viewPreferences.rulerOrigin = myRuler;

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 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

See bolded line: 
 
for (i = 0i < doc.pages.lengthi++) {
var tf = doc.pages[i].textFrames.add().properties = {
geometricBounds : [ (vmu + 5),0,(vmu + 15),hmu ],
strokeWidth : 0,
fillColor : "None",
contents : SpecialCharacters.AUTO_PAGE_NUMBER,
}
tf.texts[0].justification = Justification.CENTER_ALIGN;

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 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

Hi Grandeforedit,

one can set this up while adding the text frame.

Provide an object as argument to method add().

The other trick is to define text formatting with property parentStory, also with an object.

Text frame preferences can be done as well.

 

Example:

 

var doc = app.documents[0];
doc.textFrames.add
(
	{
		contents : "Hello World!" ,
		geometricBounds : [0,0,"100mm","100mm"],
		strokeWidth : 0 ,
		strokeColor: "None" ,
		
		parentStory : 
			{
				justification : Justification.CENTER_ALIGN ,
				pointSize : 20 ,
				fillColor : doc.colors.itemByName("Magenta") ,
				fillTint : 50 ,
				leftIndent : "20 mm" ,
				rightIndent : "20 mm"
			} ,
		
		textFramePreferences :
			{
				verticalJustification : VerticalJustification.CENTER_ALIGN
			}
	}
);

 

Regards,
Uwe Laubender

( ACP )

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
Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

LATEST

It works great,

what a lesson about nested proprerties and preferences!

Thanks, thanks a lot Uwe.

Mario

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