12 Replies Latest reply on Nov 10, 2014 12:17 PM by Chuck Uebele

    Photoshop 2014.2 bug with duplicating layers in different doc

    matias.kiviniemi Level 3

      Encountered an issue with Photoshop 2014.2 that occurs when I try to use some_basic_bitmap_layer.duplicate(some_layer_in_different_doc, ElementPlacement.PLACEAFTER). So this is code that has been pretty much unchanged for a year and works in CS6 and CC2012 and used to worked in CC2014.1. I use .duplicate() with docs and with layers inside same doc, but this is the one giving exception:

      General Photoshop error occured. This functionality may not be available in this version of Photoshop.

      - The object " <unknown> of layer 2" is not currently available

       

      Another strange thing is is that in ESTK debugging the exception surfaced in a bit different places depending on factoring. I.e. before I added more detailed exception catching, it occured later in code. But this place is the only spot there is a layer named "layer 2". But gives me the feeling it's an internal state corruption

       

      I'm guessing it might so specific no-one else will hit it, but I'd like to ask

      - Any workarounds you can think of?

      - Any ways to directly escalate it to Adobe given it's a new release. The general feedback site seems a waste of effort.

      - Any way to downgrade (in a way that normal users could do it also) to 2014.1?

        • 1. Re: Photoshop 2014.2 bug with duplicating layers in different doc
          pixxxel schubser MVP & Adobe Community Professional

          matias.kiviniemi,

          please show us a screenshot of your picture including the layers palette and also the real Javascriptcode.

           

          Otherwise: Sorry, my crystal ball is on repairs...

          • 2. Re: Re: Photoshop 2014.2 bug with duplicating layers in different doc
            matias.kiviniemi Level 3

            It's quite complex.. Before the offending line several hundreds of lines code has been run. But I managed to squeeze it to a small replicable format. I.e. below code runs in CC2012 but fires an exception in CC2014.2. Code is funny, but it's basically the steps of doc manipulation that happens in minimal case. Should work on any PSD, but you can get an example from here: Dropbox - bug_report.psd

             

            try {
                var original_doc = app.activeDocument
                var  copy_doc = original_doc.duplicate("copy_doc", false) // duplicate original
                var export_doc = app.documents.add(original_doc.width, original_doc.height, original_doc.resolution, "export_doc", NewDocumentMode.RGB, DocumentFill.TRANSPARENT) // create empty export doc
                app.activeDocument = copy_doc   // select copy and first layer of it
                var layer = copy_doc.artLayers[0]
            
            
                // create dummy layer to merge to to flatten all vector & style data
                var tmp_layer =  copy_doc.artLayers.add()
                tmp_layer.move(layer, ElementPlacement.PLACEAFTER)
                layer = layer.merge()
            
                // copy layer to export doc
                layer.duplicate (export_doc.artLayers[0] , ElementPlacement.PLACEAFTER)
            } catch (e) {
                alert(e.message)
            } finally {
                copy_doc.close(SaveOptions.DONOTSAVECHANGES)
                export_doc.close(SaveOptions.DONOTSAVECHANGES)   
            }
            
            
            • 3. Re: Re: Re: Photoshop 2014.2 bug with duplicating layers in different doc
              pixxxel schubser MVP & Adobe Community Professional

              Okay, thx.

              I do not work with CC – but did you check this?

              var original_doc = app.activeDocument;
              var  copy_doc = original_doc.duplicate("copy_doc", false); // duplicate original 
              var export_doc = app.documents.add(original_doc.width, original_doc.height, original_doc.resolution, "export_doc", NewDocumentMode.RGB, DocumentFill.TRANSPARENT); // create empty export doc 
              app.activeDocument = copy_doc;   // select copy and first layer of it 
              var layer = copy_doc.artLayers[0];
              if (!layer.isBackgroundLayer) {
                  //alert ("is not background")
              if (layer.visible == true) {
                  //alert ("visible")
              if (!layer.allLocked) {
                  //alert ("not locked")
                  alert("Did you check this all?")
                  }
              }
              }
              
              • 4. Re: Re: Photoshop 2014.2 bug with duplicating layers in different doc
                matias.kiviniemi Level 3

                Thanks. They are checked for being locked and can't be background since in the real case it'll always be a layer in group. Invisible it might be, but has not mattered so far.

                 

                And in the example PSD (and any that I've tried) that causes an exception these are all OK.

                • 5. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                  Tom Ruark Adobe Employee

                  We are working on a fix for this. The work around would be to use Action* instead of the DOM. Use ScriptListener to generate the code for you.

                  • 6. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                    Chuck Uebele Adobe Community Professional & MVP

                    Tom, there is a flaw in trying to use ScriptListener code to duplicate one or more layers from one document to another, which is what the OP seems to be saying. If you generate the code, there is no way to specify which layer is to be duplicated, and it will throw an error. See bug 3783024.

                    • 7. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                      Chuck Uebele Adobe Community Professional & MVP

                      One thing I'm seeing in your code is that you're not checking to see if you are trying to move the layer after a background layer. Either make sure layer[0] is not a background layer, if it is convert it to a normal layer, or use PLACEBEFORE.

                      • 8. Re: Re: Re: Photoshop 2014.2 bug with duplicating layers in different doc
                        matias.kiviniemi Level 3

                        Thanks for the feedback!

                         

                        The sample code is meant for the sample psd, so it's playing on assumption that there is only one layer that is not background, is visible and not locked. In the production code it's always inside a group so it's not a background and we check for locked. Visibility we don't check but it has not been the case in the PSDs we've replicated this in.

                         

                        However playing with this I did manage to find a workaround: it's possible to duplicate the layer to beginning of doc and then move it like below.

                        try {

                            var original_doc = app.activeDocument

                            var  copy_doc = original_doc.duplicate("copy_doc", false) // duplicate original

                            var export_doc = app.documents.add(original_doc.width, original_doc.height, original_doc.resolution, "export_doc", NewDocumentMode.RGB, DocumentFill.TRANSPARENT) // create empty export doc

                            app.activeDocument = copy_doc   // select copy and first layer of it

                            var layer = copy_doc.artLayers[0]

                         

                         

                            // create dummy layer to merge to to flatten all vector & style data

                            var tmp_layer =  copy_doc.artLayers.add()

                            tmp_layer.move(layer, ElementPlacement.PLACEAFTER)

                            layer = layer.merge()

                         

                         

                         

                            var duplicate = layer.duplicate (export_doc , ElementPlacement.PLACEATBEGINNING)

                            app.activeDocument = export_doc

                            var dummy = export_doc.artLayers.add()

                            var target = export_doc.artLayers.add()

                            duplicate.move(target, ElementPlacement.PLACEAFTER)

                        } catch (e) {

                            alert(e.message)

                        } finally {

                            copy_doc.close(SaveOptions.DONOTSAVECHANGES)

                            export_doc.close(SaveOptions.DONOTSAVECHANGES)   

                        }

                         

                        Also if I try to move duplicated layer without setting the active document Photoshop raises the same exception "The object " <unknown> of layer 2" is not currently available". I.e. it's hitting some internal issue instead of giving the right error of "not allowed to move layers in non-selected document". It kind of makes sense, i.e. duplicating to different doc after certain layer is a combo operation that duplicates to different doc and moves and they different requirements (what is the active doc).

                        • 9. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                          Chuck Uebele Adobe Community Professional & MVP

                          Yes, you have to have the doc from which you're moving the layer from as the front document. So far, I haven't had any issues with duplicating a layer using PLACEAFTER, as long as I'm not trying to place it after a background layer. I wrote a extension panel that moves and duplicates multiple layers within the current document and to different documents. So far I haven't had any issues with it, as long as I have the error checking for that background layer.

                          • 10. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                            matias.kiviniemi Level 3

                            Well, I never had issues before CC 2014.2 (still works fine in CC 2012 and CS6), have you tested that? It might also be dependant on the layer internal state, i.e. that merge might matter.

                            • 11. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                              Tom Ruark Adobe Employee

                              @csuebel, In the bug you have this step: "Drag one of more layers from one document to another." If you turn on actions recording you will note that the "duplicate the layer" action never occurred but you only got a "select document" event. This is the bug that should be reported, the fact that the duplicate event was never reported. Remember that everything does not get recorded via user actions and you might need to think of alternatives. "Insert Menu item" is one that comes to mind.

                               

                              To get ScriptListener and the actions panel to capture this event, 1) select the layers you want copied, 2) use the flyout menu on the layers panel to "Duplicate Layer..." and then use the dialog to get the layers into your other document. You might need to move the layer after it arrives in the other document.

                               

                              I believe you can use all the other steps using the DOM code and only replace the duplicate command in this example.

                               

                              NOTE: Our layer indexing and id capturing is the bug. If you are dealing with multiple documents with different layer structures you are going to hit that bug. I would recommend using ScriptListener code or always using the activeDocument and activeLayer to work around this problem. The merge() in the example above is what causes the indexing and id's to go out of sync. Ps is trying to get the index of the active document and not the layer from the other document.

                              • 12. Re: Photoshop 2014.2 bug with duplicating layers in different doc
                                Chuck Uebele Adobe Community Professional & MVP

                                Thanks, for that insight, Tom. I didn't think about using the layer's panel to record the duplicate.