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

after effects jsx reset position

Community Beginner ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

I need a quick way to reset the position of a selected layer to 0,0.
I found this jsx script:
https://github.com/kyletmartinez/After-Effects-Scripts/blob/bb0c5f7ce7584457fc8c58bb070c37e15f86918d...

which zero’s the position but creates a null to do so.

*I just want to change the x and y values back to 0 like a reset position function*

(Its for a character rig / head rotation layer that I constantly need to reset to 0 so i can make changes to the default position of the head and then move the x y coordinates to see if the change was successful.)
I can then add this .jsx file to a kbar icon and then it would be super fast fixing my character rigs in the future.

thank you and it would save me so much time if someone had a solution. not much of a coder but can copy paste and understand with trial and error.

TOPICS
Scripting

Views

738

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Beginner , Dec 01, 2022 Dec 01, 2022

Thank you. i shouldn't have used the word "reset". I just want to have a kbar button that when i press it, the selected layer's x and y coordiantes become 0, 0. 
@Rick Gerard 
Its for a head rig controller that is faking a 3d rotation look. The ctrl middle/neutral is 0,0. I can only attach moustaches, new eyes etc when the ctrl is 0,0. But because I need to test left/ right /up/ down alot to get the head rig looking right, I find I am losing time typing in 0,0 all the time to make the ctrl neutral

...

Votes

Translate

Translate
LEGEND , Dec 01, 2022 Dec 01, 2022

You will of course need all the code that defines what the zeroLayer actually is, but the code could be stripped down massively and still work. That is if you don't care for extra safeguards and are reasonably sure you will always use it correctly. The script engine will simply fire the commmand and hope for the best. So in its most barebones form somethin like

 

selectedLayers.transform.position.setValue()

 

Should work within the limitations laid out.

 

Mylenium

Votes

Translate

Translate
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Position reset always returns a layer's position to half the comp width and half the comp height. 

A Text layer and a Shape layer always have the Anchor Point set to 0, 0. All other layers have the anchor point set to half the layer width and half the layer height. 

 

If you reset a layer's position to 0, 0, it would be in the upper left corner of the composition. If the Anchor Point were at the default position, anything but a shape or text layer, then the layer would only show the bottom right quarter of the layer. That's not usually a very useful starting or ending position for any element. 

 

Text layers content relative to the Anchor Point is based on Paragraph Justification (left, right, center) and baseline shift. A shape layer element can be anywhere, so you have to compare shape layer content position properties to the default (0, 0) or use the Pan Behind tool to set the anchor point over the content of the shape layer. With either of those layers, resetting the Position to 0, 0 would not be a very useful tool.

 

If you can explain a situation where you would benefit by snapping a layer to the upper left corner of a composition more than you would benefit from snapping a layer to the comp center, I'm all ears. 

 

Rigging a character usually involves images of body parts on separate layers. Snapping the Anchor Point to the joint position would be useful, and if the artwork is properly prepared, it's even possible. Having a shortcut that knows whether the artwork was a hand or a foot, or a head and put the Anchor Point in the right spot is asking a lot. Properly preparing the artwork in Illustrator or Photoshop and layering all of the body parts appropriately, then importing the layer as a composition and retaining layer size is the best place to start. If you are using a third-party Character Rig Script or you are rigging by hand, you'll still have to place every null exactly where it needs to be before you parent the body part to the rig. I don't think there are any AI tools out there that can tell the difference between an eyebrow and lips or a left or right hand and rig the character for you with the click of a button. 

Votes

Translate

Translate

Report

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
LEGEND ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Agree with Rick. Just absolutely resetting the position is probably not that useful, especially if the layer itself is part of some hierarchy. Would be simple, though. You'd basically just modify this line to have fixed values:

 

zeroLayer.transform.position.setValue([0,0]);

 

Mylenium

Votes

Translate

Translate

Report

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
Community Beginner ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Thank you. i shouldn't have used the word "reset". I just want to have a kbar button that when i press it, the selected layer's x and y coordiantes become 0, 0. 
@Rick Gerard 
Its for a head rig controller that is faking a 3d rotation look. The ctrl middle/neutral is 0,0. I can only attach moustaches, new eyes etc when the ctrl is 0,0. But because I need to test left/ right /up/ down alot to get the head rig looking right, I find I am losing time typing in 0,0 all the time to make the ctrl neutral again, so i can fix the rig and test again. I should also add these x,y values can be seperated in some head rigs also. not sure if that makes the code any harder.


**I found a solution where i just select the 0,0 values of the xy and make a animation preset. attach the newly created .ffx file to a kbar button and presto it works!

 

-i am interested in this answer though:
@Mylenium with that code presented do i change the zeroLayer part to "selectedLayer" does something like that work? and then this all goes into a .jsx file that i can execute when i select any object?

Thanks for you time also, ive learnt alot today.




Votes

Translate

Translate

Report

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
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

I am going to have to see a screenshot with all the layers in place and the position properties of each layer as well as their anchor points revealed. 

 

Changing the position property of a layer does not change where the layer is scaled from. If your character rig is going to distort a mustache when the head is distorted to fake a 3D look, then simple parenting is probably the answer. 

RickGerard_0-1669964761443.gif

 

 

Votes

Translate

Translate

Report

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
Community Beginner ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

Hi Rick, 

thanks for your time, ive solved the 0,0 issue with a easy animation preset linked to a kbar button.
Here is the setup which explains the rig a bit better. Im using shape layers to shrink the layers as they rotate on the x axis. all layers are attached to a main null head rotate. The moustache is broken into Left and right and has a axis at the center of the nose and then they bend on a Y rotation as the head turns right.  All duik connector expressions for each property. came out great 🙂 hope this explains the setup better and maybe helps out someone.

3dface.gif

Votes

Translate

Translate

Report

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
LEGEND ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

You will of course need all the code that defines what the zeroLayer actually is, but the code could be stripped down massively and still work. That is if you don't care for extra safeguards and are reasonably sure you will always use it correctly. The script engine will simply fire the commmand and hope for the best. So in its most barebones form somethin like

 

selectedLayers.transform.position.setValue()

 

Should work within the limitations laid out.

 

Mylenium

Votes

Translate

Translate

Report

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
Community Beginner ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

@Mylenium Great jumping off point thank you. 

Votes

Translate

Translate

Report

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