Search code examples
pythonmayafbxmel

Python FBX SDK – How to scale models that have keyframes?


I am trying to script with Python FBX SDK to scale models. And I am using LclScaling.Set() to set scale value. But I found if this model has keyframes, then the scaling is not applied.

So my question is how to properly scale models that have keyframes. Here is my code:

scale = node.LclScaling.Get()
value = 0.5
node.LclScaling.Set(fbx.FbxDouble3(scale[0] * value, scale[1] * value, scale[2] * value))

Solution

  • In case you can't scale your model that already has animation keyframes, it seems that it has keyframes on a Scale parameter, even if scale is not changing during playback session. That could be possible in situation when user animates just a position of a model pressing S shortcut. This shortcut generates 10 keyframes at a time, but only translation/rotation keyframes are important for you here.

    enter image description here

    Solution:

    Delete redundant keyframes in Graph Editor manually or programmatically.

    import maya.cmds as cmds
    
    cmds.cutKey('pSphere1', time=(1,100), attribute='scaleX', option="keys")
    cmds.cutKey('pSphere1', time=(1,100), attribute='scaleY', option="keys")
    cmds.cutKey('pSphere1', time=(1,100), attribute='scaleZ', option="keys")
    

    After this you can easily scale your model.

    P.S.

    The other appropriate way is to update old scale keyframes for FBX model (first in the beginning and second in the end of animation).