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

Change Placement Options of all PlacedItems

Explorer ,
Mar 11, 2022 Mar 11, 2022

Copy link to clipboard

Copied

Hi, i have a lot of Ai files that each one of them contains many placed items, and i need to change the Placement Option of them to preserve File Dimentions. is this options accessable via JavaScript?

0001.PNG

Thank you very much.

TOPICS
Scripting

Views

334

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 , Mar 12, 2022 Mar 12, 2022

Hi @Sayed Ali Mousawi,

I have written a script that will return all placed items in a document to 100% size with the option to position in relation to the placed item's frame (eg. the clipping mask rectangle). Will that work in your case?

- Mark

 

/*

    UnScale All Placed Items.js
    for Adobe Illustrator 2022

    by m1b
    here:https://community.adobe.com/t5/illustrator-discussions/change-placement-options-of-all-placeditems/m-p/12806572

*/


unScaleAllPlacedItems();


function unScaleAll
...

Votes

Translate

Translate
Adobe
Explorer ,
Mar 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

var doc = app.activeDocument;
var myitems = doc.placedItems;
for (let i = 0; i < myitems.length; i++) {
    myitems[i]./*i don't know what*/    
}

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 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

it's probably not possible, not everything you can do in the UI is available to scripting.

 

you might need to do the adjustments yourself after updating the link

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 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

Hi @Sayed Ali Mousawi,

I have written a script that will return all placed items in a document to 100% size with the option to position in relation to the placed item's frame (eg. the clipping mask rectangle). Will that work in your case?

- Mark

 

/*

    UnScale All Placed Items.js
    for Adobe Illustrator 2022

    by m1b
    here:https://community.adobe.com/t5/illustrator-discussions/change-placement-options-of-all-placeditems/m-p/12806572

*/


unScaleAllPlacedItems();


function unScaleAllPlacedItems(doc) {

    doc = doc || app.activeDocument;
    var items = doc.placedItems;

    for (var i = 0; i < items.length; i++) {
        unScalePlacedItem({
            doc: doc,
            item: items[i],
            positionToFrame: Transformation.CENTER,
            transformAbout: Transformation.CENTER
        });
    }

}


function unScalePlacedItem(options) {

    var item = options.item,
        positionToFrame = options.positionToFrame,
        transformAbout = options.transformAbout;

    if (options.item == undefined)
        return;

    // unscale the placed item
    item.resize(1 / item.matrix.mValueA * 100, -1 / item.matrix.mValueD * 100, undefined, undefined, undefined, undefined, undefined, transformAbout);

    if (positionToFrame == undefined)
        return;

    // get item's frame if it has one
    var frame;
    if (item.parent.constructor.name == 'GroupItem') {
        for (var i = 0; i < item.parent.pageItems.length; i++) {
            if (item.parent.pageItems[i].clipping == true) {
                frame = item.parent.pageItems[i];
                break;
            }
        }
    }

    if (frame == undefined)
        return;

    var centerDelta = differenceBetweenPoints(centerOfItem(frame), centerOfItem(item)),
        topLeftDelta = differenceBetweenPoints([frame.left, frame.top], [item.left, item.top]),
        sizeDelta = differenceBetweenPoints([frame.width, frame.height], [item.width, item.height]);

    // position the placed item in relation to its frame
    if (positionToFrame == Transformation.TOPLEFT) {
        item.translate(topLeftDelta[0], topLeftDelta[1]);
    }
    else if (positionToFrame == Transformation.TOP) {
        item.translate(centerDelta[0], topLeftDelta[1]);
    }
    else if (positionToFrame == Transformation.TOPRIGHT) {
        item.translate(topLeftDelta[0] + sizeDelta[0], topLeftDelta[1]);
    }
    else if (positionToFrame == Transformation.LEFT) {
        item.translate(topLeftDelta[0], centerDelta[1]);
    }
    else if (positionToFrame == Transformation.CENTER) {
        item.translate(centerDelta[0], centerDelta[1]);
    }
    else if (positionToFrame == Transformation.RIGHT) {
        item.translate(topLeftDelta[0] + sizeDelta[0], centerDelta[1]);
    }
    else if (positionToFrame == Transformation.BOTTOMLEFT) {
        item.translate(topLeftDelta[0], topLeftDelta[1] - sizeDelta[1]);
    }
    else if (positionToFrame == Transformation.BOTTOM) {
        item.translate(centerDelta[0], topLeftDelta[1] - sizeDelta[1]);
    }
    else if (positionToFrame == Transformation.BOTTOMRIGHT) {
        item.translate(topLeftDelta[0] + sizeDelta[0], topLeftDelta[1] - sizeDelta[1]);
    }

}

function centerOfItem(item) {
    var hasDocCoordinates = app.coordinateSystem == CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
    var pos = hasDocCoordinates ? app.activeDocument.convertCoordinate(item.position, CoordinateSystem.DOCUMENTCOORDINATESYSTEM, CoordinateSystem.ARTBOARDCOORDINATESYSTEM) : item.position;
    pos[0] += item.width / 2;
    pos[1] -= item.height / 2;
    return pos;
}

function differenceBetweenPoints(p1, p2) {
    return [-(p2[0] - p1[0]), -(p2[1] - p1[1])];
}

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 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

WOW!

That Worked in My Case Very Well, thank you wonderful @m1b.

really appreciate that.

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 12, 2022 Mar 12, 2022

Copy link to clipboard

Copied

LATEST

Great to hear it helped!

- Mark

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