7 Replies Latest reply on Nov 12, 2018 8:57 PM by franz joelv69400054

    Move objet below the text line

    franz joelv69400054 Level 1

      Hi,

      I need help, I'm a novice in javascript, but I like to automate my query is after pasting the object into the text line, it is possible to move the same height of the object down and after apply textwrap

       

      1.jpg

       

      in this way

       

      2.jpg

       

      Thanks for your help

        • 1. Re: Move objet below the text line
          S Hopkins Adobe Community Professional

          Rectangle that holds placed image has a number of properties that are part of the anchoredObjectSettings. The following snippet may help. This where placedRef is a reference to the placed object and ancSettings is the anchored settings property record. You will need to set other properties to control the horizontal settings.

          var yOffset = "10pts";

          var placedRef = insRef.place(myFile);

          var imageRef = placedRef[0];

          var rectRef = imageRef.parent;

          var ancSettings = {anchoredPosition:AnchorPosition.ANCHORED,

              anchorPoint:AnchorPoint.TOP_LEFT_ANCHOR,

              verticalReferencePoint:VerticallyRelativeTo.LINE_BASELINE,

              verticalAlignment:VerticalAlignment.TOP_ALIGN,

              anchorYoffset:yOffset};

          rectRef.anchoredObjectSettings.properties=ancSettings;

          Hope this helps

          1 person found this helpful
          • 2. Re: Move objet below the text line
            franz joelv69400054 Level 1

            Hi S Hopkins thanks for your help,the script is great but I would like the image to be kept within the text line and not as an anchored object.

            • 3. Re: Move objet below the text line
              S Hopkins Adobe Community Professional

              Oops, that's what we get for assuming. Maybe the following will help:

              To move a page item relative use the move method with undefined:

              app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

              rectRef.move(undefined, [0, 72]); //moves item vertically 72 points

               

              To move a page item given a specific measurement use move without undefined.

              To calculate the position of the item relative to the last line of a paragraph, use the line's baseline property

               

              var yOffset = 36;

              app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

              var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;

              //Baseline includes the top margin, so you need to subtract that:

              var marTop = myPage.marginPreferences.top;

              bLine = bLine - marTop;

              var x0 = rectRef.geometricBounds[0];

              var yPosition = bLine + yOffset;

              rectRef.move([x0,yPosition]);  //moves item to page position 36 points below referenced paragraph

              1 person found this helpful
              • 4. Re: Move objet below the text line
                franz joelv69400054 Level 1

                I appreciate your help but only position the first image correctly, and how to make the yOffset variable capture the value of the height of the selected object, something like yOffset=app.selection [0].height

                 

                3.jpg

                 

                var yOffset = 123.405;

                var rectRef=app.selection[0]

                var myPage=app.activeWindow.activePage;

                app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

                var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;

                //Baseline includes the top margin, so you need to subtract that:

                var marTop = myPage.marginPreferences.top;

                bLine = bLine - marTop;

                var x0 = rectRef.geometricBounds[0];

                var yPosition = bLine + yOffset;

                rectRef.move([x0,yPosition]);  //moves item to page position 36 points below referenced paragraph

                rectRef.textWrapPreferences.textWrapMode =TextWrapModes.JUMP_OBJECT_TEXT_WRAP;

                • 5. Re: Move objet below the text line
                  payalm68947498 Level 2

                  Hi Franz,

                   

                  var AncFrame = app.documents[0].pages[0].textFrames.add();

                  AncFrame.place("ImagePath+ImageName");

                  AncFrame.textWrapPreferences.textWrapMode =TextWrapModes.jumpObjectTextWrap;

                  • 6. Re: Move objet below the text line
                    S Hopkins Adobe Community Professional

                    Not too sure what you mean by "selection"; hopefully you mean the last-placed image.

                    The following places images from an array below the first paragraph of the page. They will be placed 200px from the left and left aligned with 8 pts gap (space) between:

                    var placedItem, imageRef, rectRef, gBounds, yPos, x0;

                    var yOffset = 36; //gap below first paragraph

                    var yGap = 8; //gap between images

                    var x0=200;

                    var myFiles = getFile ("Choose files", "*.png", true);

                    var myPage = app.documents[0].pages[0];

                    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

                    var bLine = myPage.textFrames[0].paragraphs[0].lines[-1].baseline;

                    var marTop = myPage.marginPreferences.top;

                    yPos = (bLine + marTop) + yOffset;

                    for (i=0; i<myFiles.length; i++){

                    placedItem = myPage.place(myFiles[i]);

                    imageRef = placedItem [0];

                    rectRef = imageRef.parent;

                    gBounds = rectRef.geometricBounds;

                    rectRef.move([x0,yPos]);

                    rectRef.textWrapPreferences.textWrapMode =TextWrapModes.JUMP_OBJECT_TEXT_WRAP;

                    yPos = yPos + (gBounds[2]-gBounds[0] + yGap);

                    }

                     

                    function getFile (filePrompt, typeFilter, useMultiple) {

                    var fileRef = File.openDialog(filePrompt, typeFilter, useMultiple);

                    if (fileRef==null) {

                        throw ("User cancelled");

                        } else {

                            return fileRef;

                         }

                    }

                     

                    This should give you something to play with.

                    • 7. Re: Move objet below the text line
                      franz joelv69400054 Level 1

                      thanks, I was able to solve what I wanted