ScriptSpot is a diverse online community of artists and developers who come together to find and share scripts that empower their creativity with 3ds Max. Our users come from all parts of the world and work in everything from visual effects to gaming, architecture, students or hobbyists.
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 == truedo(
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
((
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 ;)
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 )
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...
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())
(for bip in selectiondo--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)
Comments
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.
You're welcome
Here is an optimized version of your script
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 ;)
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 )
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:
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...
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
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:
Cool !
Cool !
Hi,
You can use this: