Copy link to clipboard
Copied
I have been searching this forum and doing plenty of experimenting, and I can't figure out how to do this.
I select a polygon via
app.selection[0]
what i want is to insert a number in each polygon.to be after looping look like
appreciating your help
You get each Polygon and add TextFrame into Polygon :
var doc=app.documents[0];
var po=doc.pageItems[0];
var txt=po.textFrames.add();
txt.visibleBounds=po.visibleBounds;
txt.contents="1";
txt.paragraphs[0].justification=1667591796 ;
Copy link to clipboard
Copied
You get each Polygon and add TextFrame into Polygon :
var doc=app.documents[0];
var po=doc.pageItems[0];
var txt=po.textFrames.add();
txt.visibleBounds=po.visibleBounds;
txt.contents="1";
txt.paragraphs[0].justification=1667591796 ;
Copy link to clipboard
Copied
many THANKS, it works.
i want to understand the last line
txt.paragraphs[0].justification=1667591796 ;
Copy link to clipboard
Copied
set text center.
Copy link to clipboard
Copied
function insertPascalNumber(n){
myPolygon=app.selection[0];
myPolygonTextFrame=myPolygon.textFrames.add();
myPolygonTextFrame.visibleBounds=myPolygon.visibleBounds;
myPolygonTextFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
myPolygonTextFrame.contents=(n).toFixed();
myPolygon.textFrames[0].paragraphs[0].
applyParagraphStyle(app.activeDocument.paragraphStyles.item("Number",true));
}
my final script is
Copy link to clipboard
Copied
Hi daitranthanhoa,
here is a different concept.
I would work with groups.
One polygon is grouped with a corresponding text frame.
Why?
If a user changes dimensions of the group changes the dimensions of the text frame and the polygon will follow.
It's easier to maintain a couple of groups than a couple of polygons with nested text frames.
Two screenshots illustrating the problem:
Before resizing some selected objects:
After resizing some selected objects:
It's resizing, not rescaling! Rescaling is a different thing.
For all:
See also into this thread where a Pascal Number Generator by Saeed is discussed:
Titling the entries of array of array
Regards,
Uwe
Copy link to clipboard
Copied
Thanks Laubender !
That is good solution.
But if you can set Auto-Fit for parent object, child object will auto resize both.
Copy link to clipboard
Copied
Hi,
thanks for that.
Yes, using Auto-Fit on the hexagon container frame could be a solution for a nested text frame.
But as you may see from your screenshot it is working differenty than my group solution where both frames share the same dimensions. The dimensions of the text frame are no more the same after resizing.
BTW: I used a duplicate of the hexagon and converted that to a textframe.
FWIW:
Auto-Fit with Fit Frame Proportionally could be a dangerous thing if you are working with rotated container frames that are not rotated by 90°, 180° or 270°.
If you are resizing some selected hexagon containers that are rotated by e.g. 6.5° you will notice that the text in the nested text frame will be scaled. Just put the cursor in the text and see that there is a () attached to its point size.
Not so with my group solution.
Regards,
Uwe
Copy link to clipboard
Copied
Laubender wrote
… The dimensions of the text frame are no more the same after resizing.
No. I meant the dimensions of the text frame are not more the same as the hexagon container frame after resizing.
Sorry, if this was confusing.
And in fact if you are rotating the hexagon containers and then change the width of the selected objects the nested frames are scaled.
Not rotated and resized frame situation.
Nested text frame selected.
Rotated and resized frame situation.
Nested text frame selected.
Auto-Fit scaled the nested text frame to 100.8779 %.
Because of that the text is also scaled. Usually we do not want this if we simply like to resize elements.
And if we look more closely the text frame is not centered as it should.
Compare the position with my 0° example above. The corners of both frames will not fit anymore:
Regards,
Uwe
Copy link to clipboard
Copied
Now try this with a hexagon that is grouped with a text frame.
No scaling of the text frame after resizing the selected group and the other selected hexagon.
So I think it's way safer to work with groups than with nested text frames.
Regards,
Uwe
Copy link to clipboard
Copied
Or simply work with a stack of frames without grouping them:
Regards,
Uwe