3 Replies Latest reply on Nov 5, 2008 5:40 AM by numberonesuperguy

    Script: Creating layers and copy/pasting

    numberonesuperguy Level 1
      I have a JSON data structure that I import from a file, that defines a heirarchy that I need to recreate as a tree.
      At each point in the tree, I need to load an image and position it correctly on the screen (all data from my JSON file).

      I can write script to create the heirarchy (using addNewLayer() and addNewSubLayer() ) fine.
      I can write script to import all the graphics fine too.

      However, if I try to combine the two by importing the graphic at the point of creating the layer, it fails. Trying to create the next layer for the next graphic fails, with a '-1073741819' message.

      I've been stuck on this problem for days now, and I got to this point by getting stuck on other problems, so this is my last option for what I'm doing! (part of exporting graphics for Blu-ray production)

      The only other option of avoiding this cryptic error message would be to create the layers, then import the graphics afterwards, and then re-position the graphics in the correct layers...

      What WOULD be really really useful would be to get into email-or-otherwise conversation with the Fireworks javascript experts so that I could discuss the other dead-ends I came to (which is resulting in me going back to Photoshop for this last colour-reduction phase)

      Many thanks,

        • 1. Re: Script: Creating layers and copy/pasting
          numberonesuperguy Level 1
          I'm trying to get to the bottom of this, and after my loop of load-copy-paste of all my individual graphics into my main document, I tried to call fw.getDocumentDOM() again, and that call throws an error code of '-2147216341'.

          So, if copy-n-paste from one document to another (and then closing the one document) leaves FW in a state of 'I dont know what document im focused on', I think the question I need to ask is how do I tell FW to focus back on my original document? It must be hiding in the online docs somewhere...!
          • 2. Re: Script: Creating layers and copy/pasting
            numberonesuperguy Level 1
            Well for those of you interested, it seems doc.moveSelectionToLayer() will move layers around. (Thanks to the 'Arrange Commands' at Senocular.com).

            If there's anyone at Adobe who watches these forums, can I suggest that the APIs need changing so that the Layer object should contain its index (ie UID). If you write a function to find a layer by a pseudo path using 'doc.topLayers' then I can't find a reliable way to relate that back to an index in 'doc.layers'.

            I would still really appreciate any help on why I get exceptions when I open-n-cut-n-paste-n-close. *please!*
            • 3. Re: Script: Creating layers and copy/pasting
              numberonesuperguy Level 1
              Well it looks like what I really needed was doc.importFile().

              Many thanks to John Dunning for hosting a scripts ('Page Commands') that used this. It's in the FW documentation, but I obviously overlooked it. However, its funny (and reasuring) John was also having the same problem when using an alternate doc after calling doc.close().