How can I have a variable driven formula field in Xpresso?


#1

I have a Formula Effector and want to manipulate its’ formula from Xpresso.

The formula is round(rnd(4;24546))

I want to have the seed part of rnd() as a user input. I thought of just having the formula hardcoded in nodes but their is no round() node.

And then I thought to just write the formula in Python but the script gets yellow.

import c4d
import random as r

def main():
    global Output1
    r.seed(Input1)
    Output1 = round(r.randint(1,4))

#2

You can create the formula using math add data type string -

math_add


#3

I know but I can’t find the round() math node.


#4

A round function with rounding to a given number of digits is not available, but just converting from real to integer using a Universal adapter node can do the trick in many cases. Or a simple Python node


#5

Or if you need rounding to a certain number of digits and don’t want to use Python, simply do a float multiplication (Math node) by 10 (for rounding to the first fractional digit, more zeros (100, 1000,…) for more fractional digits) and afterwards do a integer division (again Math node) by the same number.