Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

copy, move and paste into different layer

$
0
0

I have a script that measures the repeat interval and gap between print impressions printed using a print cylinder (for the production team to know which print cylinders to use, and what to expect once it prints, when looking at the proof sheet). Basically it just measures the distance from the beginning of one print impression to the beginning of the next (these are printed with a cylinder, so every time the cylinder rotates a new print impression happens) as well as the distance in between prints. That part works great.

 

In order to get these meaurements, Illustrator is measuring the distance from a zero point on the artboard to the left side of a marker I made called "repeat", and it is assigned a variable called rawRepeat. What I'd like to do is have the script take that rawRepeat value and use it to move a copy of the print impression to the right by exactly that variable amount and paste it beneath the marker called "repeat". I have been doing this part manually, but haven't been able to figure out how to get illustrator to do this for me.

 

Any help would be greatly appreciated.

 

Here's the script I am using:

 

 

var myDocument = app.activeDocument;

var selectedObject = myDocument.selection;

var activeLayer = app.activeDocument.activeLayer;

var layerName = activeLayer.name;

activeLayer.name = "plate";

 

 

//Identify left edge of repeat

var repeatBounds = app.activeDocument.groupItems['repeat'].geometricBounds;

var r1 = repeatBounds[0];

 

 

// Get position of selection bounds

var myBounds = selectedObject[0].geometricBounds;

var x1 = myBounds[0];

var x2 = myBounds[2];

 

 

 

 

// Set up vars for the Measurements

var rawPrintWidth = myBounds[2] - myBounds[0];

var tmpPrintWidth = (rawPrintWidth / 72);

var finalPrintWidth = tmpPrintWidth.toFixed(2);

var rawGap = (r1 - x2);

var rawRepeat = (r1 - x1);

var Repeat = (rawRepeat / 72) + 0.25;

var Gap = (rawGap / rawRepeat) * Repeat;

 

 

//set up fraction calculations for Repeat

var Factor = 16;

var repeatFraction = Math.round(Factor*Repeat) % Factor;

if (repeatFraction)

{

    while (~(repeatFraction | Factor) & 1)

        repeatFraction >>= 1, Factor >>= 1;

    if (Math.floor(Repeat) == 0)

        Repeat = String(repeatFraction)+'/'+String(Factor);

    else

        Repeat = String(Math.floor(Repeat))+' '+String(repeatFraction)+'/'+String(Factor);

} else

{

    Repeat = String(Math.round(Repeat));

}

 

 

//set up fraction calculations for Gap

var gapFactor = 8

var gapFraction = Math.round(gapFactor*Gap) % gapFactor;

if (gapFraction)

{

    while (~(gapFraction | gapFactor) & 1)

        gapFraction >>= 1, gapFactor >>= 1;

    if (Math.floor(Gap) == 0)

        Gap = String(gapFraction)+'/'+String(gapFactor);

    else

        Gap = String(Math.floor(Gap))+' '+String(gapFraction)+'/'+String(gapFactor);

} else

{

    Gap = String(Math.round(Gap));

}

 

 

// Find specs swatch

var origSwatches = myDocument.swatches;

var swatchesLength = origSwatches.length;

for (i=0;i<swatchesLength;i++) {

          if (origSwatches[i].name == "specs" || origSwatches[i].name == "Specs") {

                    var specsSwatch = origSwatches[i];

                    }

          }

 

 

// Check if specs swatch is defined

if (specsSwatch == undefined) {

          alert("Please create a specs swatch");

          }

else {

          makeDimensions();

          releaseLayer();

}

 

 

 

 

function makeDimensions() {

 

 

// Lock the active layer to prevent color change

activeLayer.locked = true;

 

 

// Create Measurements Layer

mLayerCreate();

 

 

// Set Document colors to specs

myDocument.defaultFillColor = specsSwatch.color;

myDocument.defaultStrokeColor = specsSwatch.color;

 

// Create groups for measurements

var xMeasure = mLayer.groupItems.add();

xMeasure.name = "Width";

 

 

// Create Text for Repeat Measurement

var repeatText = xMeasure.textFrames.add();

repeatText.contents = "Will repeat every "+Repeat+"\" " + "with approximately "+Gap+"\" between prints";

repeatText.top = -327;

repeatText.left = 275;

repeatText.paragraphs[0].paragraphAttributes.justification = Justification.LEFT;

for (i=0;i<repeatText.textRange.characters.length;i++) {

          repeatText.characters[i].characterAttributes.fillColor = specsSwatch.color;

}

}

// Create Text for Ink Colors

 

 

var inkList = [];

 

 

 

 

 

 

function mLayerCreate() {

 

          var mLayerNotExists = true;

 

 

//Delete existing Measurements layer to make way for new measurements

try {

    app.activeDocument.layers.getByName("Measurements").remove();

} catch (e) {};

 

 

 

 

// Create Measurements Layer

if(mLayerNotExists){

mLayer = myDocument.layers.add();// not using var to declare makes it global

mLayer.name = "Measurements";

}

}

 

 

function releaseLayer(){

          for(i = 0; i < activeDocument.layers.length; i++) {

                    if(activeDocument.layers[i].name == "plate") {

                              activeDocument.layers[i].name = layerName;

                              activeDocument.layers[i].locked = false;

                              activeDocument.activeLayer = activeDocument.layers[i];

                              }

                    }

 

          }


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>