3 Replies Latest reply on Sep 16, 2011 2:46 AM by milligramme

    cut paste image

    gijinj1

      Hi,

       

      Is there a way we can cut paste an image rectangle into a text frame without using app.cut() & app.paste() ?

       

      Thanks,

        • 1. Re: cut paste image
          milligramme Level 3

          Hi

           

          Is what you want do create Anchored Object without using cut() and paste()

          try this code.

           

          /**
           *  without using cut() and paste()
           * 
           * env>
           * a document has one textframe and graphicframe(rectangle)
           * 
           */
          var doc = app.documents[0];
          var org = doc.rectangles[0];// has an image
          
          var tf = doc.textFrames[0];
          var dup = tf.parentStory.insertionPoints[-1].rectangles.add();
          
          for (var j in org.properties) {
            try {
              dup[j] = org.properties[j];
            }
            catch(e){}
          };
          var relative_posi = [
            dup.geometricBounds[1] - org.geometricBounds[1],
            dup.geometricBounds[0] - org.geometricBounds[0]
          ];
          
          dup.place(org.graphics[0].itemLink.filePath);
          
          for (var i in org.graphics[0].properties) {
            try {
              dup.graphics[0][i] = org.graphics[0].properties[i];
            }
            catch(e){}
          };
          
          dup.graphics[0].move(undefined, relative_posi);
          // if you want move!
          // org.remove();
          

           

          thank you

           

          mg

          • 2. Re: cut paste image
            gijinj1 Level 1

            That is fine. But not working with documents created elsewhere. It throw the exception 'Can not find the folder --'. This is because it looks for the image path from where the image has been originaly placed. Is there any other alternatives?

             

            Thanks.

            • 3. Re: cut paste image
              milligramme Level 3

              Hi.

              is your operation system "Windows"?

              try this code

               

              var doc = app.documents[0];
              var org = doc.rectangles[0];// has an image
              var tf = doc.textFrames[0]; // bigger than image
              var dup = tf.parentStory.insertionPoints[-1].rectangles.add();
              for (var j in org.properties) {
                try {
                  dup[j] = org.properties[j];
                }
                catch(e){}
              };
              var relative_posi = [
                dup.geometricBounds[1] - org.geometricBounds[1],
                dup.geometricBounds[0] - org.geometricBounds[0]
              ];
              
              
              // mac or win?
              if (Folder.fs === "Macintosh") {
                dup.place(org.graphics[0].itemLink.filePath);
              }
              else {
                dup.place(encodeURI(File(org.itemLink.filePath).fullName);
              }
              
              
              
              for (var i in org.graphics[0].properties) {
                try {
                  dup.graphics[0][i] = org.graphics[0].properties[i];
                }
                catch(e){}
              }; 
              dup.graphics[0].move(undefined, relative_posi);