Skip to main content
johnt53984649
Inspiring
March 2, 2020
Question

Increase Comp Resolution in Extendscript while keeping everything centered

  • March 2, 2020
  • 1 reply
  • 2159 views

When I use the following to increase the resolution of a composition in extendscript:

 

mycomp.width = width
mycomp.height = height
 
The compositions resolution changes, but the positions of all items in the comp remain identical. This is the not the same as changing the composition resolution through the dialog box manually, which adjusts the positions accordingly (so the items remain centered).
 
Here's a video showing my problem. What does my script need to look like so that I don't get the black bars (I want the same effect as changing the resolution manually)?
 
This topic has been closed for replies.

1 reply

Tomas Sinkunas
Legend
March 2, 2020

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();
johnt53984649
Inspiring
March 3, 2020

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?

Tomas Sinkunas
Legend
March 3, 2020

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