PDA

View Full Version : Maxscript Float Expressions help....


lucpet
12-07-2010, 01:29 AM
Screen Capture (http://picasaweb.google.com/lh/photo/BAvqxPEQh4fiD3HKtLUyiw?feat=directlink)

Hi I'm trying to understand Float Expressions and using the macro recorder in ms to find out how things are constructed, but not getting anywhere.

I have a bezier float on the cylinder and am now trying to set up the point helper with a float exspression with r as the scalar value and assigned to the $Crank.Height (cylinder) using maxscript.

I've looked up the Maxscript help but readily admit it's all Greek to me and would appreciate someone dumbing it down for me.

PiXeL_MoNKeY
12-07-2010, 02:28 AM
This should do what you need, this is step by step. For cleaner code I would set variables as needed to shorten/optimize the code.--Make sure Crank has its height set as a bezier_float()
$Crank.height.controller = bezier_float()
--Set the controller for the Z position of "point A"
$'point A'.position.controller[3].controller = float_expression()
--Set the Crank.height controller as the scalar target "r"
$'point A'.position.controller[3].controller.AddScalarTarget "r" $Crank.height.controller
--Set the expression for the Expression controller to "r"
$'point A'.position.controller[3].controller.setExpression "r"-Eric

lucpet
12-07-2010, 04:23 AM
Thanks a lot Pixel Monkey, worked like a charm after I picked up on a typo "AddScalarTarget"

The [3] referring to the z height I'm assuming.

The maxscript help has this bit of gibberish in it <&TSTR> is there a translation I'm missing somewhere.


Any way appreciate the quick reply
Thanks again

PiXeL_MoNKeY
12-07-2010, 09:20 PM
Yes the [3] refers to z parameter of the Position_XYZ controller of 'point A'. You can also access it using .z_postion:--Make sure Crank has its height set as a bezier_float()
$Crank.height.controller = bezier_float()
--Set the controller for the Z position of "point A"
$'point A'.position.z_position.controller = float_expression()
--Set the Crank.height controller as the scalar target "r"
$'point A'.position.z_position.controller.AddScalarTarget "r" $Crank.height.controller
--Set the expression for the Expression controller to "r"
$'point A'.position.z_position.controller.setExpression "r" Fixed the typo also, sorry about that, that's what I get for trying to code late in the evening. ;)

-Eric

lucpet
12-07-2010, 10:35 PM
lol don't apologise it forced me to study the code a bit more thoroughly than I would of. I'm further along and have run into a slightly more complicated part of the process but I'll spend another day trying to work it out before crawling back to the forums for more help.

Again thanks for the help, don't know what I'd do without this site :bowdown:

lucpet
12-08-2010, 12:46 AM
Screen Shot (http://picasaweb.google.com/lh/photo/u3WDpqjBe4uPUCuyAwcO5A?feat=directlink)

Ok the final part of the process involves adding to point B's x position
3 variables with different assignment to different controllers "I've broken it down in the screenshot
1 = the "r"
2 = the "L"
3 = all three with Yrot and the long expression

The trouble I'm having is tieing it all together

Here's what I've got so far

--Set the controller for the x position of "point B"
poB.pos.controller.X_Position.controller = Float_Expression ()
-- Set the Crank.height controller as the scalar target "r"
poB.pos.controller.X_position.controller.AddScalarTarget "r" cr.height.controller
-- Set the expression for the Expression controller to "r"
poB.pos.controller.X_position.controller.setExpression "r"
poB.pos.controller.X_position.controller.AddScalarTarget "L" rd.height.controller
-- Set the expression for the Expression controller to "L"
poB.pos.controller.X_position.controller.setExpression "L"

and the error message I get is:----

-- Error occurred in anonymous codeblock; filename: C:\Users\Luke\Maxscript\Piston.ms; position: 2184; line: 56
-- Runtime error: IExprCtrl::AddScalarTarget - Target needs to be controller or subAnim, got: undefined
-- Error occurred in anonymous codeblock; filename: C:\Users\Luke\Maxscript\Piston.ms; position: 2324; line: 58
-- Runtime error: IExprCtrl::SetExpression - Expression parse error: L

So am I missing a global/local declareation or should I go back to licking windows instead of maxscript
The help file needs a help file for idiots :)

PiXeL_MoNKeY
12-08-2010, 03:15 AM
So am I missing a global/local declareation or should I go back to licking windows instead of maxscriptWell there is your problem, licking windows will get you know where, but a second date.The help file needs a help file for idiots :)I guess that is what I am (and others are) here for.

No where in that code that you posted do you define cr or rd, yet you are trying to use their height controllers. Remember the height.controller of undefined will be, can you guess? If they are defined then it is something else. Could you post the scene and script you are running so I can look at it?

-Eric

lucpet
12-08-2010, 03:44 AM
ch = dummy name:"Chassis"
poO = point name:"point O" size:15
poA = point size:15 name:"point A" pos:[0.0, 0.0, 20.0]
poB = point name:"point B" size:15 pos:[45.0, 0.0, 0.0]
cr = cylinder name:"Crank" radius:2.5 height:20
rd = cylinder name:"rod" radius:2.5 height:50 pos:[0.0, 0.0, 20.0]
rotate rd (angleaxis 113.578 [0,1,0])
ps = cylinder name:"Piston" radius:9.0 height: 20.0 pos:[37.5, 0.0, 0.0]
rotate ps (angleaxis 90.0 [0,1,0])

----------------------------------------------------
poO.parent = ch
cr.parent = poO
poA.parent = cr
-----------------------------------------------------------

--Make sure Crank has its height set as a bezier_float()
cr.height.controller = bezier_float()
--Set the controller for the Z position of "point A"
poA.position.z_position.controller = float_expression()
--Set the Crank.height controller as the scalar target "r"
poA.position.z_position.controller.AddScalarTarget "r" cr.height.controller
--Set the expression for the Expression controller to "r"
poA.position.z_position.controller.setExpression "r"

--------------------------------------------------------

rd.rotation.controller = LookAt_Constraint ()
rd.rotation.controller.appendTarget poB 50
rd.rotation.controller.target_axis = 2
rd.rotation.controller.upnode_axis = 1
rd.rotation.controller.StoUP_axis = 1
rd.rotation.controller.viewline_length_abs = off
---------------------------------------------------------------

poB.parent = ch
ps.parent = poB
rd.parent = poA

------------------------------------------------------------

set animate on
sliderTime = 10f
rotate poO (angleaxis 360 [0,1,0])
setAfterORT poO #linear

------------------------------------------------------------


--Set the controller for the x position of "point B"
poB.pos.controller.X_Position.controller = Float_Expression ()
-- Set the Crank.height controller as the scalar target "r"
poB.pos.controller.X_position.controller.AddScalarTarget "r" cr.height.controller
-- Set the expression for the Expression controller to "r"
poB.pos.controller.X_position.controller.setExpression "r"
poB.pos.controller.X_position.controller.AddScalarTarget "L" rd.height.controller
-- Set the expression for the Expression controller to "L"
poB.pos.controller.X_position.controller.setExpression "L"


Here is the code so far
and the Tutorial I'm trying to script is here
Moving a piston with math (https://www.youtube.com/watch?v=-02mLcuNutQ)

lucpet
12-09-2010, 02:33 AM
ok sorted out my mistake although still stuck on the Yrot part of it I'm mixing up the type of controller it needs.

--Set the controller for the x position of "point B"
poB.pos.controller.X_Position.controller = Float_Expression ()
-- Set the Crank.height controller as the scalar target "r"
poB.pos.controller.X_position.controller.AddScalarTarget "r" cr.height.controller
-- Set the expression for the Expression controller to "r"
poB.pos.controller.X_position.controller.setExpression "r"

--Set the controller for the x position of "point B"
rd.height.controller = bezier_float()
-- Set the Crank.height controller as the scalar target "L"
poB.pos.controller.X_position.controller.AddScalarTarget "L" rd.height.controller
poB.pos.controller.X_position.controller.setExpression "L"


This is the problem now Probably because I've been at it for hours
--Set the controller for the y rotation of "point o"
poB.pos.controller.X_Position.controller = bezier_float()
poB.pos.controller.X_position.controller.AddScalarTarget "Yrot" poO.Y_rotation
-- Set the expression for the Expression controller to "Yrot"
poB.pos.controller.X_position.controller.setExpression "r*sin(radToDeg(Yrot))+sqrt(L^2-(r^2*cos(radToDeg(Yrot))^2))"

PiXeL_MoNKeY
12-10-2010, 04:17 AM
Sorry for the delay, but you have a few problems.
1) Don't set "poB.pos.controller.X_Position.controller = bezier_float()" as that removes the float expression.
2) This is the wrong target "poB.pos.controller.X_position.controller.AddScalarTarget "Yrot" poO.Y_rotation" to access the Y rotation.
3) You need to set the y rotation keys to linear, instead of auto.
4) You should probably set the in and out Out-of-range type for poO to linear.
5) You need to turn animate off or anything you do manually afterward will be auto-keyed even though autokey is off.

Here is the complete and fully working code, code changes/additions in blue and removed items in red:ch = dummy name:"Chassis"
poO = point name:"point O" size:15
poA = point size:15 name:"point A" pos:[0.0, 0.0, 20.0]
poB = point name:"point B" size:15 pos:[45.0, 0.0, 0.0]
cr = cylinder name:"Crank" radius:2.5 height:20
rd = cylinder name:"rod" radius:2.5 height:50 pos:[0.0, 0.0, 20.0]
rotate rd (angleaxis 113.578 [0,1,0])
ps = cylinder name:"Piston" radius:9.0 height: 20.0 pos:[37.5, 0.0, 0.0]
rotate ps (angleaxis 90.0 [0,1,0])
----------------------------------------------------
poO.parent = ch
cr.parent = poO
poA.parent = cr
-----------------------------------------------------------
--Make sure Crank has its height set as a bezier_float()
cr.height.controller = bezier_float()
--Set the controller for the Z position of "point A"
poA.position.z_position.controller = float_expression()
--Set the Crank.height controller as the scalar target "r"
poA.position.z_position.controller.AddScalarTarget "r" cr.height.controller
--Set the expression for the Expression controller to "r"
poA.position.z_position.controller.setExpression "r"
--------------------------------------------------------
rd.rotation.controller = LookAt_Constraint ()
rd.rotation.controller.appendTarget poB 50
rd.rotation.controller.target_axis = 2
rd.rotation.controller.upnode_axis = 1
rd.rotation.controller.StoUP_axis = 1
rd.rotation.controller.viewline_length_abs = off
---------------------------------------------------------------
poB.parent = ch
ps.parent = poB
rd.parent = poA
------------------------------------------------------------
set animate on
sliderTime = 10f
rotate poO (angleaxis 360 [0,1,0])
set animate off
-- Set the before and after Out-of-range Type to linear, not just the after
setBeforeORT poO #linear
setAfterORT poO #linear
------------------------------------------------------------
rd.height.controller = bezier_float()
--Set the controller for the x position of "point B"
poB.pos.controller.X_Position.controller = Float_Expression ()
-- Set the Crank.height controller as the scalar target "r"
poB.pos.controller.X_position.controller.AddScalarTarget "r" cr.height.controller
-- Set the expression for the Expression controller to "r"
poB.pos.controller.X_position.controller.setExpression "r"
poB.pos.controller.X_position.controller.AddScalarTarget "L" rd.height.controller
-- Set the expression for the Expression controller to "L"
poB.pos.controller.X_position.controller.setExpression "L"
------------------------------------------------------------
-- Set the in and out tangents for the y rotation keys to linear
for val in poO.rotation.controller.y_rotation.controller.keys do (
val.inTangentType = val.outTangentType = #linear
)
--Set the controller for the y rotation of "point o"
--poB.pos.controller.X_Position.controller = bezier_float()
poB.pos.controller.X_position.controller.AddScalarTarget "Yrot" poO.rotation.controller.y_rotation.controller
-- Set the expression for the Expression controller to "Yrot"
poB.pos.controller.X_position.controller.setExpression "r*sin(radToDeg(Yrot))+sqrt(L^2-(r^2*cos(radToDeg(Yrot))^2))"-Eric

lucpet
12-10-2010, 06:19 AM
Once again thanks Eric.
I'd spotted the set animate off problem this morning and fixed it.

The
"-- Set the in and out tangents for the y rotation keys to linear
for val in poO.rotation.controller.y_rotation.controller.keys do (
val.inTangentType = val.outTangentType = #linear"
would have posed a problem later on as mine are set to linear as default and wouldn't have spotted it until much later.

I was really stuck on the last bit Yrot and tried pretty much every variation I could think of except removing that first line lol

Thanks cheers :beer: :bowdown: :thumbsup:

CGTalk Moderation
12-10-2010, 06:19 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.