How keep the anchor in the Middle during the change of height and width for extendscript model?

When I try to change my composition height and width using extendScript, it works but with anchor point at the upper left corner. How to maintain it in the Center?

My code:

COMP. Width = 4000;

COMP. Height = 4000;

result:

result.jpg

expected:

expected.jpg

Thank you

OK, here is therefore the function for resizing of the model code. I tested several times with anchor points are offset on layers and centered, even with layers that are not yet within the limits of the Model Viewer. I'm sure there will be some users who eventually find something that will break it, but for now it seems to work perfectly.

app.beginUndoGroup("CompResize");
  var myComp = app.project.activeItem;
  resizeComp(myComp, 500, 500);
app.endUndoGroup();
/* TESTING ABOVE */

function resizeComp(compObj, newWidth, newHeight){
  if(typeof newWidth == "number" && typeof newHeight == "number"){
  if(compObj instanceof CompItem){
  var locData, allLayers, allLayersLen, curLayer, clAP, clPos, xShift, yShift, oldCW, oldCH, clH, clW, xOff, yOff;
  pData = new Array();
  cWidth = newWidth;
  cHeight = newHeight;
  allLayers = compObj.layers;
  allLayersLen = allLayers.length;
  oldCW = compObj.width;
  oldCH = compObj.height;
  compObj.width = cWidth;
  compObj.height = cHeight;
  for(var i=1; i<=allLayersLen; i++){
  curLayer = allLayers[i];
  clW = curLayer.width;
  clH = curLayer.height;
  clPos = curLayer.transform.position.value;
  clAP = curLayer.transform.anchorPoint.value;
  xShift = (oldCW - cWidth)/2;
  yShift = (oldCH - cHeight)/2;
  curLayer.transform.position.setValue([clPos[0] - xShift, clPos[1] - yShift]);
  }
  }else{
  alert("Invalid argument(1):\nComp Object required.");
  }
  }else{
  alert("Invalid argument(2/3):\nInteger required for Width and Height.");
  }
}

Tags: After Effects

Similar Questions

  • How can I control the monitor photo height and width with XP?

    Having 24 ' ASUS monitor.  There are no controls for the height and width of the image.  Operating system is Windows XP.  How can I change picture height and width?

    Hello

    You can try to change the resolution of the monitor screen and check if that helps.

    To change your screen resolution

    http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/display_change_screen_resolution.mspx?mfr=true

    If you want to change the position and other options that are provided as an option on the screen of the monitor you can see the manual provided by the manufacturer or contact the manufacturer for more information about the options provided in the monitor to change the position of the screen.

  • Definition of the values of height and width of a clip with XML file!

    How can I specify values of height and width of a clip using the external XML file? The user needs change the values of a specific clip [rectangular] using the xml file.

    How can I do?

    Thank you.

    You have difficulties with what part of the assistance from an xml file to store and retrieve data?  Do you know how to write the values of height and width, in the form of data in an xml file?  It could be something as simple as the following...

    200

    200

  • How to change the runtime of height and width of the front panel

    How to change the front height and width during execution. Basically, I want to decide height or width according to some parameters that I'm in the moment of execution.

    Ed johnsold was first

  • WiFi: keep the change 'search network' and 'on '.

    My wifi started to slow down and I realize that my WiFI: keeps changing to 'market' to 'the network search. I could not also connect them to "App Store". Help, please.

    This is normal and expected behavior in OS X. You can run a speed test and your connectivity.

    See also use the Diagnostics wireless for you help to solve the problems of Wi-Fi on your Mac - Apple Support .

  • What is the height and width for bitmap files in Flash?

    I am trying to import a huge game running track 8000 x 7000, and I have problems.  Any tips?

    Thank you!

    5761 we would say that the largest dimension, you can create in the ide, but with actionscript, you can use a lot of large dimensions.  somewhere between 11000000 which works and 12000000 that does not work.

  • Minimum height and width does not work in the responsive project

    I'm working on a responsive project in Captivate 9, breakpoint Office, for one of the items minimum height 50px and Minimum width to 50px.

    In points out of office and Tablet, she gets no smaller than 50px. However, breaking Mobile, point it turns into 32px Min-Height and Min-Width 4.0px.

    The 32px Min-Height and Min-Width 4.0px take a coral color in the breakpoint Mobile.

    Why don't the 50px which was update to stop Office remain the same on all breakpoints?

    What is the purpose? A 50 x 50 pixel png? I just create a project that is sensitive with a png of 200 x 200, placed in the desktop view and then set the size of the object and the height to 50 pixels. When I pass between breakpoints, the size remains the same. The size and position properties are all a light purple color on each breakpoint, which I guess means that these attributes are inherited from the Office discovers.

    If the boxes under "Height" and "Width" have transformed a coral-colored, I guess that means that these attributes have been changed for this breakpoint.

    And you obviously already know. I guess that I'm just trying to say that he expected to run, as it does for me!

    You are able to adjust these modified figures go back to your desired size? The same thing happens if you create, say, a dynamic square object in the view of the Office? Have you tried right clicking on the object in the desktop view and selecting "Apply position properties from all points of view"?

  • How to export pictures / albums of iPhotos to external disk and keep the time/date/year and location information changed?

    How to export pictures / albums of iPhotos to external disk and keep the time/date/year and location information changed?

    Menu, file == > export - check boxes to include metadata and location- export to iPhoto

    LN

  • How to keep the Macbook pro screen and cin on position?

    How to keep the Macbook pro screen and computer in position 'on '.  I don't want the computer shuts down or cut unless I ask him to...

    If you talk to keep your machine to fall asleep, take a look at the caffeine.

  • In the middle of my teens adding devices, and registration for the apple's music, security issues have been changed and now nobody seems to remember the answers.  How can you bypass those to change your settings?

    In the middle of my teens adding devices, and registration for the apple's music, security issues have been changed and now nobody seems to remember the answers.  How can you bypass those to change your settings?

    You must ask security team account Apple to reset your security questions. To contact them, click here and choose a method; If this page does not list one for your country or if you are unable to call, complete and submit this form.


    (140233)

  • Preview not to honor «to ask to keep the changes...» "setting.

    Everything by testing the question of a user in the preview before moving a text box annotate, it turns out that the preview auto-saved the Annotation despite "to ask to keep the changes when closing documents" activated.

    Okay, I found the problem. If you have 'Close the windows when you exit an application' disabled, tell so you can still open Safari in fullscreen for example, it leaves the document in a "legal vacuum". When I activated "close windows...". "and reopened the image in preview and then quit, he asked if I wanted to save the document and I chose"Changes throw", no more modifications I made.

    There are certainly many "quirks" in El Capitan.

  • Hello. I so want to know if there is a way to keep the photos on icloud and get them deleted on your iphone, so that there is no problem of storage of the device

    Hello. I so want to know if there is a way to keep the photos on icloud and get them deleted on your iphone, so that there is no problem of storage of the device.

    iCloud is a synchronization system, not an external 'hard drive '. If you remove them on your device, they will remove icloud. To increase the available space, go settings/iCloud/Photos and select optimize iPhone/iPad storage. That will reduce the space required by 90% when it is fully effective.

  • How can I set the default font size and type for the outgoing Hotmail mail?

    How can I set the default font size and type for the outgoing Hotmail mail?

    Hi Dale,

    What is the email client do you use?

    Outlook can be configured per - start Outlook-> Tools-> Options-> mail-> fixed Format and fonts... Select the font and size you need... Click ok on all screens.

    I hope this helps.

  • What is the best way to resize an image, but keep the height and width of the same original size or format?

    What is the best way to resize an image, but keep the height and width of the same original size or format?

    I tried to use the function of the size of the Image, but when I changed the size of the image, the width has not changed with it.

    Thanks for the tips!

    Hi Landon.Luu,

    You want to keep the relationship between the width and height to be the same?

    Click the constraint between width and height to keep the ratio intact.

    Kind regards

    Claes

  • Hi, how do I change the orientation of the page with headers and footers for facing pages

    Hello

    How to change the orientation of the page with headers and footers for facing pages in CS5

    Turning the page is only for the formatting of data - the page is not literally transformed for printing.

    In most print even if the pages of a book are enabled for the landscape, the header and the footer are still in the same position.

    If you need pages in landscape mode with headers and footers in a different location - you need to do these pages in the section "Master Pages" of the Pages panel

    Then apply these new Master Pages to the pages in your document.

    http://helpx.Adobe.com/InDesign/using/master-pages.html

    Note - it is not usual to have a different orientation for the headers and footers.

Maybe you are looking for