[Closed] Skin: remove bones array from skin
can anybody explain me what is wrong in this script?
I want to remove the array of bones from skin list
this is my function
BnArray – an array of Bones ID that should to remove
SkinMod – is a Skin Modifier of object
fn RemBnLstFromSkin BnArray SkinMod =
(
RemovingBones = for i = 1 to BnArray.count collect SkinOps.GetBoneName SkinMod BnArray[i] 0 – collect removing bones names in array
bi = 1
for i = 1 to BnArray.count do – go by bones ID
(
do – loop while bone ID (bi) less than number of bones in skin
(
if (SkinOps.GetBoneName SkinMod bi 0) == RemovingBones[i] – test bones name that should be removed with bone in current loop iteration
then
(
SkinOps.removeBone SkinMod bi
–exit –with messagebox “exit”
)
else bi +=1
)while (bi > (skinOps.getNumberBones SkinMod))
)
)
P.S. I hope I explained myself clear enough
Don’t worry, english is my only language and I still can’t speak it
Onto the problem…there are a number of problems with the code…
RemovingBones = for i = 1 to BnArray.count collect SkinOps.GetBoneName SkinMod BnArray[i] 0 -- collect
This won’t work. GetBoneName expects a “bone index” not a bone name, so
SkinOps.GetBoneName SkinMod i 0
would be more correct but would still not yeild what you want.
Also, most of the skin ops require that the skin modifier be selected…this is easy to achieve
max modify mode
modPanel.setCurrentObject SkinMod ui:true
Your basic idea is almost right, but is somewhat a little skewed/off.
Here is my first idea
fn RemBnLstFromSkin BnArray SkinMod = (
-- Get the names of the bones...
local lstBoneNames = for i = 1 to BnArray.count collect BnArray[i].name
-- Open the modify panel and select the skin modifier
max modify mode
modPanel.setCurrentObject SkinMod ui:true
-- Starting bone index
local iSkinBone = 1
-- Loop through until we reach the end
-- The bone list is dynamic so we need to do
-- a check on every loop
while iSkinBone < (SkinOps.getNumberBones skinMod) do (
-- Get the name of the bone at the appropriate index
local sBoneName = SkinOps.GetBoneName SkinMod iSkinBone 0
-- Check to see if the name is in our name array
local iIndex = findItem lstBoneNames sBoneName
-- Checck...
if iIndex > 0 then (
-- Kill it...
SkinOps.removeBone SkinMod iSkinBone
-- This is the funny part. If we delete a bone, all the items in the
-- skinops bone array move up by one, so we don't need to
-- change the iSkineBone index!!
) else iSkinBone += 1
)
)
RemBnLstFromSkin #($bone01) $box01.modifiers[#skin]
I then thought, it would be really cool if I could just pass a single bone OR multiple bones depending on what I needed to do…so
mapped fn RemBnLstFromSkin boneToDelete SkinMod = (
local sBoneToDeleteName = boneToDelete.name
-- Open the modify panel and select the skin modifier
max modify mode
modPanel.setCurrentObject SkinMod ui:true
-- Starting bone index
local iSkinBone = 1
-- Loop through until we reach the end
-- The bone list is dynamic so we need to do
-- a check on every loop
while iSkinBone < (SkinOps.getNumberBones skinMod) do (
-- Get the name of the bone at the appropriate index
local sBoneName = SkinOps.GetBoneName SkinMod iSkinBone 0
if sBoneName == sBoneToDeleteName then (
-- Kill it...
SkinOps.removeBone SkinMod iSkinBone
-- This is the funny part. If we delete a bone, all the items in the
-- skinops bone array move up by one, so we don't need to
-- change the iSkineBone index!!
) else iSkinBone += 1
)
)
RemBnLstFromSkin $bone02 $box01.modifiers[#skin]
RemBnLstFromSkin #($bone03, $bone04) $box01.modifiers[#skin]
Is my second attempt. It allows you to pass either a single node or an array of nodes depending on what you need…
I think I might have gone slightly over board…
Shane
wow, it’s exactly that what I want.
thanx
p.s. in my example BnArray was an array of indexes of bones which I tried to remove
...
RemovingBones = for i = 1 to BnArray.count collect SkinOps.GetBoneName SkinMod BnArray[i] 0
....
RemBnLstFromSkin #(1,3,5) $.modifiers[#skin]