Storing objects / arrays of objects in custom attributes

Become a member of the CGSociety

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

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2013
Storing objects / arrays of objects in custom attributes

i am setting up an ik/fk switcher using max script

I want to show/hide groups of ctrls depending on the mode.

I can do this with arrays easily.

inside my custom attribute definition rollout block,
I have code like:


--define an array of max objects
fk_ctrls=#($fk_upper_arm,$fk_lowerArm,$fk_hand)

...
--hide the array
fn hide_fk =(
	fk_ctrls.hidden=true
)


but this is very object specific.
I want to build a generic fk/ik setup tool
that uses variables (attributes i guess) to hold these objects
so i can simply pick the objects involved and run the script to set the system up.

like :


--assign max objects to a set of vars
fk_upper_arm= $ctrl_fk_r_arm_a
fk_lower_arm= $ctrl_fk_r_arm_b
fk_hand= $ctrl_fk_r_arm_c
...
--and in the  rollout block
...
--define the array using vars instead of objects
fk_ctrls=#(fk_upper_arm,fk_lowerArm,fk_hand)

...
--hide the array
fn hide_fk =(
fk_ctrls.hidden=true
)


What is the best way to store the variable assignments with the custom attribute?
 
  01 January 2013
Create a param block that is type:#maxObjectTab and use a nodeTransformMonitor to store references to the nodes and place them in the maxObjectTab. This will make sure that circular references are not created. You can also use #nodeTab and just propulate it with nodes how ever you could run into issues with circular references.
__________________
Paul Neale
http://paulneale.com
 
  02 February 2013
I take it this is the method outlined in your tutorial
thanks, I suspected as much.
I'll have to put my brain on it.
 
  02 February 2013
OK I've gone through the tutorial example at your site and have begun adapting to my needs.
I was hoping I could store these as some kind of dictionary of key:value pairs.

but it looks like I will just have to store an array of all the objects, and assign by index to local vars inside the rollout block...


ikfk_ca = attributes ikfk_attribs
(
	parameters ikfk_params rollout: ikfk_roll
	(
		--nodeStore for the ikfk objects
		'ikfkNodes' type:#maxObjectTab tabSize:0 tabSizeVariable:true
	)
	
	rollout ikfk_roll "IK-FK"
	(
		--define ikfk objects from ikfkNodes param
		local def_1 = fkikNodes[1]
		local def_2 = fkikNodes[2]
		local def_3 = fkikNodes[3] 
		...
	)
)
--assign ca to ikCtrlObject

custAttributes.add ikCtrlObject.modifiers[1] ikfk_ca

--after assigning the ca, define the actual object array

ikfkArray=#()
ikfkArray[1]=def_1=$FBX_r_arm_a
ikfkArray[2]=def_2=$FBX_r_arm_b
ikfkArray[3]=def_3=$FBX_r_wrist
...
--and assign that array to ikCtrlObject.modifiers[1].ikfkNodes

for each in ikfkArray do
(
	obj=nodeTransformMonitor node:each forwardTransformChangeMsgs:false
	append  ikCtrlObject.modifiers[1].ikfkNodes obj
)


testing this now...

Last edited by Mambo4 : 02 February 2013 at 06:11 PM.
 
  02 February 2013
Plug-in not active, unable to access plug-in local or parameter: ikfkNodes


it appears I cannot assign elements in the ikfkNodes param to local variables.
 
  02 February 2013
Why do you want to do it this way anyway? It's not even a fixed-size array so it doesn't make much sense to do something like local def_n = fkikNodes[n]. If the size of the array was fixed, you could declare your variables in the rollout scope like you do now (without assigning the values) and intialize them in rollout open handler.
__________________
Scripts :: linkedin
 
  02 February 2013
I'm just trying to save an array of the objects I wish to manipulate when switching form fk to ik.
so that the system is not tied to hard coded object names.
 
  02 February 2013
All I'm saying is that if you want to initialize a fixed amount of locals, you should also use fixed-size array they are associated with to prevent shooting yourself in the foot later on. And then there's no problem with initializing all of them in the open rollout handler, something like:

(
  	parameters ikfk_params rollout:ikfk_roll
  	(
  		ikfkNodes type:#maxObjectTab tabSize:5
  
  		on ikfkNodes set val index do this.ikfk_roll.updateLocals()
  	)
  	
  	rollout ikfk_roll "IK-FK"
  	(
  		local def_1, def_2, def_3, def_4, def_5
  
  		fn updateLocals =
  			for item = 1 to 5 do
  				setProperty this.ikfk_roll ("def_" + item as string) ikfkNodes[item]
  		
  		on ikfk_roll open do updateLocals()
  	)
  )
__________________
Scripts :: linkedin
 
  02 February 2013
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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 07:57 PM.


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