如何交换两个对象?

平面设计 adobe-illustrator
2022-02-18 17:09:35

有时我想交换两个对象,因此选定的对象之一将排在第二位,反之亦然。有什么简单的方法可以做到吗?

4个回答

除了 Naty 的回答之外,Wundes 的“交换对象”脚本还交换了对象的尺寸。我制作了一个类似的脚本,它只是交换位置而不管尺寸如何。

该脚本根据对象中心 x 和 y 交换 2 个对象。

干得好:

try { 
    var selObjs = "Please select two objects on the page.";
    var docRef = activeDocument;
    if (documents.length>0) {
        if (docRef.selection.length == 2) {
            mySelection = docRef.selection;

            //if object is a (collection of) object(s) not a text field.
            if (mySelection instanceof Array) {
                //initialize vars
                var object_A = mySelection[0];
                var object_B = mySelection[1];

                // Calculate new center object A
                new_A = [
                    (object_B.left+(object_B.width/2))-object_A.width/2,
                    (object_B.top-(object_B.height/2))+object_A.height/2
                ];
                // Calculate new center object B
                new_B = [
                    (object_A.left+(object_A.width/2))-object_B.width/2,
                    (object_A.top-(object_A.height/2))+object_B.height/2
                ];
                // Make the swap
                object_A.position = new_A;
                object_B.position = new_B;

            } else {
                alert(mySelection+" is not an array!\n"+selObjs);
            }
        } else {
            alert("Selection is not 2 objects!\n"+selObjs);
        }
    }
} catch(e){
    alert("problem:\n"+e);
}

您可以下载“交换对象”脚本并运行它或...

  1. 复制粘贴在他们前面
  2. 将第一个与第二个对齐,反之亦然。
  3. 删除旧的
var centerToOrigin1 = [object_B.getLeft()+(object_B.getWidth()/2)] - [object_A.getWidth()] / 2, [object_B.getTop()+(object_B.getHeight()/2)] - [object_A.getHeight()] / 2;
var centerToOrigin2 = [object_A.getLeft()+(object_A.getWidth()/2)] - [object_B.getWidth()] / 2, [object_A.getTop()+(object_A.getHeight()/2)] - [object_B.getHeight()] / 2

这个对我有用。

我是来自 Inkscape 的 AI 新手,我想念这个功能。一个快速的解决方法是选择两个对象,然后水平翻转一次,然后垂直翻转。然后,您将返回单独选择每个对象并重复翻转操作。与 Inkscape 的一键式工具相比,它只需点击几下,但它就是这样......