Skip to main content
Inspiring
January 19, 2012
Answered

Math.round for Shape layers to land on whole pixels?

  • January 19, 2012
  • 1 reply
  • 2534 views

Trying to keep my shape layers on whole pixels to avoid subpixel blurring.

For one-dimensional properties, this works fine:

Math.round(value);

But for two dimensional props, I'm running into errors with things like this:

temp = Math.round(content("Rectangle 1").content("Rectangle Path 1").size.value)

(temp[0],temp[1])

temp = Math.round(content("Rectangle 1").content("Rectangle Path 1").size)

(temp[0],temp[1])


I'm sure my syntax is off. Properties in arrays always give me problems. Can you help?

This topic has been closed for replies.
Correct answer Dan Ebberts

Your expression works perfectly for Shape Layer size.  But when I alter it for Transform>Position, I get a "class Global has no property named 'temp' error.

Isn't Postion an array like Shape Layer>Size?

temp = thisComp.layer("Shape Layer 1").transform.position.value

[Math.round(temp[0]),Math.round(temp[1])]

Is it possible to construct a more general purpose expression by using temp = value without having to use thisComp.layer("layername").etc?


You're just missing a semi-colon at the end of the first line.

In answer to your second question, yes--in fact this will work:

[Math.round(value[0]),Math.round(value[1])]

Dan

1 reply

Dan Ebberts
Community Expert
Community Expert
January 19, 2012

Math.round() won't work with an array, so you need to use it twice, like this

(Math.round(temp[0]),Math.round(temp[1]))

Dan

Inspiring
January 19, 2012

When I use your suggestion:

temp = Math.round(content("Rectangle 1").content("Rectangle Path 1").size);     >> or   .size.value

(Math.round(temp[0]),Math.round(temp[1]))

I'm getting a error. Also errors with the simpler, self referring expression:

(Math.round(value[0]),Math.round(value[1]))

Dan Ebberts
Community Expert
Community Expert
January 19, 2012

Sorry, it should be like this:

temp =content("Rectangle 1").content("Rectangle Path 1").size.value;

[Math.round(temp[0]),Math.round(temp[1])]

I didn't test it, but it should be close.

Dan