10 Replies Latest reply on Jun 29, 2017 4:36 AM by Laubender

    inserting numbers in a polygon

    Saeedfs Level 1

      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

       

       

        • 1. Re: inserting numbers in a polygon
          daitranthanhoa Level 1

          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 ;

          • 2. Re: inserting numbers in a polygon
            Saeedfs Level 1

            many THANKS, it works.

            i want to understand the last line

            txt.paragraphs[0].justification=1667591796 ;

            • 3. Re: inserting numbers in a polygon
              daitranthanhoa Level 1

              set text center.

              • 4. Re: inserting numbers in a polygon
                Saeedfs Level 1
                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

                • 5. Re: inserting numbers in a polygon
                  Laubender Adobe Community Professional & MVP

                  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

                  • 6. Re: inserting numbers in a polygon
                    daitranthanhoa Level 1

                    Thanks Laubender !

                    That is good solution.

                    But if you can set Auto-Fit for parent object, child object will auto resize both.

                    SetAutoFit.png

                    • 7. Re: inserting numbers in a polygon
                      Laubender Adobe Community Professional & MVP

                      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

                      • 8. Re: inserting numbers in a polygon
                        Laubender Adobe Community Professional & MVP

                        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

                        • 9. Re: inserting numbers in a polygon
                          Laubender Adobe Community Professional & MVP

                          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

                          • 10. Re: inserting numbers in a polygon
                            Laubender Adobe Community Professional & MVP

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

                             

                            StackedFrames.png

                             

                            Regards,
                            Uwe