Copy link to clipboard
Copied
When I use the following to increase the resolution of a composition in extendscript:
Copy link to clipboard
Copied
You need to shift all the layers in the comp by sizeDelta/2, like this:
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem)) {
return alert('Please select composition first');
}
var widthOld = composition.width;
var widthNew = widthOld * 2;
var widthDelta = widthNew - widthOld;
var heightOld = composition.height;
var heightNew = heightOld * 2;
var heightDelta = heightNew - heightOld;
app.beginUndoGroup('change comp size');
composition.width = widthNew;
composition.height = heightNew;
for (var i = 1, il = composition.numLayers; i <= il; i ++) {
var layer = composition.layer(i);
var positionProperty = layer.property('ADBE Transform Group').property('ADBE Position');
var positionValue = positionProperty.value;
positionProperty.setValue(positionValue + [widthDelta/2, heightDelta/2]);
}
app.endUndoGroup();
Copy link to clipboard
Copied
Thank you, but I'm afraid this won't work if any of the layers have their position keyframed. How would you account for that?
Copy link to clipboard
Copied
Here's how it could work for keyframed layers
var composition = app.project.activeItem;
if (!composition || !(composition instanceof CompItem)) {
return alert('Please select composition first');
}
var widthOld = composition.width;
var widthNew = widthOld * 2;
var widthDelta = widthNew - widthOld;
var heightOld = composition.height;
var heightNew = heightOld * 2;
var heightDelta = heightNew - heightOld;
var offset = [widthDelta / 2, heightDelta / 2];
app.beginUndoGroup('change comp size');
composition.width = widthNew;
composition.height = heightNew;
for (var i = 1, il = composition.numLayers; i <= il; i++) {
var layer = composition.layer(i);
var positionProperty = layer.property('ADBE Transform Group').property('ADBE Position');
if (positionProperty.numKeys > 0) {
for (var j = 1, jl = positionProperty.numKeys; j <= jl; j++) {
var keyValue = positionProperty.keyValue(j);
positionProperty.setValueAtKey(j, keyValue + offset);
}
} else {
var positionValue = positionProperty.value;
positionProperty.setValue(positionValue + offset);
}
}
app.endUndoGroup();
Copy link to clipboard
Copied
I didn't realize you could check for keyframes like that. This is perfect. Thank you so much!