[Closed] functions using execute
Hi
Im working on a quickie tool to assign noise / scripts controllers to selected objects.
I want to be able to only assign to fx x position and so on.
To reduce the amount of functions needed ive constructed functions so that I send the axis to the function as a string and then in the function construct the expression as a string and then execute it using execute.
below is a simple function trying to assign a float_list controller this way…
fn f_ctrl objs axis =
(
for obj in objs do
(
p0 = obj.pos.controller as string
p1 = axis
p2 = “.controller = float_list()”
cmd = p0 + p1 + p2
execute cmd
)
)
f_ctrl selection “.y_position”
whenever you work with execute, add a debug statement that prints the command you’ll be executing; makes it easier to identify the problem.
In your case, an example command getting execute is:
"Controller:Position_XYZ.y_position.controller = float_list()"
which, as you may imagine, can’t be right
Try…
fn f_ctrl objs axis =
(
for obj in objs do
(
p0 = exprForMAXObject obj
p00 = ".pos.controller"
p1 = axis
p2 = ".controller = float_list()"
cmd = p0 + p00 + p1 + p2
-- print cmd
execute cmd
)
)
f_ctrl selection ".y_position"
There’s easier ways to do what you want, by the way – without using execute
darn enter key.
fn f_ctrl objs axis =
(
for obj in objs do
(
setPropertyController obj.pos.controller axis (float_list())
)
)
f_ctrl selection "y_position" -- note: no period in front!
Seems to work perfect – and not at all as messy as my approach – thankyou very much