4 Replies Latest reply on Sep 17, 2009 7:23 AM by Ken Krugh

    Adding Sections

    Ken Krugh Level 1

      I have a script that adds a spread and creates sections to renumber the pages as necessary.


      Everything works fine as long as I'm BEFORE any other sections in the document. If I try to run it AFTER any other sections I'm getting an error of "Method 'Add' of object 'Sections' failed" though I can't see why.


      It doesn't matter whether my script created the sections or I created it manually on the pages pallet.


      Any ideas on why it works before but not after?


      Many thanks,


        • 1. Re: Adding Sections
          Harbs. Level 6

          Let's see the script and maybe we can figure out the problem...



          • 2. Re: Adding Sections
            Ken Krugh Level 1

            Thanks you Harbs,


            If the fact that I'm in VB (should have mentioned this before, sorry) is more of a hassle than it's worth for you I completely understand.


            From everything I can tell while debugging everything has the value it needs and it WORKS perfectly as long as there are no prior sections in the document.


            TheSprd is the spread the user is on, NextSprd is the spread following that, if there is one.


            On NextSprd it turns off AllowShuffle and starts a new section with that same page number.

            It then inserts a spread aftter TheSprd and makes the new spread start a section that is numbered for the page that precedes it with a and b (121a and 121b).


            I initially had it inserting the spread, renumbering the new spread then renumbering the spread following the new spread but couldn't add the 2nd section. Hense the commented-out code at the bottom.


            Thanks again,



                Dim Reslt$, PgsCount%, TheSprd As InDesign.Spread, TheSec As InDesign.Section, NextSprd As InDesign.Spread, PreFix$

                Set IPage = Ind.ActiveWindow.ActivePage
                Set TheSprd = IPage.Parent
                If TheSprd.Pages.Count > 1 Then Set IPage = TheSprd.Pages(2)
                If TheSprd.Index < IDoc.Spreads.Count Then 'set the next spread page number
                    Set NextSprd = IDoc.Spreads(TheSprd.Index + 1)
                    NextSprd.AllowPageShuffle = False
                    Set TheSec = IDoc.Sections.Add(NextSprd.Pages(1))
                    With TheSec
                        .ContinueNumbering = False
                        .PageNumberStart = CLng(IPage.Name) + 1
                        .SectionPrefix = ""
                        .IncludeSectionPrefix = False
                    End With
                    NextSprd.AllowPageShuffle = True
                End If
                PreFix$ = IPage.Name
                Set TheSprd = IDoc.Spreads.Add(idAfter, TheSprd)
                TheSprd.AllowPageShuffle = False
                Set IPage = TheSprd.Pages(1)
                Set TheSec = IDoc.Sections.Add(IPage)
                With TheSec
                    .ContinueNumbering = False
                    .PageNumberStart = 1
                    .PageNumberStyle = idNumberingStyle.idLowerLetters
                    .SectionPrefix = PreFix$
                    .IncludeSectionPrefix = True
                End With
            '    If TheSprd.Index < IDoc.Spreads.Count Then
            ''        Set TheSprd = IDoc.Spreads(TheSprd.Index + 1)
            '''        Set IPage = TheSprd.Pages(1)
            '''        Set Ind.ActiveWindow.ActivePage = IPage
            ''        Set TheSec = IDoc.Sections.Add(TheSprd.Pages(1))
            ''        With TheSec
            ''            .ContinueNumbering = False
            ''            .PageNumberStart = CLng(PreFix$)
            ''            .PageNumberStyle = idNumberingStyle.idArabic
            ''            .SectionPrefix = ""
            ''            .IncludeSectionPrefix = False
            ''        End With
            '    End If

            • 3. Re: Adding Sections
              Ken Krugh Level 1

              Well, took another look at this over the weekend and came up with nothing, zilch, nada, squat . . .


              I'd be curious as to whether the same thing happens with Java but I don't have the foggiest idea of how to code it. I can, however, run JavaScript code from by VB code.


              If someone had a moment to indulge me and post Java code for adding a section I might be able to determine whether it is a VB problem or a general problem.


              Thanks again for any time spent.




              • 4. Re: Adding Sections
                Ken Krugh Level 1

                Hello All!


                Getting pretty desperate on this front.


                Can I trouble someone to post the Java code for inserting a new section? I should be able to pick it apart enough to add variables and run it from VB to get what I need. I dying to know if the same things happens through Java. Not sure if it will matter, but desperate times call for desperate measure.


                On a side note, what do Java nuts recommend for developing Java code? I currently use VB 6 which has great features like command completion (i.e. one types Application. and when you hit the period you get a list of options) and would like to find something that works similar.


                Many thanks,