9 Replies Latest reply on Dec 7, 2009 7:46 AM by [Jongware]

    scripting newbie...help for a "simple" crop mark script

    soulglowdeej Level 1

      Hello,

       

      I am after some advice or assistance on the scripting side of things for indesign please.

       

      Basically where do you start? I'm wanting to do some scripts to speed up some repetitive processes.

       

      What I'm trying to do initially is (what I'd think would be) a very simple script. Basically it's adding crop marks to document, with the horizontal ones running the full width of the document. I've just no idea where to start...

       

      So, I think the process of the script would be this:

       

      1. Find document size

       

      2. Add a horizontal line at 0.1 pt size,
      Length = document width + 20mm
      X axis =  document width divided by 2 (line sits centrally, hanging 10mm over left and right edges)
      Y Axis = 0mm

       

      3. Add a horizontal line at 0.1 pt size,
      Length = document width + 20mm
      X axis =  document width divided by 2 (line sits centrally, hanging 10mm over left and right edges)
      Y Axis = document height

       

      4. Add a vertical line at 0.1 pt size,
      Length = 10mm
      X axis =  0mm
      Y Axis = -2mm to -12mm (bottom line sits at -2, top of line at -12)

       

      5. Add a vertical line at 0.1 pt size,
      Length = 10mm
      X axis =  document width
      Y Axis = -2mm to -12mm (bottom line sits at -2, top of line at -12)

       

      6. Add a vertical line at 0.1 pt size,
      Length = 10mm
      X axis =  0mm
      Y Axis = document height + 2mm, to document height +12mm (top of line sits at document height +2mm, bottom of line at document height +12mm)

       

      7. Add a vertical line at 0.1 pt size,
      Length = 10mm
      X axis =  document width
      Y Axis = document height + 2mm to document height +12mm (top of line sits at document height +2mm, bottom of line at document height +12mm)

       


      For the future I am wanting some more complex scripts but this will hopefully help me understand a little bit.  (I will need one with input tables where you can add variables if that's do-able, but i somehow think it wont be me doing that one!!)

       

      Thanks in advance for any help or pointers.

       

      Phil

        • 1. Re: scripting newbie...help for a "simple" crop mark script
          Thomas B. Nielsen Level 3

          Hi Phil,

           

          Well you've come to the right place :-)

           

          First of all, have you searched the internet for scripts?

          There's a good chance that someone else have done the same as you want to do, or at least something very similar.

           

          If you can find a script that do, or allmost do, what you need, you could learn to modify it, or perhaps someone here will do it for you :-)

           

          --

           

          Thomas B. Nielsen

          http://www.lund-co.dk

          1 person found this helpful
          • 2. Re: scripting newbie...help for a "simple" crop mark script
            Peter Kahrel Adobe Community Professional & MVP

            One of the sample scripts installed by InDesign is called cropmarks.jsx. I guess that it will have some pointers for you.

             

            Peter

            1 person found this helpful
            • 3. Re: scripting newbie...help for a "simple" crop mark script
              soulglowdeej Level 1

              Hi,

               

              Thanks for the advice - I have done a search here and over the net but not been able to find what I need unfortunately.

              Thanks for the tip on the free script, again unfortunately I've already looked at this, but having zero experience or knowledge of scripting (other than creating "actions" which gives me no info on how the codes created) I don't really have a clue what refers to what.

               

              Cheers, Phil

              • 4. Re: scripting newbie...help for a "simple" crop mark script
                [Jongware] Most Valuable Participant

                See http://forums.adobe.com/message/2179388#2179388 for a script evolving from a general crop marks script to a quite complex one (and an accompanying message in http://forums.adobe.com/message/2179390#2179390 for a bit techie explanation).

                • 5. Re: scripting newbie...help for a "simple" crop mark script
                  soulglowdeej Level 1

                  Thanks - i did see these but will take another look and try to figure it out....

                  • 6. Re: scripting newbie...help for a "simple" crop mark script
                    [Jongware] Most Valuable Participant

                    As said above, we can walk you through a custom script step by step

                     

                    Let me get you started with this: the ESTK Help -- or one of its variants -- is your biggest friend!

                     

                     

                    "1. Find document size"

                     

                    Use app.activeDocument.documentPreferences.pageWidth and app.activeDocument.documentPreferences.pageWidth for these.

                     

                    "2. Add a horizontal line at 0.1 pt size,
                    Length = document width + 20mm
                    X axis =  document width divided by 2 (line sits centrally, hanging 10mm over left and right edges)
                    Y Axis = 0mm"

                     

                    app.activeDocument.graphicLines.add () adds a new graphic line on a default position. You can then move it into position.

                     

                     

                    Doing the math results in this little script to add the first line:

                     

                    newLine = app.activeDocument.graphicLines.add();

                    newLine.paths[0].pathPoints[0].anchor = [ -20, 0 ];

                    newLine.paths[0].pathPoints[1].anchor = [ app.activeDocument.documentPreferences.pageWidth+20, 0 ];

                    newLine.strokeWeight = 0.1;

                    newLine.strokeColor = app.activeDocument.swatches.item("Registration");

                    newLine.strokeStyle = app.strokeStyles[0];

                     

                    A 'line' can consist of a number of paths (consider a compound path), but usually has only one single path. A new line only has two endpoints -- the anchors --, and you can move these around by setting the coordinates with an array of [ x y ] values. Important: These values are in your current measurement units! I'm assuming, for convenience, that you have mm for this. If you see 20 inch wide lines popping up, you know why :-) Another important point: the rulers' zero point must be in the top left of your document. All "absolute" values are relative to this zero point.

                     

                    It is perfectly possible to have the script set the correct measurements and move the zero point for you, but now you know why it has to do that.

                    Notice you don't explicitly move the center of the new line; in this case, it's easier to immediately move each end point into its correct place.

                     

                    There are a few other things you can do to make the script misbehave. The new line is created with the active defaults in your document. You could have the script change the defaults to the correct settings, but that's not really user friendly. Instead, you can change everything by applying new values to the new line only. You can see I set its weight, color, and stroke style.

                     

                    A few points on these latter three settings:

                    • Didn't I just tell you all values are in current measurement units? Well, line widths are always in points (as is font size and line spacing).
                    • The correct line color is grabbed by asking for a swatch called "Registration" -- you might want to replace this with another swatch name.
                    • The stroke style is grabbed by blindly using the very first stroke style in InDesign. I found out the hard way using "Solid" (or what is it called) does not work across different languages. Much later I learned there is a language-independent way of using the names, but hey, that's harder to remember.
                    • 7. Re: scripting newbie...help for a "simple" crop mark script
                      soulglowdeej Level 1

                      Wow!! Thank you Jongware, that's really helpful!!

                       

                      I'v never done anything like this before so I'll have a go as soon as i get chance and let you know how i get on.

                       

                      Thanks very much!

                      • 8. Re: scripting newbie...help for a "simple" crop mark script
                        soulglowdeej Level 1

                        Hi Jongware,

                         

                        Thanks very much for your help on this - i've been able to get what I initially wanted working so all's good! Now I'm goign to try and tweek it to do other things!

                         

                        Everyone's input was greatly appreciated.

                         

                        Thanks (again)!

                        • 9. Re: scripting newbie...help for a "simple" crop mark script
                          [Jongware] Most Valuable Participant

                          Happy tweeking. You won't (hopefully) find it hard to adjust this script to draw vertical lines, or lines not spanning the entire document. (Etc.) From here on, The World Is Your Lobster.

                           

                          I finally remembered the language-independent way of accessing 'named' items, but on testing ... my InDesign failed! It seems a gremlin struck, and instead of changing the strokeStyle of the new line, I should have changed the strokeType (which is changed to another strokeStyle -- hence the confusion).

                           

                          app.selection[0].strokeType = app.activeDocument.strokeStyles.item("$ID/Thick - Thick");

                          I think Marc Autret -- www.indiscripts.com -- was the one pointing the "$ID" trick out to me. I may be mistaken, but his site is so full of JavaScript that this is a perfectly good reason to drop his name & URL. (By the way, this is only important if you want to write scripts that may be used outside your own office and in different languages.)