Activity › Forums › Adobe After Effects Expressions › Clamping x position on after effects
-
Clamping x position on after effects
Posted by Gabriel Rocha on October 8, 2012 at 8:42 pmhello,
Is there a way to clamp a X Position opn after effects on several different values?
I’ve been using this code:x1=1024.3322
x2=1224.1572
clamp(transform.xPosition,x1,x2)
if (transform.xPosition>x1) {
transform.xPosition=x2;
}But that only allows me to snap from one position to another. I’d like to be able to snap into 6 positions (on X dimension).
is there a way to do that?
I use the Snaped position to get the position value and use in another layer but i really need to be clamped.
Thanks,GR
Meng Zhang replied 9 years, 3 months ago 3 Members · 13 Replies -
13 Replies
-
Dan Ebberts
October 8, 2012 at 8:56 pmSomething like this should work:
xVals = [1024,1224,1444,1624,1824,2024];
i = 0;
while (value > xVals[i] && i < (xVals.length-1)) i++;
xVals[i]Dan
-
Gabriel Rocha
October 9, 2012 at 12:54 pmHey Dan,
I knew you would come for the Help.
Right now for some reason it’s not working.
im not sure if i made myself 100% clear.
Check the file i uploaded as an example of what i have now. Just slide the layer to On and OFF.
Download the AEP here:
https://www.sendspace.com/file/gjj1piBut instead of ON and OFF i would have Value 1, Value, 2 Value 3, Value 4…
Im adding your code on the xPosition but i get the Layer stuck in one single position.
Thanks again for your help! -
Gabriel Rocha
October 9, 2012 at 12:57 pmok forget about it.
The code you sent wasn’t working on my original Project, but its working on a plain project (like the one i uploaded). SO it must be something on my previous project.
I’ll check it out! Thanks man. You rock! -
Gabriel Rocha
October 10, 2012 at 8:23 pmHey Dan,
What if i want to slide a layer on the xPosition, but having a limitation.
Let`s say i want to slide it from 1024 to 1530, not clamping just being able to slide from 1024 to 1530, limiting the beginning and the end to those values?
I`ve found similar possibilities, but none quite the same here on CC.
THanks again in advance,GR
-
Dan Ebberts
October 10, 2012 at 8:36 pmAre you talking about something different than just right-clicking on the slider value in the Effect Controls window and setting the slider range?
Dan
-
Gabriel Rocha
October 10, 2012 at 8:42 pmYes, i want to do that on the Viewport.
I know about the slider, checkbox and stuff on the Effects tab, but i want to do that on the viewport. you know what i mean? -
Dan Ebberts
October 10, 2012 at 8:57 pm> you know what i mean?
Sorry, I’m not sure. By “Viewport” do you mean the Comp window?
If you’re talking about an expression that would keep you from dragging a layer outside that range, that be a clamping expression for X Position like this:
clamp(value,1024,1530)
If not, I’m not sure what you’re trying to do.
Dan
-
Gabriel Rocha
October 10, 2012 at 9:01 pmActually that’s perfect.
I didn’t know Clampping would give me that result.
I thought that clamping would be more like snapping.
THanks again man, that helped! -
Meng Zhang
April 10, 2017 at 5:10 pmThat’s awesome. Does anyone know how can I limit the position within a polygon, like a mask or shape layer? I have been searching for this, but no luck. Thanks guys!
-
Dan Ebberts
April 10, 2017 at 8:17 pmI don’t think there’s a practical way to do that. You could hack something together with sampleImage() on a shape layer, but it would be quite a bit of work to get it set up.
Dan
Reply to this Discussion! Login or Sign Up