• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Create script for adding shapes with specified colour on specified layers.

Explorer ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

Hello everyone, feel free to shoot me down if this is too crazy but I am looking for some help with a script. 

The script would:
1. Set the document to have 9mm bleed

2. Create five 6mm circles, that have a spot black fill called 'Black'
3. Position dots so one is in the top left, top right, bottom left, bottom right, and center left (touching the edge of 9mm bleed).
4. Create five 6mm circles with no fill, but a 0.25pt stroke set to overprint, using a spot green called 'Registration'. 
5. Position these in the same place as the black circles, (over the top) but seperate them into a layer called 'Overprint'.

If any magic users out there have any ideas, I would be very thankful - its taking up so much time when faced with a large quantity of files. 

Many thanks.

TOPICS
Scripting

Views

401

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , May 17, 2024 May 17, 2024

From what i've gathered, there is not a clean and easy way to script the setting of a documents bleed. If someone else knows an easy way to implement feel free to add. below is a script that will create the 10 circles you need, 5 filled, and 5 stroked. I would suggest using a different name than "black" for your swatch. it gets messy since there is already a default black swatch.

/*get the artboards dimensions for placing the circles*/
var ArtboardRect = app.activeDocument.artboards[0].artboardRe
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

Can you share at least one sample Illustrator file that shows the desired result?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

You are right this would have been helpful! Fortunately, RobOctopus seems to have hit the nail on the head with his script, will remember this moving forward.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Yes, RobOctopus' script is very good.

 

You may also take a look at the Grommet Marks script by William Campbell. It has some useful settings.

 

Crommet Marks script by William Campbell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 17, 2024 May 17, 2024

Copy link to clipboard

Copied

From what i've gathered, there is not a clean and easy way to script the setting of a documents bleed. If someone else knows an easy way to implement feel free to add. below is a script that will create the 10 circles you need, 5 filled, and 5 stroked. I would suggest using a different name than "black" for your swatch. it gets messy since there is already a default black swatch.

/*get the artboards dimensions for placing the circles*/
var ArtboardRect = app.activeDocument.artboards[0].artboardRect
var ALeft = ArtboardRect[0]
var ATop = ArtboardRect[1]
var ARight = ArtboardRect[2]
var ABottom = ArtboardRect[3]
var AWidth = ArtboardRect[2]-ArtboardRect[0]
var AHeight = ArtboardRect[3]-ArtboardRect[1]

/*
change the bleed value here to change where the circles need to be placed
change the CircleWidthHeight value to change how large the circles are. they are currently 6mm converted to pts.
look up the UnitValue function to edit these
*/
var Bleed = UnitValue(9,"mm").as("pt")
var CircleWidthHeight = UnitValue(6,"mm").as("pt")
/* adds the spot colors. will probably fail with the black as the name is not unique*/
AddSpot("Black", 0, 0, 0, 100, true)
AddSpot("Registration", 100, 0, 100, 0, true)

/*create new layers for your new circles*/
var FilledCircles = FindLayerCreate(app.activeDocument, "BLACK CIRCLES")
var StrokedCircles = FindLayerCreate(app.activeDocument, "OVERPRINT")

/*here we set the values for making the stroked circles*/
var StrokeValues = {
    stroked: true,
    sWidth: 0.25,
    sColor: app.activeDocument.swatches.getByName("Registration").color,
    sOverprint: true,
    filled: false,
    fColor: new NoColor(),
    fOverprint: false,
    targetLayer: StrokedCircles
}

/*make all 5 stroked circles*/
MakeCircle(ATop+Bleed,ALeft-Bleed,CircleWidthHeight,StrokeValues)
MakeCircle(ATop+Bleed,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,StrokeValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,StrokeValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ALeft-Bleed,CircleWidthHeight,StrokeValues)
MakeCircle((ABottom/2)+(CircleWidthHeight/2),ALeft-Bleed,CircleWidthHeight,StrokeValues)

/*set the values for the filled circles*/
var FillValues = {
    stroked: false,
    sWidth: 0,
    sColor: new NoColor(),
    sOverprint: false,
    filled: true,
    fColor: app.activeDocument.swatches.getByName("Black").color,
    fOverprint: false,
    targetLayer: FilledCircles
}

/*make all 5 filled circles*/
MakeCircle(ATop+Bleed,ALeft-Bleed,CircleWidthHeight,FillValues)
MakeCircle(ATop+Bleed,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,FillValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,FillValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ALeft-Bleed,CircleWidthHeight,FillValues)
MakeCircle((ABottom/2)+(CircleWidthHeight/2),ALeft-Bleed,CircleWidthHeight,FillValues)


function MakeCircle(Top,Left,CWH,StrokeFillValues){
    var newCircle = StrokeFillValues.targetLayer.pathItems.ellipse(Top,Left,CWH,CWH,false)
    newCircle.stroked = StrokeFillValues.stroked
    newCircle.filled = StrokeFillValues.filled

    newCircle.strokeWidth = StrokeFillValues.sWidth
    newCircle.strokeColor = StrokeFillValues.sColor
    newCircle.strokeOverprint = StrokeFillValues.sOverprint

    newCircle.fillColor = StrokeFillValues.fColor
    newCircle.fillOverprint = StrokeFillValues.fOverprint
}


/**
 * Adds a spot swatch based on CMYK information
 * @Param {Object|String} NewColor - if its an object of color information will convert otherwise assumes its a string
 * @Param {Number} c - the value of Cyan 0-100
 * @Param {Number} m - the value of Magenta 0-100
 * @Param {Number} y - the value of Yellow 0-100
 * @Param {Number} k - the value of Black 0-100
 * @Param {Boolean} SpotProcess - true/false if the spot color is a process or not. if true will be spot
 */
function AddSpot(NewColor, c, m, y, k, SpotProcess) {
    SpotProcess = (SpotProcess === 'true') /*convert to bool*/
    if (typeof NewColor == "object") {
        var name = NewColor[0]
        var c = NewColor[1]
        var m = NewColor[2]
        var y = NewColor[3]
        var k = NewColor[4]
    } else if (typeof NewColor == "string") {
        name = NewColor
    } else {
        alert(NewColor + " is not in a recognizable format for coding")
    }
    try {
        swatch = app.activeDocument.swatches[name]; // if swatch exists....  
        //AddSpot (name+=' 1', c, m, y, k); // ...add 1 to swatch name  
    } catch (e) {
        var newColor = new CMYKColor();
        newColor.cyan = c;
        newColor.magenta = m;
        newColor.yellow = y;
        newColor.black = k;
        var newSpot = app.activeDocument.spots.add()
        newSpot.colorType = SpotProcess ? ColorModel.SPOT : ColorModel.PROCESS;
        newSpot.name = name;
        newSpot.color = newColor;
    }
}

function FindLayerCreate(ParentLayer, ChildLayer) {
    try {
        var NewLayer = ParentLayer.layers[ChildLayer]
    } catch (e) {
        var NewLayer = ParentLayer.layers.add()
        NewLayer.name = ChildLayer
    }
    return NewLayer
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

This works perfectly thank you so much! Been testing it over the last couple of days! Works so well thank you

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

@RobOctopus is there some code I can add to create a: stroke only rectangle, white, the size of artboard + bleed, that has an inside stroke alignment?

Screenshot 2024-05-23 at 13.17.52.png

Screenshot 2024-05-23 at 13.16.18.png

I've run into an issue where the circles need white underneath to register.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

LATEST

No Problem @Aidan_C . Unfortunately, aligning stroke is really goofy via scripting, but doable.

Add the following to the previous code.

/*the original code i sent had layers being created around line 23/24 add this there*/
var BackgroundRectangle = FindLayerCreate(app.activeDocument, "WHITE RECTANGLE")

/*previous code things here*/

/*then after the circles are made add this
it will create a rectangle on the background rectangle layer we make earlier
then we make sure the stroke is white, the width is equal to the circle sizes, and that there isnt a fill. then we call the align stroke function and finally move it to the bottom of the stack as a redudancy*/
var WhiteRectangle = BackgroundRectangle.pathItems.rectangle(ATop+Bleed,ALeft-Bleed, AWidth+(Bleed*2), -(AHeight-(Bleed*2)))
WhiteRectangle.stroked = true
WhiteRectangle.strokeWidth = CircleWidthHeight
WhiteRectangle.strokeColor = new CMYKColor();
WhiteRectangle.filled = false
WhiteRectangle.fillColor = new NoColor();
AlignStroke(WhiteRectangle, 1)
BackgroundRectangle.move(app.activeDocument,ElementPlacement.PLACEATEND)

/* somewhere at the bottom of the code, copy/paste this function does some goofy things to align the stroke by creating an action to do it for us and then deleting the action */
/**
 * Will change the alignment of a stroked path.
 * @param {Object} FrameToAlign - PathItem to edit
 * @param {String|Number} AlignNumber - 0=Center, 1=Inside, 2=Outside
 */
function AlignStroke(FrameToAlign, AlignNumber){
    /*
    need to grab the previous stroke join and cap as they are overwritten for some reason.
    will reset them back to their previous state at the end of the function
    */
    var PreviousJoin = FrameToAlign.strokeJoin
    var PreviousCap = FrameToAlign.strokeCap
    switch(AlignNumber){
        case "0":
        case 0:
            var AlignInsert = [
                '/name [ 6',
                '43656e746572',
                ']',
                '/value 0']
                break;
        case "1":
        case 1:
            var AlignInsert = [
                '/name [ 6',
                '496e73696465',
            ']',
            '/value 1']
            break;
        case "2":
        case 2:
            var AlignInsert = [
            '/name [ 7',
            '4f757473696465',
            ']',
            '/value 2']
            break
    }
    var ActionString = [
	'/version 3',
	'/name [ 14',
		'5374726f6b65416c69676e536574',
	']',
	'/isOpen 1',
	'/actionCount 1',
	'/action-1 {',
	'/name [ 17',
		'5374726f6b65416c69676e416374696f6e',
	']',
	'/keyIndex 0',
	'/colorIndex 0',
	'/isOpen 1',
	'/eventCount 1',
	'/event-1 {',
	'/useRulersIn1stQuadrant 0',
	'/internalName (ai_plugin_setStroke)',
	'/localizedName [ 10',
		'536574205374726f6b65',
	']',
	'/isOpen 1',
	'/isOn 1',
	'/hasDialog 0',
	'/parameterCount 1',
	'/parameter-1 {',
		'/key 1634494318',
		'/showInPalette 4294967295',
		'/type (enumerated)'].concat(AlignInsert,
	'}',
'}',
'}').join("\n")
var f = File(Folder.desktop+"/StrokeAlignment.aia");
f.open('w');
f.write(ActionString);
f.close();
app.executeMenuCommand("deselectall")
FrameToAlign.selected = true;
app.loadAction(f);
app.doScript('StrokeAlignAction', 'StrokeAlignSet');
    app.unloadAction('StrokeAlignSet', '');
f.remove();
FrameToAlign.strokeJoin = PreviousJoin
FrameToAlign.strokeCap = PreviousCap
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 18, 2024 May 18, 2024

Copy link to clipboard

Copied

Hello, You can get the result with create and using an Action instead of Script. it would work so easier.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2024 May 23, 2024

Copy link to clipboard

Copied

Unfortunately had quite a few issues with the actions remembering swatch colours - and doesn't seem to want to make rename layers etc. Thanks for the help though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines