• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

inserting numbers in a polygon

Community Beginner ,
Jun 20, 2017 Jun 20, 2017

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

TOPICS
Scripting

Views

832

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

Enthusiast , Jun 21, 2017 Jun 21, 2017

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 ;

Votes

Translate

Translate
Enthusiast ,
Jun 21, 2017 Jun 21, 2017

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 ;

Votes

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
Community Beginner ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

many THANKS, it works.

i want to understand the last line

txt.paragraphs[0].justification=1667591796 ;

Votes

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
Enthusiast ,
Jun 21, 2017 Jun 21, 2017

Copy link to clipboard

Copied

set text center.

Votes

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
Community Beginner ,
Jun 22, 2017 Jun 22, 2017

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

Votes

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
Community Expert ,
Jun 28, 2017 Jun 28, 2017

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:

Nested-vs-Grouped-PolygonAndTexFrame-BEFORE-RESIZING.png

After resizing some selected objects:

Nested-vs-Grouped-PolygonAndTexFrame-AFTER-RESIZING.png

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

Votes

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
Enthusiast ,
Jun 29, 2017 Jun 29, 2017

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.

SetAutoFit.png

Votes

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
Community Expert ,
Jun 29, 2017 Jun 29, 2017

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.

NestedFrame-AutoFit-FillProportionally-1.png

NestedFrame-AutoFit-FillProportionally.png

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

Votes

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
Community Expert ,
Jun 29, 2017 Jun 29, 2017

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.

AutoFit-TextFrame-SCALED-rotationAngle-not-90.png

Rotated and resized frame situation.

Nested text frame selected.

AutoFit-TextFrame-NOT-Scaled.png

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:

CornersWillNotFit.png

Regards,
Uwe

Votes

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
Community Expert ,
Jun 29, 2017 Jun 29, 2017

Copy link to clipboard

Copied

Now try this with a hexagon that is grouped with a text frame.

GroupedHexagonAndTexFrame.png

GroupedHexagonAndTexFrame-NoChangeInScalingAfterResize.png

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

Votes

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
Community Expert ,
Jun 29, 2017 Jun 29, 2017

Copy link to clipboard

Copied

LATEST

Or simply work with a stack of frames without grouping them:

StackedFrames.png

Regards,
Uwe

Votes

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