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

Create a script to insert . AI within a document.AI.

Explorer ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hello, I already work creating some scripts, but very simple things. I have several .AI files in a folder. Within these files there is only one Group. I need a way to insert these files into a document open in Illustrator with its editing capabilities intact. It would be like opening a file, copying and pasting it into my document. But it is not feasible to do this with multiple files. I need ideas.

TOPICS
How-to , Import and export , Scripting

Views

108

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 , Feb 23, 2024 Feb 23, 2024

Hi @MarcosAdriano1994, you can try this script I just wrote. When you run it, it will duplicate all the page items into the active document. Let me know if it helps.

- Mark

 

/**
 * Gather page items from all documents into active document.
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/create-a-script-to-insert-ai-within-a-document-ai/m-p/14442488
 */
(function () {

    var docs = app.documents;

    if (docs.length < 2)
        return alert('Please open t
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 23, 2024 Feb 23, 2024

Copy link to clipboard

Copied

Hi @MarcosAdriano1994, you can try this script I just wrote. When you run it, it will duplicate all the page items into the active document. Let me know if it helps.

- Mark

 

/**
 * Gather page items from all documents into active document.
 * @author m1b
 * @discussion https://community.adobe.com/t5/illustrator-discussions/create-a-script-to-insert-ai-within-a-document-ai/m-p/14442488
 */
(function () {

    var docs = app.documents;

    if (docs.length < 2)
        return alert('Please open two or more documents and try again.');

    var sourceDocNames = [],
        targetDoc = docs[0];

    for (var i = 1; i < docs.length; i++)
        sourceDocNames.push(docs[i].name);

    for (var i = 0, sourceDoc, items, layer; i < sourceDocNames.length; i++) {

        sourceDoc = app.documents.getByName(sourceDocNames[i]);

        for (var j = sourceDoc.layers.length -1; j >= 0 ; j--) {

            items = sourceDoc.layers[j].pageItems;
            layer = makeLayer(targetDoc, sourceDoc.layers[j]);

            for (var k = 0; k < items.length; k++)
                items[k].duplicate(layer, ElementPlacement.PLACEATEND);

        }

    }


})();




/**
 * Makes, or gets, a layer.
 * @author m1b
 * @version 2022-07-24
 * @param {Document} [doc] - an Illustrator Document.
 * @param {String|Layer} [nameOrLayer] - the layer name, or a Layer.
 * @returns {Layer}
 */
function makeLayer(doc, nameOrLayer) {

    doc = doc || app.activeDocument;
    var newLayer,
        name = nameOrLayer.hasOwnProperty('name') ? nameOrLayer.name : nameOrLayer;

    try {
        newLayer = doc.layers.getByName(name);
    } catch (e) {
        newLayer = doc.layers.add();
        if (undefined != nameOrLayer) {
            newLayer.name = name;
            if (nameOrLayer.hasOwnProperty('color'))
                newLayer.color = nameOrLayer.color;
        }
    }

    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 ,
Mar 07, 2024 Mar 07, 2024

Copy link to clipboard

Copied

Apologies for the delay. I adapted your code and it worked perfectly. Thank you very much.

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 ,
Mar 07, 2024 Mar 07, 2024

Copy link to clipboard

Copied

LATEST

Excellent! Well done! 😊

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