4 Replies Latest reply on Oct 30, 2013 1:05 PM by MadMich

    Spawning two templates to create second page, possible?

    MadMich Level 1

      I am not sure if this is possible but based on a value on the first page i want to be able to create a second page using two templates.

      My script below just creates two extra pages. Any ideas please?

       

       

      var t = this.templates;

      var j = this.pageNum;

         

      // this is my 3 templates, depending on the value of the first page the second will pick 2 of these templates

          var T = t[0];

          var S = t[1];

          var R = t[2];

       

      if (this.getField("P"+j+".Background.Dropdown4").value == "Other"){

       

          var XO = T.spawn(this.numPages, true, true);

       

          for (var i=0; i<0; i++) T.spawn(this.numPages, true, true, XO);

       

      }else if (this.getField("P"+j+".Background.Dropdown4").value == "Hair Colour"){

         

              var XO = T.spawn(this.numPages, true, true);

              var XY = S.spawn(this.numPages, true, true);

       

          for (var i=0; i<0; i++) T.spawn(this.numPages, true, true, XO);

          for (var i=0; i<0; i++) S.spawn(this.numPages, true, true, XY);

         

      }

       

      this.pageNum++;

       

      app.alert("A new page has been added")

        • 1. Re: Spawning two templates to create second page, possible?
          George_Johnson MVP & Adobe Community Professional

          It's possible, but I have to ask, what those "for" loops are supposed to be doing in the code you posted? When you spawn a new page, the bOverlay parameter should be false.

          • 2. Re: Spawning two templates to create second page, possible?
            MadMich Level 1

            Thanks for the comments, the loops were taken initially from the examples on the SDK site for another project which needed more than one page template, I've taken them out and retried with the bOverlay changed to false but it adds 3  templates of which two are the same?

             

            Heres my modified colde, any help would be much appreciated:

             

            var t = this.templates;

            var j = this.pageNum;

               

                var T = t[0];

                var S = t[1];

                var R = t[2];

             

            if (this.getField("P"+j+".Background.Dropdown4").value == "Other"){

             

                var XO = T.spawn(this.numPages, true, false);

                T.spawn(this.numPages, true, false, XO);

             

            }else if (this.getField("P"+j+".Background.Dropdown4").value == "Hair Colour"){

               

                    var XO = T.spawn(this.numPages, true, false);

                    var XY = S.spawn(this.numPages, true, false);

             

                T.spawn(this.numPages, true, false, XO);

                S.spawn(this.numPages, true, false, XY);

               

            }

            this.pageNum++;

             

            app.alert("A new page has been added")

            • 3. Re: Spawning two templates to create second page, possible?
              George_Johnson MVP & Adobe Community Professional

              Study this simplified sample code to see how this should be done:

               

              // Get references to two different templates

              var t1 = getTemplate("t1");

              var t2 = getTemplate("t2");

               

              // Create a new page based on the t1 template

              t1.spawn({nPage: numPages, bRename: true, bOverlay: false});

               

              // Overlay the t2 template on the new page

              t2.spawn({nPage: numPages - 1, bRename: true, bOverlay: true});

              • 4. Re: Spawning two templates to create second page, possible?
                MadMich Level 1

                Your a beautiful man George! That worked perfect.

                Thank you so much