Mobile app version of vmapp.org
Login or Join
Cugini998

: How to swap two objects? Sometimes I want to swap two objects, so one of selected will be on second's place, and vice versa. There is any simple way to do it?

@Cugini998

Posted in: #AdobeIllustrator

Sometimes I want to swap two objects, so one of selected will be on second's place, and vice versa.
There is any simple way to do it?

10.05% popularity Vote Up Vote Down


Login to follow query

More posts by @Cugini998

5 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley591

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


This one works for me.

10% popularity Vote Up Vote Down


 

@Martha945

In addition to Naty's answer, the "swap objects" script by Wundes also swaps the dimensions of the objects. I made a similar script which just swaps the position regardless of the dimensions.

The script swaps 2 objects based on the objects center x & y.

Here you go:

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);
}

10% popularity Vote Up Vote Down


 

@Vandalay110

I'm assuming you are referring to the order of the objects here. You can use the layer palette for this. Select one object then in the palette drag it to the place you desire.

10% popularity Vote Up Vote Down


 

@Angie364

In Adobe Illustrator when you select two objects like OBJECT A and OBJECT B and now if you want to swap each other just select both object and then again select A or B now it's selection become bold and other object will come to that object.

10% popularity Vote Up Vote Down


 

@Sherry646

You can download the "Swap Objects" script and run it or...


Copy and paste in front both of them
Align the first to the second and vice versa.
Delete the old ones

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme