3 Replies Latest reply on Jun 6, 2013 7:40 AM by pr JSrules

    graphicLine madness

    pr JSrules

      Not sure how to ask for help on this one, but let me know if I'm not clear enough. I'm definitely a rookie.


      I have a doScript with a function that I want to draw a graphic line.


      var xPlace=xLoc[XOholder+1];



                          function lineDrarwing (xPlace) {


                              var myPageDD = app.activeWindow.activePage; 

                              var myMarginsDD = myPageDD.marginPreferences;

                              var BotMarginDD = [myPageDD.bounds[2]-myMarginsDD.bottom];

                              var SMLogoYCDD=BotMarginDD;

                              var SMLogoYADD=BotMarginDD-lineHT;


                              var myGraphicLine = myPage.graphicLines.add({ strokeColor: SMLineColor, strokeWeight: SMLogoStrk });


                              myGraphicLine.paths.item(0).pathPoints.item(0).anchor = [xPlace, SMLogoYADD];  //  X1, Y1

                              myGraphicLine.paths.item(0).pathPoints.item(1).anchor = [xPlace, SMLogoYCDD];  // X2, Y2



                              myGraphicLine.label="Line SM Icon";

                              mySel.transparencySettings.blendingSettings.blendMode= BlendMode.NORMAL;




      The problem that I've narrowed down to is with the variable SMLogoYCDD in the line above

      myGraphicLine.paths.item(0).pathPoints.item(1).anchor = [xPlace, SMLogoYCDD];


      If I replace that with a number, the script works great. My goal is that I can use a variable there.

      It's strange that the other variables work just fine; except that last one. I can't figure out why. I've tried renaming the variable, replacing it with BotMarginDD, etc. I've placed an alert just before that line to tell me what the value of SMLogoYCDD is - and that works fine in the alert, but fails in the executioin in the line following. There aren't any other variables with the name SMLogoYCDD, so it's getting confused somewhere. The error I get is "Error: No data available of the requested type."


      Just in case you were wondering, the variable xPlace works fine. It looks at array named xLoc, and gets a number located at space [XOholder+1]


      Thanks in advance for any help.

        • 1. Re: graphicLine madness
          Peter Kahrel Adobe Community Professional & MVP

          In this line:


          var BotMarginDD = [myPageDD.bounds[2]-myMarginsDD.bottom];


          you create an array. What happens if you use this:


          var BotMarginDD = myPageDD.bounds[2]-myMarginsDD.bottom;


          which gives you a numeric value.


          By the way, when you show values using alert() or $.writeln(), ESTK can trick you. For instance, if you do this:


          a =  [1];

          $.writeln (a);


          you see 1 in the console. If you get strange results like you did, use constructor.name to show what you're dealing with. Thus, though you saw a value printed when you did alert (BotMarginDD), if you do alert (BotMarginDD.constructor.name), you'll see Array.



          • 2. Re: graphicLine madness
            MrTIFF Level 3

            This line: 

                                    var BotMarginDD = [myPageDD.bounds[2]-myMarginsDD.bottom];


            should not have square brackets. Just delete them.


            The square brackets mean that you are defining an array -- with only one element, in this case. But you are using the result as if were just a number.  So when you set your anchors a few lines later, instead of an array containing two numeric values, you get an array containing a number for the first value, but a single-element array for the 2nd value, which InDesign was not expecting!

            • 3. Re: graphicLine madness
              pr JSrules Level 1

              Wow. You are right. I was staring and playing with that code all day-between work of course. Thank you so much for your prompt reply. I got rid of the brackets as suggested and 'IT WORKED!". You guys are definitely amazing.