-
After Effects Scripting – swapping composition dimensions
Hey hey!
I work with both HD portrait and landscape video and I often need to swap between the dimentions so I’ve created a little script that basically swaps the X and Y dimensions of a comp:
var comp = app.project.activeItem;
var compSize = [comp.width,comp.height];
comp.height = compSize[0];
comp.width = compSize[1];eg. 1920×1080 becomes 1080×1920 (instead of opening the comp setting and changing it manually)
It works but the problem I’m having is that the content of the comp does not behave in the same way that it does when you change it manually. When you change the comp size manually, position properties of all layers update so they are relative to the frame size. For Example:
A 1920×1080 comp has a solid which is centred in the frame at position 960,540…. If i change the comp dimensions manually (using composition setting window) to 1080×1920, the comp appears to resize from the centre and the solid position will remain in the centre of the frame but will have a new position value of 540×960. If i use the script however, the solid’s position will not change (as if the composition is being scaled from the top left) and will then end up in a different position (visually speaking).
Is there something i can add to the script which will make the changing of the frame size behave the same as if i was doing it manually with the composition settings window, ie. have the comp resize from the centre.
I understand it might seem odd why i want to do this, but it’s part of a larger.
Any light you can shed would be amazing!
Thanks!
Tom