Copy link to clipboard
Copied
Hi there!
I've spent so many hours on this problem, and tried so many permutations of 'Actions' and scripting, but I've run out of things to try. I'm on the verge of doing everything manually (which will take many hours), so I'm posting here in the hope that someone cleverer than me have figure out how to accomplish what I'm trying to do.
I have a composition where I'd like to grab a few points and run 'Transform>Rotate' by 1 degree, export the image, and repeat this action 360 times, incrementing the rotation by 1 degree each time.
What complicates this a little is that some of the points are connected to an object, but I'm only selecting a few of them. Rotating just some of the points creates an interesting 'chaos composition' (see attachment) – this is the effect I'm going for.
I can't do this rotation with 'Actions' because actions doesn't let me export the image with incrementing file names (I have to manually type it out each time).
However, I can do all this with a script, HOWEVER, the rotate function in my script produces different results than the 'in-app' 'transform>rotate' function.
Here's the script I use to rotate the composition with:
// Get the center point of the selection
var centerX = 0;
var centerY = 0;
for (var i = 0; i < selection.length; i++) {
centerX += selection[i].position[0] + selection[i].width / 2;
centerY += selection[i].position[1] - selection[i].height / 2;
}
centerX /= selection.length;
centerY /= selection.length;
// Perform rotation and export 360 times
for (var i = 0; i < 10; i++) {
// Rotate the selected objects around their collective center by -1 degree (counter-clockwise)
for (var j = 0; j < selection.length; j++) {
var obj = selection[j];
var angle = -1; // rotation angle in degrees
var rad = angle * Math.PI / 180; // convert angle to radians
// Get the object's current position
var objCenterX = obj.position[0] + obj.width / 2;
var objCenterY = obj.position[1] - obj.height / 2;
// Calculate the new position
var newX = Math.cos(rad) * (objCenterX - centerX) - Math.sin(rad) * (objCenterY - centerY) + centerX - obj.width / 2;
var newY = Math.sin(rad) * (objCenterX - centerX) + Math.cos(rad) * (objCenterY - centerY) + centerY + obj.height / 2;
// Set the new position
obj.position = [newX, newY];
// Rotate the object
obj.rotate(angle);
}
// Define the file name with the increment
var fileName = "RotatedImage_" + (increment + i) + ".png";
var file = new File(folderPath + fileName);
// Export the file
doc.exportFile(file, fileType, exportOptions);
}
I've also tried creating a script that runs an action that rotates the shape, but this doesn't yield the same result as 'native rotation' either.
Does anyone have experience with rotation and scripting and can potentially tell me what to change here?
Copy link to clipboard
Copied
I've also tried creating an Action that does this:
- 'native' rotation
- then export using a custom script ('save_script.jsx')
Then I made a script that would run the above action 360 times, but when I do this, I get an error message from Illustrator saying that 'save_script is not currently available'.
Copy link to clipboard
Copied
Hi @Subset, for a start you probably want to be working with the individually selected path points. You can do this like so:
var pathItem = app.activeDocument.selection[0];
var selectedPathPoints = [];
for (var i = 0; i < pathItem.pathPoints.length; i++)
if (PathPointSelection.ANCHORPOINT === pathItem.pathPoints[i].selected)
selectedPathPoints.push(pathItem.pathPoints[i]);
/* something with the pathpoints */
Note that PathPoint has anchor and a leftDirection and rightDirection which are all [x, y] points. See PathPoint docs. To do your rotation you can manipulate these directly (This may be preferable than using the rotate method of PathItem.)
Hope that gets you moving forward.
- Mark
Copy link to clipboard
Copied
Also, it might be really helpful to see a video of what you are doing manually. It isn't clear at the moment.
- Mark
Copy link to clipboard
Copied
I can't do this rotation with 'Actions' because actions doesn't let me export the image with incrementing file names (I have to manually type it out each time).
By @Subset
I have a trick to "loop" Actions.
- create a variable
- create 360 Datasets
- run your action in batch mode using the Datasets
- use the dataset names in your export file name