Stretching/translating a layer into another document

I probably just have my math wrong, but given a selection box boundary (or boundaries), I'm trying to resize it so that it's the size of a target document and then translate it so it's in the top-left corner taking up the whole screen (so what's in square selection takes up whole screen.  Now if I duplicate the layer in the same document and scale it using the document's dimensions and translate, it fills the whole screen.  However, if duplicate the layers into a target document and scale and translate according to its dimensions, the layer is the correct size, but wildly off position (most of the time off the page).  I would think the translation would be independent of the destination doc and based just on the scale and (minX,minY) of the selection box. 
Is my math off or is there something funny about duplicating a layer into another document?  I'm guessing it's the former, but I keep doing it in my head and the math looks sensible. 
var layer = app.activeDocument.activeLayer;
//layer.isBackgroundLayer = false;
var layers = new Array(thumbnails.length);
//layers[0] = layer;
for (var i = 0; i < layers.length; i++) {
    layers[i] = layer.duplicate(documentTarget);
var srcDocument = app.activeDocument;
app.activeDocument = documentTarget;
// for every layer, go through translating and resizing based on the box size
for (var i = 0; i < layers.length; i++) {
    var selectionBox = thumbnails[i];
    var scaleX = documentTarget.width.as("px") / (selectionBox["maxX"] - selectionBox["minX"]);
    var scaleY = documentTarget.height.as("px") / (selectionBox["maxY"] - selectionBox["minY"]);
    layers[i].resize(scaleX * 100, scaleY * 100, AnchorPosition.TOPLEFT);
    layers[i].translate(new UnitValue(-selectionBox["minX"] * scaleX, "px"),
                                new UnitValue(-selectionBox["minY"] * scaleY, "px"));

.. Why would minX,minY be different assuming the layer is duplicated to the topleft of the target document at 0,0?  
That was the point I was trying to make. That assumption is incorrect. The duplicated layer will not be at 0,0 unless both documents are the same size and resolution. The duped layer is centered in the new doc. Only when the sizes match will the positions match. Otherwise the new top left position could be anywhere including off canvas( negative values ).
If you don't want to change minX, minY for some reason you could add code to align the layer to the top left before the translate line.
function align(type){
   var desc = new ActionDescriptor();
     var ref = new ActionReference();
       ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Lnkd" ));
   desc.putReference( charIDToTypeID( "null" ), ref);
   desc.putEnumerated( charIDToTypeID( "Usng" ),charIDToTypeID( "ADSt" ), charIDToTypeID( type ) );
   executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );;
function alignTopLeft(){
  align("AdTp");
  align("AdLf");
app.activeDocument.selection.selectAll();
alignTopLeft();
app.activeDocument.selection.deselect();

Similar Messages

  • Using Photoshop scripting copy a layer and paste into another document at a particular selection

    I want to copy a layer of a document and paste it into another document in the particular layer selection..

    Thanks Badunit for your quick response
    I have found the answer - it is a incompatabilty between CopyPaste Pro and Numbers: -
    Thanks dbg1596 - solved my problem with which I wasted a good couple of hours getting more and more frustrated with numbers 3.0
    I had the same problem - copy a cell - paste into another cell and it created three vertical cells with the pasted data in the middle
    Definitely a problem between CopyPaste Pro - one of the most useful aps on my Mac for the last many years
    Once I quit CopyPaste Pro - no problem with pasting in Numbers 3.0
    But I use CopyPaste Pro all the time
    Have the folks responded to your query?
    But I use CopyPaste Pro all the time - hope that it can be sorted sooner rather than later

  • (NOT SOLVED) Duplicate layers into another document

    Hello, honorabe participants of Photoshop Scripting forum!
    I have a problem - how to implement in action/script duplication of two linked layers from one document to another already opened document? Linked layers is a specially formatted text, so I can't just copy-paste them into opened document. Already opened document is a CR2-file.
    When I record action, PS also record name of the reciever-document. But this name changes when I open another file so all acation breaks.
    PS can record 'Select next document' and 'Select previous document', but cant' record 'Duplicate layers into previous document'.
    Please, help me to solve my problem.

    Hi Borizzzed!,
    Try this.... one...!!!
    if ( app.documents.length >0 ) {
            var docRef = app.activeDocument
            var layerIndex = 0
            var visiblelayerCount = 0
            var activelayers = app.activeDocument.activelayers;
            var myLayers = docRef.layers;
            var selAlpha, Lname
            var Fname=prompt("Enter The file name with extension ...!","","Do Smart") // like temp1.jpg, yajiv.psd
            if (Fname!="")
            for (var layerIndex = visiblelayerCount; layerIndex < myLayers.length; layerIndex++) {
                selAlpha=docRef.layers.getByName(myLayers[layerIndex].name);
                Lname=myLayers[layerIndex].name; // Selected current layer name
                //alert(Lname);   
                DpLayer(Lname,Fname); // duplicate layer name to other Photoshop Document.
        function DpLayer(Lname,fname)
                var id766 = charIDToTypeID( "slct" );
                var desc45 = new ActionDescriptor();
                var id767 = charIDToTypeID( "null" );
                    var ref9 = new ActionReference();
                    var id768 = charIDToTypeID( "Lyr " );
                    ref9.putName( id768, Lname );
                desc45.putReference( id767, ref9 );
                var id769 = charIDToTypeID( "MkVs" );
                desc45.putBoolean( id769, false );
            executeAction( id766, desc45, DialogModes.NO );
            // =======================================================
            var id770 = charIDToTypeID( "Dplc" );
                var desc46 = new ActionDescriptor();
                var id771 = charIDToTypeID( "null" );
                    var ref10 = new ActionReference();
                    var id772 = charIDToTypeID( "Lyr " );
                    var id773 = charIDToTypeID( "Ordn" );
                    var id774 = charIDToTypeID( "Trgt" );
                    ref10.putEnumerated( id772, id773, id774 );
                desc46.putReference( id771, ref10 );
                var id775 = charIDToTypeID( "T   " );
                    var ref11 = new ActionReference();
                    var id776 = charIDToTypeID( "Dcmn" );
                    ref11.putName( id776, fname );
                desc46.putReference( id775, ref11 );
                var id777 = charIDToTypeID( "Vrsn" );
                desc46.putInteger( id777, 2 );
            executeAction( id770, desc46, DialogModes.NO );

  • Cpy/paiste group into another document

    hello forumers.
    im trying to copy/paiste my group(consists of 10layers) from one ps document into another.is this possible?
    im selecting all its paisting it into my other document,but all the layers are merged.i need it to come into the document as a group wiht all its layers.
    thank you.

    jeffrey your a life savour thanks 1000
    best regards.

  • How do I merge multiple artboards into another document?

    I am working on a team, and we'd like to combine our work into a master document that contains all of our different artboards.
    I have a UI document set up with multiple sets of different artboards.  I.E. a row of 32x32 artboards with individual small icons, a row of 60x60 artboards with bigger icons, etc. so recreating these would be very cumbersome.
    I know it's possible to just copy paste everything into one document, but what is the strategy for copying the artboards as well?
    I'm currently looking at having to rebuild the artboards in the master document, so any help would be MUCH appreciated!!  Thank you.
    -Nick

    Ah that's something! I drew 32x32 rectangles around my icons, copied rectangles+icons over to new document.  Then selected just the rectangles around the icons and did Object > Artboards > Convert to Artboards
    Now I just have to rename them again, which is not as bad as recreating each one.  That's pretty awesome, thank you Monika!
    Further question for Monkia/Adobe/comminuty: is there an even more automatic way to merge artboards from two files together?  Ideally it would just merge all the artboards to a new file (in the same place, etc).
    The Artboard feature makes Illustrator a very viable tool for app UI design (center icons in individual art boards, export with transparency, at different resolutions etc).  Having icons be symbols is also useful - change an icon, it propagates throughout the layout.
    However, not being able to merge artboards (with respective names) from different files prevents it from being terribly useful for teams.
    I found a discussion regarding a script for CS5 by CarlosCanto that seems to do this, but it doesn't work on CS6:
    http://forums.adobe.com/thread/954411
    Again, thank you Monika, your advice just saved me a TON of time, and I hope this feature makes it into future versions of Illustrator.
    -Nick

  • After hiighlighting a word and pasting it into another document, the clipboard does not clear ;when I hit enter it pastes again and again. How do I fix it?

    When I highlight a word or phrase and copy to the clipboard, then paste it in another area the clipboard does not clear the phrase. Therefore, every time as I type and hit the enter key it continues to paste the phrase all over my document. I do have the latest download of Firefox installed (16.0, win 7 and that is when this started. How do I stop this obnoxious behavior so I can type a sentence with normalcy?
    Louise

    Thank you, Iusually do that first thing with any computer problems. Old school computer fix. Hard Boot regardless! lol Thanks again.

  • Know any reason why color swatch coverts to black when I copy and paste into another document?

    I keep having issues when I copy and paste a table from one document to the next. Some of the PMS ink colors convert to black. Anyone have a clue?

    In colors in the table or elsewhere in the file? Are you using table or cell styles? If so, did you define new ones or redifine the defualts? The general principle to remember when moving content from file to file is that anything like styles or swatches that appear with the same name in both documents will use the definition from the receiving file.
    Anothe possibility, though less likely, is that you've used the ink manager to alias the spot color to black.

  • Is there a way I can type in English but have it translate my words into another language?

    I speak english.  I want to be able to type the English words and have them translated into other languages.  Japanese kanji, katagana, hiragana in my specific case.  I tried using text input, but it just translates a letter at a time making my word a mix in English letters and Katagana characters. 

    seraph6496 wrote:
    I want to be able to type the English words and have them translated into other languages.
    Not now. Maybe in a few years or so. Or maybe never, if you stop to think about it.
    There are several free automatic translators on the web. You can find them by googling it. (Your Dashboard translator uses Systran's.)
    I tried using text input
    I assume you mean you enabled Kotoeri, the Japanese input method. This is for those who wish to type in Japanese. It's not a translating tool.

  • Is it possible to insert a document into another?

    I would like to insert a document into another document without cutting and pasting. That is, to "insert" it into the present document. I have been unable to find that option. Is it possible?

    It would seem a logical function, though Pages is in essence a $30.00 program so it's not going to have all the features one might wish. You can submit feedback to Apple on the issue here, though:
    http://www.apple.com/feedback/pages.html
    Regards.

  • JTextPane: Insert one (part of) a Document into another

    Hi,
    I am writing a small programm which user a JTextPane and a
    StyledDocument with
    an RTFEditorKit.
    Now I have the problem that I want to get one Document, transport it
    over
    a network and insert it into another Document.
    The only method in Document to insert sth needs a string but I have a
    Document.
    So my question is: How can I insert one Document into another or at
    least append
    one Document to another?
    Thanks
    Frank

    Hi, it is much more simpler than i thaught.
    use the getLength method of the Document-Interface.
    e.g.:
                    InputStream in1; // Streams of your Files
         InputStream in2; // Streams of your Files
         RTFEditorKit rtf = new RTFEditorKit();
         Document doc = rtf.createDefaultDocument();
         try{
             rtf.read(in1, doc,0);
             int x = doc.getLength();
             rtf.read(in2,doc,x);
         }catch(BadLocationException ble){
         }catch(IOException ioe){
         }use this value in the read-method as pos and your second doc is concated to the first.
    Or any other pos you like.
    Hope this is what you are lokking for.
    Greetings Michael
    read
    public void read(InputStream in,
                     Document doc,
                     int pos)
              throws IOException,
                     BadLocationException
        Insert content from the given stream which is expected to be in a format appropriate for this
        kind of content handler.
        Overrides:
           read in class DefaultEditorKit
        Parameters:
           in - The stream to read from
           doc - The destination for the insertion.
           pos - The location in the document to place the content.
        Throws:
           IOException - on any I/O error
           BadLocationException - if pos represents an invalid location within the document.

  • How to insert a pages document into another pages document?

    How can I insert a pages document into another one?
    How can I insert 1 page of a document into another document?

    Open your files & show thumbnails. Sections have a yellow border around all of the pages in that section. Now click on the page in the thumbnail pane & copy. If the file is more than one page & you only want one, you'll need to insert a section break to separate the pages. Then go to your other file, click in the thumbnail pane & paste. The whole copied page will be pasted in. Repeat with another section. Styles will copy over with the sections but headers & footers will not.

  • How to transfer (copy/move/paste) group layer to another page or file?

    Hi
    I wanted to transfer a set of group layer to another page in Fireworks CS5, how can I do that?
    When I try to copy paste, it doesnt paste as a group instead paste as layers, then I have to again group it and name it Why Fireworks doesn't understand that I have copied a set of group layer?

    You can share a layer to another page in Fireworks by selecting the layer in the Layers panel, then clicking on the small fly-out menu in the upper-righthand corner of the Layers panel and choosing "Share Layer to Pages". This opens up a two-column dialog, where can select the new page and add it to the right-hand column, "Include layer to page(s)".
    As far as moving a layer into another file, you may need to use a Command like "L - Copy to Next Doc" from John Dunning's Frame and Layer Utilities command set:
    http://johndunning.com/fireworks/about/FrameLayerUtils

  • How can i translate a document into another language?

    I am trying to translate a script into Spanish. The document is secured - which is my first problem - and also - i cannot find a way to translate it?! Any and all help would be much appreciated - thanks!

    Hi elyssap
    If document allows you to copy and paste the text then you can use google Translator to translate to another language.
    Refer ; https://translate.google.com/
    ~Mandy

  • Copy and paste layer mask into another layer mask

    I know there is a way to do this.
    How can I copy and paste on layer mask into another.
    I need to use the same mask for multiple layers and images.
    Thanks

    In the same document, click on the layer mask, option drag to a new layer
    To copy mask to a different document with both documents open, select the layer, Duplicate Layer to the other document (destination). Then in the other document, option drag the mask to whatever layer you want, delete the layer you duplicated (you don't need it anymore, you just needed the mask)
    Or to copy mask to a different document with both documents open, load mask as a selection. Save selection to the other document (destination). Then in the other document load the new alpha channel and apply as a layer mask. Delete the alpha, you don't need it anymore.
    Edit: J always beats me to it

  • How can I merge documents with layout written with pages? How can I copy pages-document with layout and paste it into another pages document?

    Hi
    I am working with pages for a book and have made already a layout whre photos and graphs etc. are partly outside of the area for the text, their posotion is not fixed the the text.
    And now I nedd support: When I add text or a photo to the layout the text moves and the unfixed photos etc. keep there position. This means I have to update each photo or graph to shift it to the new position ore I have to place photos etc. within the frame of the text, which is not the kind of layout I am going for.
    I hope for two reliefs, which I do not know how to realize it.
    1. If I specify each chapter as a new partition starting with own page (then I hoped) the new section would shift together into a new page and the positions of photos etc. and text would stay fix. But unfortunately this seeems not to be the case. Question: is this possibe orno? If yes, how to do it?
    I could divede the whole txt chapter by chapter into individual documents, which are seperatly created and worked. At the end I would have to merge all this document into one. Is it possibe to merge different pages-document into one document?
    Who can help me?
    Thanks Hartmut

    Images and other object can either be floating or be inline. Yours are floating and will not move with the text. Inline object will move with the text but can't be outside the text layer. It doesn't help if you have created section in the document. Floating images doesn't care. Nor will it help if you create several documents that you want to merge later. Doesn't make any difference.
    My suggestion is that until your text is finished you have the images inline. Then as a last editing you can start make the images floating and move them a little.

Maybe you are looking for

  • Re: Query for Cost center actual by period.

    Hi Experts, Good Morning everybody, I want cost center actual values (with cost element) by period. I have created query through T.code-SQVI by joining tables COSP and CSKS. I got the report, but i cannot see the foreign currency postings in SQVI rep

  • Reading an external file

    I'm new to Acrobat scripting though I've done some for JavaScript for InDesign. It seems very different and I'm having difficulty wrapping my head around it. I need to open and read an external text file that contains names of PDF files. Then, I need

  • My new Lenovo IdeaPad N580 not working well :(

    Hello, I have a Lenovo IdeaPad N580 with build-in windos 8 OEM. I got from my uncle, came from abroad. now a days it does not wark as well. Problems, 1. Sometimes touchpad seems to be hanging when I working. But with external usb mouse it works fine.

  • How to delete WBS  if system status is REL

    How to delete WBS at 2nd level if system status is REL (no cost have been populated yet). What happened is that system is set to auto release when created.

  • Two Users can connect to apleu3test02 but not each other

    Hello, I have been trying to connect to with my wife whom is on a road runner cable modem behind a belkin wireless router. I am on a comcast cable modem behind a linksys wrt54gv4 router, however it is flashed with an open source firmware. Both of us