10 Replies Latest reply on Jul 26, 2013 4:17 AM by Flynn lives

    Copy paste anchored objects in a table

    Flynn lives

      Hi all!

      I must design very often posters with a lot of brands logos  (events sponsors) distribuited like anchored objects in the cells of a table.

      Very frecuently, the list of brands changes after designed the poster, adding or deleting someones, and then i must replace the logos one by one.

      I'm programming a script that moves the content of the cells, making space to the new inserts, or filling the space leaved by brands out. I use the "content" property of the object "cell", and it really works with text (its useful for me in others cases, anyway) but it makes absolutly nothing with the anchored objects.

      Somebody have any idea that can help me?

       

      Thanks for your help, and sorry for my english!

       

      Jose

        • 1. Re: Copy paste anchored objects in a table
          Laubender Adobe Community Professional & MVP

          Consider using  Texts objects.
          An anchored object is nothing but a character in a Texts object.

           

          Uwe

          1 person found this helpful
          • 2. Re: Copy paste anchored objects in a table
            Laubender Adobe Community Professional & MVP

            Something around:

             

            var myFormattedText = myTable.cells[0].texts[0];
            myFormattedText.move(LocationOptions.AFTER,myTable.cells[1].texts[0].insertionPoints[0]);
            

             

            Uwe

            1 person found this helpful
            • 3. Re: Copy paste anchored objects in a table
              Laubender Adobe Community Professional & MVP

              Oh, and what is very helpful:

               

              The parent of an anchored object is a Character Object.

               

              Example 1:

              A text frame with an anchored object (the magenta square).
              The text frame is selected.

               

              1_AnchoredObject_TextFrameSelected.png

              If you ask for the count of characters in the text frame:

               

              app.selection[0].characters.length;
              

               

              The answer is "5"!
              The anchor, that is indeed the anchored rectangle, is treated as a character.

               

              If you select the anchored object and ask for its parent:

               

              app.selection[0].parent;
              

               

              The answer is "[object Character]".

               

              To move such an anchored object without loosing its anchordness, you have to move the character.

               

              In the above case, the character is characters[0] of the text frame. Or more precise, the characters[0] of texts[0] (all formatted text in the text frame) of the text frame. You also could go a step backward and say: in this case it's the characters[0] of texts[0] of the parentStory of the text frame

               

              To move it somewhere else (e.g. to a cell of a table), you must move it to another Text object.
              Every insertion point is a text object (like every character).

               

              Example 2:


              A table comes into play:

              2_ATable_BeforeScript.png

              The text frame is still selected.
              And the following code will move the anchored object (indeed the character) to the table:

               

              var myTextFrame = app.selection[0];
              var myTable = myTextFrame.parentStory.tables[0];
              
              myTextFrame.characters[0].move(LocationOptions.AFTER, myTable.cells[0].insertionPoints[0]);
              

               

              Situation after executing the snippet:

               

              3_ATable_AfterScript.png

               

              Hope that helps,
              Uwe

              • 4. Re: Copy paste anchored objects in a table
                Flynn lives Level 1

                Thank you very much, Uwe!!

                You have worked hard solving the question! Im very surprised and pleased!

                 

                Its works FINE!

                 

                Again, thank you!!!

                 

                Best regards,

                Jose

                • 5. Re: Copy paste anchored objects in a table
                  Flynn lives Level 1

                  One more question:

                  And what if the object (image) was pasted, no anchored, in the cell??? Then it hasnt insertion point, images pasted_table.jpg

                  but the object is anchored, anyway...

                  pasted but anchored copia.jpg

                  Thanks!

                  Jose

                  • 6. Re: Copy paste anchored objects in a table
                    Laubender Adobe Community Professional & MVP

                    An object pasted like that is an inline anchored object. No big deal…
                    Also represented as a Character object.


                    Every single cell as shown in your screen shot should have a

                     

                    myTable.cells[n].texts[0].insertionPoints.length

                     

                    of "2"

                     

                    Uwe

                    1 person found this helpful
                    • 7. Re: Copy paste anchored objects in a table
                      Flynn lives Level 1

                      THANKS!!!

                       

                      best regards,

                      Jose

                      • 8. Re: Copy paste anchored objects in a table
                        Laubender Adobe Community Professional & MVP

                        Oh.

                        There is another thing that is missing (e.g. for a round trip from a character to the anchored object [e.g. the rectangle] and back):

                         

                        The Character object "contains" the rectangle with all properties and all settings (e.g. anchoredObjectSettings).

                         

                        myCharacterThatRepresentsTheAnchoredObject.rectangles[0].fillColor = "Yellow";
                        

                         

                        will fill the anchored object with color "Yellow" (in case it is a rectangle).

                         

                         

                        To get it in every case, be it a rectangle, an oval, a polygon etc., you could use the higher level class "SplineItem" or even "PageItem". A caution here. It's best, that you first will "resolve" the specific object out of that class, before applying a property.

                         

                         

                        My example with the higher level "PageItem" class will work with just:

                         

                        myCharacterThatRepresentsTheAnchoredObject.pageItems[0].fillColor = "Yellow";
                        

                         

                        but may fail with other, none "SplineItems" (did not test that out entirely) like "Buttons", "MultiStateObjects" etc.

                        Resolving the specifier should work in any case (or at least will result in a meaningful error message ;-) ):

                         

                        myCharacterThatRepresentsTheAnchoredObject.pageItems[0].getElements()[0].fillColor = "Yellow";
                        

                         

                        Uwe

                        • 9. Re: Copy paste anchored objects in a table
                          Laubender Adobe Community Professional & MVP

                          Just one additional thing:

                          it could depend on the property you want to use when working with pageItems[0] like in my example.

                           

                          But I'm finding no negative example right now ;-)

                           

                          In any case, resolving the specific constructor of a page item is necessary, if you base some layout decisons on specific object types…

                           

                          Uwe

                          • 10. Re: Copy paste anchored objects in a table
                            Flynn lives Level 1

                             

                            Thanks, thanks, thanks.....

                             

                            Until now, all my works are with rectangles, so the job must be easier.

                             

                            I'm working with all your usefuls informations and I expect to have a script for my (almost) diary work!!!

                             

                            Thanks a lot!!!

                            Jose