Getting a subanim from a value

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  05 May 2008
Getting a subanim from a value

I've got a script that's returning something like this:
What I want is to convert it and any other returning value expressions to their respective subanim forms. ie. $teapot01.baseobject[#radius]
How can I do that?
  05 May 2008
No takers? OK...

Well, what I'm doing specifically is trying to extract the details of a script controller; trying to create the code that will create a target, object, constant or node variable in a script controller by extracting the information contained within it. The problem is however, that maxscript's commands for getting that info have a few holes in them.

For example, if I try to extract the info of a variable assigned to a controller on an object using .getobject, I get something like Controller:bezier_float. No detail on the object's name or where in the controller hierachy it is. So, I use the command .printDetails() which gives me a good array of stuff that I can sift through with string stream commands to get what I need.


If that variable's target is the weight of a list controller, the result printed isn't correct.
For example, this is what's returned from .printDetails():
$Teapot01.pos.controller.X_Position.controller.wei  ght.controller
When what it should be is:
$Teapot01.pos.controller.X_Position.controller.wei  ght.weight__bezier_float.controller

How can I extract the specific controller that it is? Especially as in this example, both weights are called weight__bezier_float, how do you extract the index of the weights from the small amount of information given?
  05 May 2008
Can you use some combination of


Portfolio | Keyframes and Code
  05 May 2008
Hmm, looks like a real head ache. Can you elaborate on what it is you are doing and why? Maybe there are other ways to go about it.
Paul Neale
  05 May 2008
Dave: I just discovered exprForMAXObject for the .getObject stuff and that saves me a lot of stringstream searching through the .printDetails() result.

However, the same problem remains, how do I get the right weight controller/subanim?

Paul: What I'm doing is turning a rig into code. Rigging something by hand, then running the script to create a new script that when run, will rebuild the rig. I've got it to build objects, name them, link them, assign CAs, assign controllers and wire them. I can put script controllers on them but it fails when assigning variable targets and/or objects when they are list weights.

For example:
for i = 5 to obj.controller.numvariables() do
      scriptVar = obj.controller.getName i
      scriptTarget = exprForMAXObject (obj.controller.getTarget i)
      format (objname + "_script.addTarget \"" + scriptVar + "\" " + scriptTarget + "\n") to:ScriptFile

When it comes to list weights, the scriptTarget variable is returning:
when it should return:
or better still:

I could easily do some string replacing to turn "weight" into "weights[1]" but I can't find the index number of the weight I should be using. It won't always be 1.

Does that make sense?
  05 May 2008
What I would try is this:

  1. Get your target controller as an object
  2. Create a recursive function that recurses through any object's subanims
  3. Recurse through the object (as you have its name) building up the string as you go with name and index values, eg "$object.position.controller[2].controller"
  4. When your target == your iterator, you have your string!
Would that work? Probably not perfectly on instanced controllers, but you may be able to write checks for this.

Any good to ya?

Portfolio | Keyframes and Code
  05 May 2008
Hi Chinwagon,

a way that' i found to get the real string and avoid that bug is to use the string from the exprForMAXObject function, then loop in each of its controllers, and compare it to the controller gotten from the "getObject" function.

Here i made a try:

targetController=(scriptController.getobject "variable")
stringVal=exprForMAXObject targetController explicitNames:true
auxCtrl=execute stringVal
if auxCtrl==undefined then
	--Here i copy the string without the ".controller" part
	for i=1 to (stringval.count-11) do
		append stringval2	stringval[i]

	--get the number of weights and loop throught them
	n=execute (stringval2+".count")
	for i=1 to n do
		--compare to the controller to find the right string
		aux=(stringval2+"["+(i as string)+"].controller")
		if (execute aux)==targetController then stringVal=aux
  05 May 2008
Didn't notice that davestewart posted a similar answer XD
  05 May 2008
Originally Posted by phoelix: Didn't notice that davestewart posted a similar answer XD

Ha ha, well at least you save me the trouble of finding out
Portfolio | Keyframes and Code
  05 May 2008
YIKES!, looked into that at one point and just ran away screaming. good on ya. That would be very handy to have.
Paul Neale
  05 May 2008
OK, Here's my take:

struct scriptExpr
 	expr = "",
 	function getSubAnims src trg path =
 		local sas = getSubAnimNames src
 		if sas != undefined do
 			for sa in sas do
 				local ctrl = src[sa].controller
 				local temp = path + "[#" + sa + "]"
 				if ctrl != undefined AND ctrl == trg then
 					-- success!
 					expr = temp + ".controller"
 					-- failure
 					getSubAnims src[sa] trg temp
 	function get trg =
 		-- get the source object if unsupplied
 			local obj = exprformaxobject trg explicitNames:true
 			local src = execute (filterstring obj ".")[1]
 		-- recurse through src and attempt to find target controller
 			getSubAnims src trg ("$" +
 		-- return the final script path
 -- objects
	trg		= $.pos.controller[2].controller -- second controller in a position list
	se		= scriptExpr()
-- get the expression
	expr	= se.get trg
	trg == (execute expr)

-- results
	-- "$Teapot01[#transform][#position][#Pos_2].controller"
	-- true

I was trying to make a standalone struct, but I was having a bit of trouble figuring out how to pass the final expression back up the recursion chain.

Still, this is an OK starting point. You may need to add checks to check for unique names, or use indices instead, but this proves the theory at least.

Hope that helps.

Portfolio | Keyframes and Code

Last edited by davestewart : 05 May 2008 at 10:11 PM.
  05 May 2008
Thanks for the help guys.
In the end, I went with phoelix's method (as I'm not too familiar with structs) and it worked a treat.
  05 May 2008
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:09 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.