Skip to main content
Participant
March 6, 2024
Answered

Create right-to-left paragraph style, based on existing (left-to-right) style

  • March 6, 2024
  • 2 replies
  • 527 views

When working with Arabic translations, my current layout process involves defining all paragraph styles for the document in the English layout (let's use "H1" as an example). Then I create a new paragraph style called "H1_RTL," based on H1, alignment = right, paragraph composer = Adobe World-Ready Paragraph Composer.

 

The closest I've been able to come is modifying the CreateCharacterStyle sample script to create a new paragraph style using the selected text; this sets "Based on" to "[none]" and copies the other parameters--that's fine, it seems like it would be easier to have the script grab the "Based on" property instead but I could be wrong--but even using that, I can only create an exact copy of the selected style. I've got no idea how to change the alignment or the composer.

 

I've found a way to add a dialog box to set the name for the new style into the CreateCharacterStyle.jsx script that comes packaged with InDesign, and changed "character" to "paragraph" throughout the rest of the script, and if that's the only change I make, it works just fine. However, trying to add myParagraphStyle.composer = "Adobe World-Ready Paragraph Composer" throws an error, and I'm not sure what other expressions to try for that.

 

I've also tried every single parameter I can find any reference to that might change the paragraph alignment (alignment, justification, position, paragraphAttributes.justification, characterAttributes.justification), with various permutions of possible values, and none of them have worked.

 

Here's the dialog box, plus the first few parameters the script grabs from the selected text:

function myDefineParagraphStyle(myParagraphStyleName){
	var myParagraphStyle;
	var myDocument = app.activeDocument;
	//Create the character style if it does not already exist.
	myParagraphStyle = myDocument.paragraphStyles.item(myParagraphStyleName);
	try{
		myParagraphStyle.name;
	}
	catch (myError){
		myParagraphStyle = myDocument.paragraphStyles.add({name:myParagraphStyleName});
	}
	var mySourceText;
	/* check if the text cursor is inside some text first */
	if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline"))
		mySourceText = app.activeDocument.selection[0].appliedParagraphStyle;
	else
		mySourceText = app.activeDocument.textDefaults.appliedParagraphStyle;
/* clear out any possible previous Find text and formatting */
	app.findTextPreferences = null;
	myParagraphStyle.appliedFont = mySourceText.appliedFont;
	myParagraphStyle.fontStyle = mySourceText.fontStyle;
	myParagraphStyle.pointSize = mySourceText.pointSize;
/*the list of parameters continues on in this way for some time*/

 

This topic has been closed for replies.
Correct answer Eugene Tyson

Don't know if this will work for you or if it's even 100% correct but might give you a pointer to work from

 

myParagraphStyle.alignToBaseline = false; // Ensure alignment to the top of the text box
myParagraphStyle.justification = Justification.RIGHT_ALIGN; // Set alignment to right
myParagraphStyle.composer = "Adobe World-Ready Paragraph Composer"; // Set composer to Adobe World-Ready Paragraph Composer

2 replies

Peter Kahrel
Community Expert
Community Expert
March 7, 2024

Eugene's code is correct. To base the style on another style and add the required properties in on go, you can use this code:

 

myParagraphStyle = myDocument.paragraphStyles.item(myParagraphStyleName);
if (!myParagraphStyle.isValid) {
  myDocument.paragraphStyles.add ({
    name: myParagraphStyleName,
  });
}

myParagraphStyle.properties = {
  basedOn: myDocument.paragraphStyles.item ('...'),  // Your style name
  name: myParagraphStyleName,
  justification: Justification.RIGHT_ALIGN,
  composer: "Adobe World-Ready Paragraph Composer",
});
Eugene TysonCommunity ExpertCorrect answer
Community Expert
March 6, 2024

Don't know if this will work for you or if it's even 100% correct but might give you a pointer to work from

 

myParagraphStyle.alignToBaseline = false; // Ensure alignment to the top of the text box
myParagraphStyle.justification = Justification.RIGHT_ALIGN; // Set alignment to right
myParagraphStyle.composer = "Adobe World-Ready Paragraph Composer"; // Set composer to Adobe World-Ready Paragraph Composer
Participant
March 18, 2024

This worked perfectly! Thank you so much, it felt like it should be such a simple thing, but I just couldn't find the right variables.