the referencing of a controller in MaxScript

the referencing of a controller in MaxScript

richardGRWZS
Participant Participant
2,066 Views
9 Replies
Message 1 of 10

the referencing of a controller in MaxScript

richardGRWZS
Participant
Participant

Hello everyone,

I'm a beginner and I'm stuck with the logic of the referencing of a controller in MaxScript.
I'm trying to create a script that requires referencing a controller that has either been created by a script or not. Despite reading the documentation, I'm feeling a bit lost...

  1. Is it possible to give a name to a controller when it's created? (the MaxScript listener remains silent when I rename it manually). I tried to add, without success, the line 'fs.name = "my_controller_name"' just after 'fs = Float_Expression()'.

  2. If not, how can I reference a 'Float Expression' controller since MaxScript doesn't seem to recognize the syntax 'Float Expression.controller' or 'Float_Expression.controller'?

 

masterRot = $Wheel_00

-- Point gizmo creation
pointObj = Point box:on size:5 pos:selectedObj.pivot

-- Add Float Expression controller to the point object
pointObj.rotation.controller.Z_Rotation.controller = float_list ()
fs = Float_Expression ()
pointObj.rotation.controller.Z_Rotation.controller.Available.controller = fs

-- //!\\ problematic line doing error: trying to do a connection with a controller on an other object
masterRotCtrl = execute (masterRot.name as string +".rotation.controller.Z_Rotation.controller.Float Expression.controller")

-- Filling the expression of the float expression controller
fs.addScalarTarget "Rot" masterRotCtrl
fs.addScalarConstant "n" nT
fs.addScalarConstant "nR" nTR
fs.SetExpression "-Rot/(n/nR)"

 

Thank you in advance,

0 Likes
Accepted solutions (1)
2,067 Views
9 Replies
Replies (9)
Message 2 of 10

denisT.MaxDoctor
Advisor
Advisor
cc = float_list()
ln = cc.available.controller = linear_float()
cc.setname 1 "Linear"
ex = cc.available.controller = float_expression()
cc.setname 2 "Expression"

cc[#linear].controller == ln
cc[#expression].controller == ex
0 Likes
Message 3 of 10

richardGRWZS
Participant
Participant

Thank you for your response!

I understand now how to set a name, I'm almost there. But there is still an unknown area for me:
If I understand correctly, a controller is like an object that you need to know the path to access, but I didn't understand how I can "reconstruct" this path when I don't have access to it directly in a variable !

If I take back my exemple updated with your explanations:

 

 

 

masterRot = $Wheel_00

-- Point gizmo creation
pointObj = Point box:on size:5 pos:selectedObj.pivot

-- Add Float Expression controller to the point object
local cc = pointObj.rotation.controller.Z_Rotation.controller 
cc = float_list ()
cc.available.controller = linear_float()
cc.setname 1 "Manual_Adjst"
fs = cc.available.controller = float_expression()
cc.setname 2 "SlaveRot"

-- Filling the expression of the float expression controller
-- //!\\ Problematic line: "syntax error: at [, expected name"
masterRotCtrl = execute ("$"+ masterRot.name as string +".Rotation.controller.Z_Rotation.controller.[#SlaveRot].controller")

fs.addScalarTarget "MasterRot" masterRotCtrl
fs.addScalarConstant "n" nT
fs.addScalarConstant "nR" nTR
fs.SetExpression "-MasterRot/(n/nR)"

 

 

 

 

So there is something wrong with this line 16 because i still don't anderstand how to build the path to target a specific controller :
masterRotCtrl = execute ("$"+ masterRot.name as string +".Rotation.controller.Z_Rotation.controller.[#SlaveRot].controller")

 

I tried with [#SlaveRot] > syntax error: at [, expected name

I tried also simply with 'SlaveRot' > error: Unknown property: "rotation" in undefined

 

Thank you again in advance

 

0 Likes
Message 4 of 10

istan
Advisor
Advisor

As you want to use "execute()" I'd enter

  $MASTERROTNAME.rotation.controller.Z_Rotation.controller.[#SlaveRot].controller

in the MXS listener and check why this line is outputting an error..

 

0 Likes
Message 5 of 10

richardGRWZS
Participant
Participant

You think the logic of the syntax is good but it's just a problem with my actual scene test ?

Here is a screenshot of my test with the manual request in the listener:

expression_problem.png 

0 Likes
Message 6 of 10

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

You're working with expression controllers the wrong way....

(I'm not talking about syntax errors now, but the concept as a whole)

 

look at my example, use MXS help to understand, ask questions if something is not clear:

 

(
	delete objects

	bx = box wirecolor:green
	cn = cone wirecolor:orange 
	bx.height.controller = linear_float()

	z_ex = cn.pos.controller[3].controller = float_expression()
	z_ex.addscalartarget "rise" bx.height.controller -- one way to pass a controller 
	z_ex.setexpression "rise"

	h_ex = cn.radius1.controller = float_expression()
	h_ex.addscalartarget "base" bx.baseobject[#height] -- another way to pass a controller
	h_ex.setexpression "base / sqrt(2)"
)

 

 

This example uses expression controllers to bind the 'z-position' and 'radius 1' of the cone with the height of the box.

 

 

0 Likes
Message 7 of 10

richardGRWZS
Participant
Participant

Thanks a lot for your help !

I feel stupid it tooks me so long to get it 😅 
It works fine for me now, so you can find below the modified code with what I understood from your comments:

masterRot = $Wheel_00

-- Point gizmo creation
pointObj = Point box:on size:5 pos:selectedObj.pivot

-- Add Float List controller to the point object
fs = pointObj.rotation.controller[3].controller = float_list ()

-- Rename the default "Bezier float" controller
fs.setname 1 "Manual_Adjst"

-- Création and filling the "Float Expression" controller
cc = float_expression()
masterRotCtrl = execute ("$"+ masterRot.name as string +".rotation.controller[3].controller.SlaveRot.controller")
cc.addScalarTarget "MasterRot" masterRotCtrl			
cc.addScalarConstant "n" 10
cc.addScalarConstant "nR" 40
cc.SetExpression "-MasterRot/(n/nR)"

-- Apply the "Float Expression" controller and rename it
fs[2].controller = cc
fs.setname 2 "SlaveRot"

 

If it can help other noob like me 👍
Thanks again and please don't hesitate to provide further feedback on the script exemple, even if it's working fine!

0 Likes
Message 8 of 10

denisT.MaxDoctor
Advisor
Advisor

@richardGRWZS wrote:

 


 

masterRotCtrl = execute ("$"+ masterRot.name as string +".rotation.controller[3].controller.SlaveRot.controller")

 

 

It doesn't make sense to me. That's how it should be:

 

masterRotCtrl = masterRot.rotation.controller[3].controller.SlaveRot.controller

 

 

 

0 Likes
Message 9 of 10

richardGRWZS
Participant
Participant

You are absolutely right; it's a remnant from the original script that I haven't cleaned up.

In my original script, 'masterRot' doesn't directly target the object I want. I need to add the prefix 'H_' to get it.
This results in: execute ("$H_"+ masterRot.name as string + "...")

 

0 Likes
Message 10 of 10

denisT.MaxDoctor
Advisor
Advisor

@richardGRWZS wrote:

You are absolutely right; it's a remnant from the original script that I haven't cleaned up.

In my original script, 'masterRot' doesn't directly target the object I want. I need to add the prefix 'H_' to get it.
This results in: execute ("$H_"+ masterRot.name as string + "...")

 


Using "execute" is completely irrelevant in this case. 

0 Likes