Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Increase Comp Resolution in Extendscript while keeping everything centered

Engaged ,
Mar 01, 2020 Mar 01, 2020

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)?
 
TOPICS
Expressions , How to , Scripting , SDK , User interface or workspaces
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 02, 2020 Mar 02, 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();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 02, 2020 Mar 02, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 03, 2020 Mar 03, 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();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 03, 2020 Mar 03, 2020
LATEST

I didn't realize you could check for keyframes like that. This is perfect. Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines