Copy link to clipboard
Copied
Hi! I was trying to replicate in a jsx script a specific object. It's the kind of shape-bounded text that you can do by creating a shape (e.g. cirle) and using the text tool to put text inside. I'm trying to replicate that object in code, but I'm unable to find the dependencies between TextFrame and Oval objects it involves. Any idea?
Thank you!
1 Correct answer
After you create Oval - change its contentType:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Oval.html
Copy link to clipboard
Copied
After you create Oval - change its contentType:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Oval.html
Copy link to clipboard
Copied
This is the correct answer. Thank you! I'll provide a very short snippet for those interested:
var doc = app.activeDocument;
var new_oval = doc.ovals.add()
new_oval.geometricBounds = [0, 0, 50, 50];
new_oval.contentType = ContentType.TEXT_TYPE;
Copy link to clipboard
Copied
A follow-up question if you are so kind. How can I add text to this object? textFrames and textBoxes are empty and I can't .add() a new one.
Copy link to clipboard
Copied
Either set contents:
new_oval.contents = "this is an oval";
or you can link it with existing TextFrames - using nextTextFrame / previousTextFrame.
Or you can paste contents of the Clipboard:
new_oval.texts[0].paste();
Copy link to clipboard
Copied
Hello,
o replicate shape-bounded text in a JSX (JavaScript for Adobe Illustrator) script, you need to work with both TextFrame and shape objects, such as Ellipse (for circles). In Illustrator scripting, these objects interact as follows:
Create the Shape: First, you need to create the shape, such as a circle or any other closed path (for example, using the PathItems.ellipse() method to create an ellipse).
Create Text and Fit It to the Shape: After creating the shape, you need to place text inside it. The TextFrame object can be used to create text. You can then fit the text to the boundaries of the shape (ellipse in this case).
example of how you can create shape-bounded text inside an ellipse in JSX:
// Create a new document
var doc = app.documents.add();
// Define ellipse dimensions (position, width, height)
var x = 200;
var y = 200;
var width = 400;
var height = 200;
// Create an ellipse shape (path item)
var ellipse = doc.pathItems.ellipse(y + height / 2, x - width / 2, width, height);
// Create a text frame inside the ellipse
var textFrame = doc.textFrames.add();
textFrame.contents = "Hello, Illustrator!";
// Set the text frame's position
textFrame.position = [x - width / 2, y + height / 2];
// Fit text inside the shape (ellipse)
textFrame.textPath = ellipse; // Make text follow the path of the ellipse
// Optionally adjust text properties (font, size, etc.)
var textRange = textFrame.textRange;
textRange.characterAttributes.size = 24;
textRange.characterAttributes.textFont = app.textFonts.getByName("Arial");
// Adjust the text to be vertically aligned in the center of the shape
textFrame.textPathJustification = Justification.CENTER;
Ellipse Creation: The ellipse is created using the doc.pathItems.ellipse() method. This takes the y and x positions, followed by the width and height.
TextFrame Creation: The textFrame is added to the document and its contents is set to the text you want to display.
Positioning: The text frame is positioned at the center of the ellipse.
Text Fit to Path: The key part here is textFrame.textPath = ellipse;, which makes the text follow the path of the ellipse (or any shape you create).
Text Adjustments: You can adjust the font, size, and other properties of the text as needed.
The textPath property links the text frame to the path of the shape (ellipse), making the text conform to its outline. dgme paystub
Depending on the text length, you might need to adjust font size or the shape's size to make the text fit properly within the shape.
The textFrame.textPathJustification property is used to align the text inside the path (center, left, or right).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Something is not right because pathItems attribute doesn't exist in Document objects.
Copy link to clipboard
Copied
Something is not right because pathItems attribute doesn't exist in Document objects.
By Luis27099811ehw5
Because this code is for Illustrator - not InDesign.

