[Closed] Select bones from skin
I need to select a mesh and all the bones from it’s skin modifier in viewport via MaxScript, how can this be achieved?
Thanks
Here you go.
fn selectSkinBonesFn obj =
(
max modify mode
select obj
if obj.modifiers[#Skin] != undefined do
(
skinBones = #()
skinMods = getclassinstances Skin target:obj
for s = 1 to skinMods.count where skinMods.count > 0 do
(
skel = skinOps.getnumberbones skinMods[s]
for x = 1 to skel do
(
myBone = (skinOps.getBoneName skinMods[s] x 0)
append skinBones (getNodeByName myBone)
)
)
clearSelection()
select skinBones
format "--
Selected the following bones:
"
for bn in skinBones do format (bn.name+"
")
)
)
selectSkinBonesFn $
sorry but i can’t leave this code without comments. too many strange solutions…
#1
if obj.modifiers[#Skin] != undefined do
you check here that the object has modifier with name “Skin” after that you are looking for all modifiers by class. There is no logic here. You should do either one thing or the other. Searching by class is deeper and more subject than by name.
#2
for s = 1 to skinMods.count where skinMods.count > 0 do
if number of skin modifiers == 0 the loop will not work. there is no any reason to doublecheck it
#3
myBone = (skinOps.getBoneName skinMods[s] x 0)
append skinBones (getNodeByName myBone)
skinops returns a name. after that you are searching a node by name. it cannot guaranty that you will find the right node if there are more then one node with the same name in the scene
#4
if you are looking for bones in more than one skin modifier you have to set every modifier as current modpanel object to make skinops works right.
#5
clearSelection()
select skinBones
select methods replaces selection. it doesn’t need clearing before.
#6
it makes sense to make a function that returns a list of skin bones. after that you can do whatever you need with this list – select, hide/unhide, freeze/unfreeze, delete, etc.
Thanks for you replies.
So, denis, how would such function work? I really only need to:
select an object
get list of bones which have influence on it
add them to selection
export fbx
deselect
select another object, do the same
I covered everything but selecting bones from the skin modifier.
fn collectSkinBones node =
(
fn findNodesByName list name =
(
for node in list where stricmp node.name name == 0 collect node
)
max modify mode
local bones = #()
for sk in node.modifiers where iskindof sk Skin do
(
modpanel.setcurrentobject sk
nodes = for n in (refs.dependson sk) where isvalidnode n collect n
for k=1 to skinops.getnumberbones sk do
(
name = skinops.getbonename sk k 0
join bones (findNodesByName nodes name)
)
)
bones
)
/*
(
bones = collectSkinBones <node>
if bones.count > 0 then select bones else clearselection()
)
*/
something like this
but it’s very unlikely that some node can have more than one Skin modifier. Max doesn’t really support it.
#1 yeah that was a cheap and lazy way for me to put some sort of error checking.
#2 true
#3 I don’t usually have duped names in my scenes but good point.
#4 true
#5 bad habit of mine for sure.
#6 completely forgot to return the list of bones at the end there.
Once again thx for the comments Dennis.