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

A script to place and rotate copies of an item on all artboards

Participant ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

Hello Everyone;


I’m searching for a script to place and rotate copies of an item on all artboards and align them to corners.

I found this script to place an item:

#target illustrator
var doc = app.activeDocument;

var outlineLayer = doc.layers.add();
outlineLayer.name = "Object";
var placedOutline = outlineLayer.placedItems.add();
placedOutline.file = File("~/AppData/Roaming/Adobe/CEP/Object.pdf");
placedOutline.embed();

But I didn't find a way to finish the script.
 

Attached an item and a sample file of the final file.

TOPICS
How-to , Scripting , Tools

Views

191

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

Community Expert , Jan 31, 2024 Jan 31, 2024

Hi @MidoSemsem, I'm wondering if using symbols for the corner graphics would be a good idea? Here's a script I wrote that uses a symbol called "Corner" (you can adjust). Let me know if this is helpful. Try it on my attached demo file to see how I set up the symbol. (The symbol points to the top left corner.)

- Mark

 

/**
 * Puts a symbol item into every corner
 * of every artboard of active document.
 * Usage:
 * 1. Create a Symbol in the active document.
 *    If orientation is important, it sh
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

Hi @MidoSemsem, I'm wondering if using symbols for the corner graphics would be a good idea? Here's a script I wrote that uses a symbol called "Corner" (you can adjust). Let me know if this is helpful. Try it on my attached demo file to see how I set up the symbol. (The symbol points to the top left corner.)

- Mark

 

/**
 * Puts a symbol item into every corner
 * of every artboard of active document.
 * Usage:
 * 1. Create a Symbol in the active document.
 *    If orientation is important, it should
 *    point to the TOP LEFT.
 * 2. Run script.
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/a-script-to-place-and-rotate-copies-of-an-item-on-all-artboards/m-p/14391298
 */
(function () {

    try {
        var doc = app.activeDocument,
            symbol = doc.symbols.getByName('Corner');
    } catch (error) {
        return alert('Could not find symbol "Corner". Please create symbol and try again.');
    }

    addSymbolsToArtboardCorners(doc, symbol, doc.activeLayer.groupItems.add());

})();

/**
 * Positions a symbol item (of `symbol`)
 * into every corner of every artboard of `doc`.
 * @author m1b
 * @version 2024-01-31
 * @param {Document} doc - an Illustrator Document.
 * @param {Symbol} symbol - an Illustrator Symbol.
 * @param {Document|Layer|GroupItem} [container] - an Illustrator container, for the symbol items (default: activeLayer).
 */
function addSymbolsToArtboardCorners(doc, symbol, container) {

    container = container || doc.activeLayer;

    for (var i = 0, ab, angle, symbolItem, len = doc.artboards.length; i < len; i++) {

        ab = doc.artboards[i];

        for (var corner = 0; corner < 4; corner++) {

            angle = 360 - (corner * 90);
            symbolItem = container.symbolItems.add(symbol);
            symbolItem.rotate(angle);
            symbolItem.position = getArtboardCornerPosition(ab, corner, symbolItem.width, symbolItem.height);

        }

    }

    /**
     * Returns the position for the artboard corner.
     * @param {Artboard} ab
     * @param {Number} corner - the corner (0 = TL, 1 = TR, 2 = BR, 3 = BL)
     * @param {Number} w - width of symbol item.
     * @param {Number} h - height of symbol item.
     * @returns {Array<Number>}
     */
    function getArtboardCornerPosition(ab, corner, w, h) {

        var r = ab.artboardRect;

        return [
            [r[0], r[1]],
            [r[2] - w, r[1]],
            [r[2] - w, r[3] + h],
            [r[0], r[3] + h],
        ][corner];
    };

};

 

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

Thanks @m1b 
It works perfectly 

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 ,
Jan 31, 2024 Jan 31, 2024

Copy link to clipboard

Copied

LATEST

Great!

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