8 Replies Latest reply on Aug 8, 2009 8:18 AM by [Jongware]

    Need a Script

    wuzen

      Hi, I wanted to know if anyone can help me out with a script to create specific sized ellipses in a document.

       

      The scenario is as follows:

       

      I would open documents (variable sizes) and I need (5) .5" black circles placed in specific areas in each document. Below is an example based off an 11"x8.5" document.

       

      Picture 3.jpg

       

      Beginning on the lower left, this first circle needs to be .375" away from the edge of the document. The next circle to the right of it needs to be 3" away from the first circle.

       

      The third circle on the bottom right needs to be .375" away from the edge of the document and the circle above that one needs to be 3" away from the third circle.

       

      The final circle on the top right just needs to be .375" away horizontally and .125" above the top of the document.

       

      Again, the size of the documents will vary, but the distance and size of the circles will not.

       

      Any help would be immensly appreciated. Thank you for reading.

       

      Gus

        • 1. Re: Need a Script
          [Jongware] Most Valuable Participant

          Your specifications are not exact enough, I don't think I can work it out. Besides, you give the location of four circles, but I count 5 in the image ... [Ah...] see below ..

           

          Here is a Javascript you might be able to adjust by yourself:

           

          pagewide = app.activeDocument.documentPreferences.pageWidth;
          pagehigh = app.activeDocument.documentPreferences.pageHeight;
          app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
          app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
          app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
          app.activeDocument.zeroPoint = [ 0, pagehigh ];
          none = app.activeDocument.swatches[0];
          black = app.activeDocument.swatches.item("Black");
          // No. 1: this first circle needs to be .375" away from the edge
          addOnXy (-.375, .375); 
          // No. 2: The next circle to the right of it needs to be 3" away 
          addOnXy (-.375 + 3, .375); 
          /* No. 3: The third circle on the bottom right needs to be
           .375" away from the edge of the document */
          addOnXy (pagewide +.375, .375); 
          /* No. 4: The final circle on the top right just needs to
           be .375" away horizontally and .125" above the top of
           the document */
          addOnXy (pagewide +.375, -pagehigh + .125); 
          function addOnXy (x,y)
          {
           oval = app.activeDocument.ovals.add ();
           oval.geometricBounds = [y - .15, x-.15, y + .15, x + .15 ];
           oval.fillColor = black;
           oval.strokeColor = none;
           oval.contentType = ContentType.GRAPHIC_TYPE;
          }
          

          The function addXy (x,y) expects the center of the circles to be added. As you can see, you can use the shortcuts 'pagehigh' and 'pagewide' which are retrieved at the top of the script.

          Notice I change the ruler origin, so it's a lot easier to draw on the bottom and right. You might want to re-set that to [0,0] if you use it.

           

          Is there any purpose at all to place these circles outside the document and outside the bleed as well? They will *not* appear on any kind of output.

           

          [Edit] ... and now I do see 5 locations. Must be sleepy, or something. Hold on a minute.

          • 2. Re: Need a Script
            [Jongware] Most Valuable Participant

            Five circles, as per request. But my other questions remain.

             

            pagewide = app.activeDocument.documentPreferences.pageWidth;
            pagehigh = app.activeDocument.documentPreferences.pageHeight;
            app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
            app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
            app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES_DECIMAL;
            app.activeDocument.zeroPoint = [ 0, pagehigh ];
            none = app.activeDocument.swatches[0];
            black = app.activeDocument.swatches.item("Black");
            // No. 1: this first circle needs to be .375" away from the edge
            addOnXy (-.375, .375); 
            // No. 2: The next circle to the right of it needs to be 3" away 
            addOnXy (-.375 + 3, .375); 
            /* No. 3: The third circle on the bottom right needs to be
             .375" away from the edge of the document */
            addOnXy (pagewide +.375, .375); 
            /* No. 4: the circle above that one needs to be 3" away
             from the third circle */
            addOnXy (pagewide +.375, .375 - 3); 
            /* No. 5: The final circle on the top right just needs to
             be .375" away horizontally and .125" above the top of
             the document */
            addOnXy (pagewide +.375, -pagehigh + .125); 
            function addOnXy (x,y)
            {
             oval = app.activeDocument.ovals.add ();
             oval.geometricBounds = [y - .15, x-.15, y + .15, x + .15 ];
             oval.fillColor = black;
             oval.strokeColor = none;
             oval.contentType = ContentType.GRAPHIC_TYPE;
            }
            
            • 3. Re: Need a Script
              [Jongware] Most Valuable Participant

              And again -- sorry!

               

              Replace the geometricBounds line with this one

               

              oval.geometricBounds = [y - .25, x-.25, y + .25, x + .25 ];

               

              to get .5 inch circles instead of the .3" it creates now

               

              Perhaps I should get some sleep -- past midnight, but it's about 30 degrees here (touching 90, for our American friends)

              • 4. Re: Need a Script
                wuzen Level 1

                This is perfect!!!! I only had to adjust the distance to .5" instead of .375" to get it exactly .375" away from the trim.

                 

                To answer your question, there is a purpose to this. We have a die cutting machine which uses these circles as targets to define the trim area. The circle must be .25" away from the bleed in order for the laser to read the circles. They do appear in the output even though they are out of the trim/bleed area.

                 

                I export them as EPS and in the Export to EPS dialog box, I include bleed of 1" which includes any elemtents outside of the trim area up to that distance away.

                 

                This script is working absolutely perfect! Thank you so much!!!!

                 

                Is there any way to easily make this script work in Illustrator CS4?

                 

                Is there also an easy way for a script to be written for Indesign that sets a frame around the document based off the document size? The frame can be empty and have no fill or stroke.

                • 5. Re: Need a Script
                  [Jongware] Most Valuable Participant
                  I export them as EPS ...

                   

                  Good answer ... teaches me not to assume anything up front!

                   

                  I suppose the script can be easily adjusted for Illustrator, since all one has to do is rewrite the addXy function, using Illustrator objects and properties. I don't remotely know enough of Illy to do that ... Just post the script as-is in the Illy scripting fourm and ask, I'd suggest.

                   

                  Adding a frame is a breeze as well. Add this

                   

                  myRect = app.activeDocument.rectangles.add();
                  myRect.geometricBounds = [ 0,0, -pagehigh, pagewide ];
                  myRect.fillColor = none;
                  myRect.strokeColor = none;
                  

                   

                  just above the "function addXy" line. I *think* it needs a negative pagehigh (= top right y) because the zero origin is still at the lower left. Adjust when necessary ...

                  • 6. Re: Need a Script
                    wuzen Level 1

                    Frame code works great too! I will post the Javascript over on the Illustrator board and see if anyone can help.

                     

                    Now I'm just trying to have the script create the circles in a new layer. I can get it to create the layer (stealing the code from the built in crop marks script) but I cannot get the circles to reside in the layer.

                    • 7. Re: Need a Script
                      wuzen Level 1

                      I figured out how to put it in it's own layer!

                      • 8. Re: Need a Script
                        [Jongware] Most Valuable Participant

                        To quote one of my favourite writers,

                         

                        "That simple, eh?"

                        "And now I shall test it," said Wen.