ScriptSpot

Forum topic · General Scripting

AddTarget - Float scripts

By Matyrix · 2010-09-11

Description

Hello,

How can i use the AddTarget option in float scripts? I dont't want to write a new script to solve this problem, but where i have to write this "AddTarget" to make it works, and what i have to write punctually?...

I searched for solution on scriptspot and cgtalk, but i didn't found what i want, only separated scripts which solve this, i think (hope) it could works without any other scripts...

For example: There is three spheres. (Sphere01, Sphere02, Sphere03). I give to the Sphere01 that it's position controller be a float script, and in this script write that "$Sphere02.pos". So it will be always where the Sphere02 is. But if i link the Sphere02 to the Sphere03, and i move the Sphere03, the 01 is not updated by the script. Only when i move the Sphere02...

What i have to do in this case?

Thanks the answer(s) in advance!

Comments (11)

Matyrix · 2010-09-12

So... I want to use the AddTarget option in float script. Because i have a character rig, and there are a lot of cases where is a good opportunity the AddTarget.
This is why i wrote this little example, because more easy to comment on it.

This sphere example is not my problem, it's just a little model of my problem.

The problem is AddTarget usage.

So please if anybody knows how can i use this AddTarget (what is the right usage by an example, and where i have to write this), please let me know.

Thanks in advance and thanks the comments! :)

Anubis · 2010-09-13

Hi Matyrix, an example for AddTarget usage is available in the help - "float_script - FloatController > Target (Track) Variable". I hope this helps.

-- Example from the help:
obj1 = Teapot() --Create a teapot
obj2 = instance obj1 --Create an instance
obj2.pos = [-100,0,0] --Place the instance 100 units along -X
obj3 = Box pos:[100,0,0] --Create a box 100 units long X
ctrl = float_script()--Create a Float Script Controller
obj3.height.controller = ctrl --Assign Controller to Height of Box
ctrl.addTarget "myTeapot" obj1[4] --Add Target Var. with Teapot Obj.
ctrl.setExpression "myTeapot.Radius" --Set Height to Teapot Radius
ctrl.getTarget "myTeapot" --Get the Target Track as SubAnim value
ctrl.getTarget "myTeapot" asObject:true --Get as Object
ctrl.PrintDetails()--Print the controller details

Matyrix · 2010-09-13

Really thanks! I don't know how could i not found this. But... What the hell is the [4] in the "ctrl.addTarget "myTeapot" obj1[4]" line? :)

Anubis · 2010-09-13

Check for "SubAnims" (Indexed Access to Animatable Properties) :)

obj1 = Teapot()
obj1[1] --SubAnim:Visibility
obj1[2] --SubAnim:Space_Warps
obj1[3] --SubAnim:Transform
obj1[4] --SubAnim:Object__Teapot
obj1[5] --SubAnim:Material
obj1[6] --SubAnim:Image_Motion_Blur_Multiplier
obj1[7] --SubAnim:Object_Motion_Blur_On_Off
getSubAnimNames obj1 -- #(#visibility, #Space_Warps, #transform, #Object__Teapot, #material, #Image_Motion_Blur_Multiplier, #Object_Motion_Blur_On_Off)
obj1[4].object -- Teapot
obj1[4].numSubs -- 7
getSubAnimNames obj1[4] -- #(#radius, #Segments, #smooth, #body, #handle, #spout, #lid)

Matyrix · 2010-09-14

Thanks again! This helped me a lot. But... I couldn't use it to solve my problem.
I recorded my problem and uploaded here as a video:
http://vimeo.com/14942897

What is the easiest way to solve this?

Anubis · 2010-09-14

Strangely, wiring fail, but float script works here (Max 2009), just as Veneta said, need to move slider to update the controller. Here is my test (screenshot) - I wrote "$Box02.pos[3]" in the expression (without adding target).

Attachments

Matyrix · 2010-09-14

It's really interesting. So the main problem was the target usage.. hm.
But thanks your help again! It's work from now, and i forgot the wire parameters for a long time. :)

veneta · 2010-09-12

I not see any problem. In the described example shpere01 follow sphere02 position even if sphere02 is linked to sphere03 and sphere03 is moved, just need to move the slider to update ;)

Matyrix · 2010-09-12

Hmm, what is the version of your max? I moved the slider but nothing changed... I use 2009.

By the way i hope somebody knows how could be used the AddTarget option :)

Anubis · 2010-09-12

You can instance Sphere01 and Sphere02 position controllers.
The float script will not necessary in this case.

Matyrix · 2010-09-12

Yes you are right, but this was just a very short cut of my problem. My problem is that i can't use the AddTarget option in a character's rig, and hoped that if you could show me how can use it in the case of sphere's (in a very simple case) i could use everywhere.

So the matter is the right usage of AddTarget.