Biped activate Mixer Mode

Hi,
I would like to know how to activate or deactivate Biped Mixer Mode by script.
Thanks ! :-)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
titane357's picture

Thank you very much ! It is

Thank you very much ! It is what I needed
I just "made" a little script as always in frankenstein style.
The marvelous fonction is from ZalitZ
If it can be helpfull to somebody.
Script : Toggle Mixer Mode from the selected skinned mesh.

----by ZalitZ 
 
fn ListSkinBones obj toNode:false = 
( 
    skinMod
    bonesList = #()
    result
    -------------------------------------------------------------------------------
 
    clearSelection()
    max modify mode
 
    hiddenState = obj.ishidden 
    obj.ishidden = false
    select obj
 
    skinMod = obj.modifiers[#skin]
    modPanel.setCurrentObject obj.modifiers[#Skin]
 
    bonesList = for i=1 to (skinOps.GetNumberBones skinMod) collect (skinOps.GetBoneName skinMod i 0)
 
    obj.ishidden = hiddenState 
    result = bonesList 
 
    if toNode == true do 
    (
        result = for i in bonesList collect (getNodebyName(i) ) 
    )
 
    result
)
SELM = $
ALLB = (ListSkinBones $ toNode:true)
 
select ( for a in ALLB where (  matchPattern a.name pattern:("*"+ "Pelvis" + "*")) collect a)
select ( $.parent)
 
biped_ctrl=$.controller 
 
if biped_ctrl.mixerMode == on then biped_ctrl.mixerMode = off else biped_ctrl.mixerMode = on
 
select SELM
max zoomext sel
SimonBourgeois's picture

You're welcome

Here is an optimized version of your script

(
	(
	fn GetPelvisBones obj = 
	(
		local pelvis	
		local skinMod = obj.modifiers[#skin]
		modPanel.setCurrentObject obj.modifiers[#Skin]
		local bonesList = for i=1 to (skinOps.GetNumberBones skinMod) collect (skinOps.GetBoneName skinMod i 0)
		local pelvisbone = for a in bonesList where (matchPattern a pattern:("*"+ "Pelvis" + "*")) collect a
		pelvis = getNodebyName pelvisbone[1]
	)
	with redraw off
	(
		max create mode
		local SELM = selection[1]
		local hiddenState = SELM.ishidden 
		local pelvisB = GetPelvisBones SELM 
		local bip = pelvisB.parent
		local biped_ctrl=bip.controller 
 
		if biped_ctrl.mixerMode == on then biped_ctrl.mixerMode = off else biped_ctrl.mixerMode = on
		if hiddenState == true then (SELM.ishidden = false;max zoomext sel;SELM.ishidden = true)
		else max zoomext sel
		--max modify mode --optional much faster without it but you can uncomment if you need to be on modify panel
	)
	redrawviews()
)

I've removed some "select" stuff that wasn't needed, also removed all the "hidden"check stuff from the function, and add it back in the end to ensure that the zoom on selection at the end works even if the selected object is hidden (it could be selected in the layer manager but hidden in the viewport), i've put the "pelvis search into the function to avoid creating two arrays with all the bones names and nodes, you only needed the pelvis to be returned by the function, adding "max create mode" makes it much faster as in this case you don't need to be in modify mode (sometimes it is required, but not in this case).Declaring every variable as local is not neccessary in this case if all the code is within parentheses, but i like to do so anyway, it is more for clarity and readability. In your code, variables were just declared without being within parentheses, it was creating some global variables that can be problematic in certain case, enclosing your code within parentheses avoid creating global variables as maxscript automatically declare variable as local if within parentheses. I also added a redraw off to even further speed up the process ;)

titane357's picture

Hi ! Thank you very much

Hi ! Thank you very much !
But a ")" is missing at the end ;-)

I think I'll never do a clean script in my all life...

In some cases, I get :
-- MAXScript FileIn Exception:
-- Unknown property: "mixerMode" in Controller:Position_Rotation_Scale
( with RenderPeople rigged )

SimonBourgeois's picture

you're welcome

Don't worry i am kind of messy too, I try to get better at it ... There is always stuff to learn...
In fact it wasn't a missing ")" at the end, but it was an extra "("at the begining, before the beginning of the function GetPelvisBones.;)

I've check the "RenderPeople rigged" setup and the problem comes from the fact that the pelvis object isn't included in the skin modifier so the function return undefined, you can add the pelvis to the skinmodifier, the script will work fine...
but i came up with something that will work even on RenderPeople rigged characters:

(
	fn getParents o Arr=
    (
        try (
				if o.parent != undefined then 
				(
					appendifunique Arr o.parent
					getParents o.parent Arr
				)
				else appendifunique Arr o 
			)catch()
    )
	fn getChildren o Arr=
	(
		try (	
				appendifunique Arr o 
				if o.children != undefined do
				(
					join Arr o.children
					for child in o.children do(for i = 1 to child.children.count do getChildren child.children[i] Arr)
				)
			)catch()
	)
	fn ParentsAndChildren obj =
	(
		local resultArr=#()
		getParents obj resultArr
		getChildren obj resultArr
		makeUniqueArray resultArr
		resultArr
	)
	fn GetBip obj = 
	(
		local skinMod = obj.modifiers[#skin]
		modPanel.setCurrentObject obj.modifiers[#Skin]
		local bone1 = skinOps.GetBoneName skinMod 1 0
		local AllHierarchy = ParentsAndChildren (getNodeByName bone1)
		local bipbone  
		for o in AllHierarchy where o.controller != undefined and hasproperty o.controller #mixerMode do bipbone = o
		bipbone
	)
 
	with redraw off
	(
		max create mode
		local SELM = selection[1]
		local hiddenState = SELM.ishidden 
		local bip = GetBip SELM 
		local biped_ctrl=bip.controller 
		if biped_ctrl.mixerMode == on then biped_ctrl.mixerMode = off else biped_ctrl.mixerMode = on
		if hiddenState == true then (SELM.ishidden = false;max zoomext sel;SELM.ishidden = true)
		else max zoomext sel
		--max modify mode --optional much faster without it but you can uncomment if you need to be on modify panel
	)
	redrawviews()
)

in this version i collect all bones hierarchy even if they aren't in the skin modifier and then i filter only the one that has a "mixerMode" property, this way it will likely work in most cases, i hope...
the way i build the hierachy array could surely be better written, but it works...

titane357's picture

Hi Simon. Thank you very much

Hi Simon.
Thank you very much again !
Now it works like a charm !
I think I can live with the hierarchy array as it is written :-)
Best

SimonBourgeois's picture

You're welcome

Me too :)
if you apply the script to an object that doesn't have any skin modifier it crashes, so here is a modified version, it will return a warning message instead of crashing:

(
	fn getParents o Arr=
    (
        try (
				if o.parent != undefined then 
				(
					appendifunique Arr o.parent
					getParents o.parent Arr
				)
				else appendifunique Arr o 
			)catch()
    )
	fn getChildren o Arr=
	(
		try (	
				appendifunique Arr o 
				if o.children != undefined do
				(
					join Arr o.children
					for child in o.children do(for i = 1 to child.children.count do getChildren child.children[i] Arr)
				)
			)catch()
	)
	fn ParentsAndChildren obj =
	(
		local resultArr=#()
		getParents obj resultArr
		getChildren obj resultArr
		makeUniqueArray resultArr
		resultArr
	)
	fn GetBip obj = 
	(
		local bipbone 
		local skinMod = obj.modifiers[#skin]
		if skinMod != undefined then
		(
			modPanel.setCurrentObject obj.modifiers[#Skin]
			local bone1 = skinOps.GetBoneName skinMod 1 0
			local AllHierarchy = ParentsAndChildren (getNodeByName bone1)
			for o in AllHierarchy where o.controller != undefined and hasproperty o.controller #mixerMode do bipbone = o
		)else (messagebox "Please Select an object with a Skin modifier"beep:off;return undefined)
		bipbone
	)
 
	with redraw off
	(
		max create mode
		local SELM = selection[1]
		local hiddenState = SELM.ishidden 
		local bip = GetBip SELM
		if bip != undefined do
		(
			local biped_ctrl=bip.controller 
			if biped_ctrl.mixerMode == on then biped_ctrl.mixerMode = off else biped_ctrl.mixerMode = on
			if hiddenState == true then (SELM.ishidden = false;max zoomext sel;SELM.ishidden = true)
			else max zoomext sel
			--max modify mode --optional much faster without it but you can uncomment if you need to be on modify panel
		)
	)
	redrawviews()
)
titane357's picture

Cool !

Cool !

SimonBourgeois's picture

Hi,

You can use this:

(
	for bip in selection do --assuming you have the root bip selected
	(	
		biped_ctrl=bip.controller 
		biped_ctrl.mixerMode = on --or off
	)
)
--or
(
	biped_ctrl=$bip01.controller --where bip01 is the  root bip name
	biped_ctrl.mixerMode = on --or off
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.