Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Python Set Anim Layer RotationAccumulation by layer

Python Set Anim Layer RotationAccumulation by layer

elfenliedtopfan5
Participant Participant
545 Views
4 Replies
Message 1 of 5

Python Set Anim Layer RotationAccumulation by layer

elfenliedtopfan5
Participant
Participant

Good morning all, 

 

i have been trying for a couple of days now to set the rotationaccumulation by layer in python but cant seem to get it to work 

 

what i have tyried so far 

def create_anim_layer():
    # Create an animation layer
    anim_layer = cmds.animLayer("Idle_AnimLayer", override=True)

    # Set the rotation accumulation to "by layer" using MEL
    mel_command = 'editAnimLayer -e -rotationAccumulation "byLayer" "{}";'.format(anim_layer)
    mel.eval(mel_command)

    # Adjust the number of frames to the maximum frame count
    max_time = cmds.playbackOptions(q=True, max=True)
    cmds.animLayer(anim_layer, edit=True, override=True, at=max_time)


def create_anim_layer():
    # Create an animation layer
    anim_layer = cmds.animLayer("Idle_AnimLayer", override=True)

    # Set the rotation accumulation to "by layer" using cmds.setAttr
    cmds.setAttr('{}.rotationAccumulation'.format(anim_layer), 'byLayer')

    # Adjust the number of frames to the maximum frame count
    max_time = cmds.playbackOptions(q=True, max=True)
    cmds.animLayer(anim_layer, edit=True, override=True, at=max_time)


def create_anim_layer():
    # Create an animation layer
    anim_layer = cmds.animLayer("Idle_AnimLayer", override=True)

    # Set the rotation accumulation to "by layer" using the SEToolsPlugin module
    mel_command = 'animLayer -edit -rotationAccumulation "byLayer" "{}";'.format(anim_layer)
    mel.eval(mel_command)

    # Adjust the number of frames to the maximum frame count
    max_time = cmds.playbackOptions(q=True, max=True)
    cmds.animLayer(anim_layer, edit=True, override=True, at=max_time)

 

however i cant seem to get the correct name it keeps coming up with errors like 
# Error: AttributeError: file <maya console> line 44: module 'maya.cmds' has no attribute 'editAnimLayer'

this is the current one i was working on but still no luck 

def create_anim_layer():
    # Create an animation layer
    anim_layer = cmds.animLayer("Idle_AnimLayer", override=True)

    # Set the rotation accumulation to "by layer" using MEL
    mel_command = 'editAnimLayer -e -rotationAccumulation "byLayer" "{}";'.format(anim_layer)
    mel.eval(mel_command)

    # Adjust the number of frames to the maximum frame count
    max_time = cmds.playbackOptions(q=True, max=True)
    cmds.animLayer(anim_layer, edit=True, override=True, at=max_time)

 

all i really need to do is change the anim layer to by layer does anyone here know how that could be acchived in python ? 
Screenshot 2023-12-21 085519.png

thank you in advance 

elfenliedtopfan5

0 Likes
Accepted solutions (1)
546 Views
4 Replies
Replies (4)
Message 2 of 5

FirespriteNate
Advocate
Advocate

I don't have 2023 installed here, only 2022, but when I execute

whatIs editAnimLayer;

in MEL, it returns "Unknown", which means editAnimLayer is NOT a regular cmds command, so will not work in python using cmds. There are only three other alternatives I can think of, it's a plug-in command, so will become available to cmds if the plug-in is enabled, it's a runtime command (unlikely as it doesn't start with an uppercase letter), or, most likely it's a MEL script that hasn't been sourced yet.

If the MEL code above DOES return a valid mel file source path when you run it, then you simply have to ensure the mel script it specifies is sourced before you run your code.

 

However, I just did a search on the entire Maya2022 install folder and "editAnimLayer" produced zero hits.. are you sure it's actually a valid command/function/script?

Message 3 of 5

elfenliedtopfan5
Participant
Participant
import maya.cmds as cmds
import maya.mel as mel
import maya.OpenMaya as om
import SEToolsPlugin  # Import the SEToolsPlugin module

def import_se_anim_file(file_path):
    # Call the Python function directly from the imported module
    SEToolsPlugin.__load_seanim__(file_path, scene_time=False, blend_anim=False)

    # Select all joints
    cmds.select("Joints", hi=True)

    # Get the time range
    min_time = cmds.playbackOptions(q=True, min=True)
    max_time = cmds.playbackOptions(q=True, max=True)

    # Copy the keyframes with the time range specified
    cmds.cutKey(time=(min_time, max_time), clear=True)
    print("cutkey")
    # Paste the keyframes back to the original joints
    cmds.pasteKey(time=(min_time, max_time), option="replace")
    print("pasteworked", min_time, max_time)

def import_se_anim_file_and_create_anim_layer(*args):
    # Specify the path to your SE Anim file
    se_anim_file_path = r"path removed but path to anim file need to be loaded"
    
    # Call the import_se_anim_file function
    import_se_anim_file(se_anim_file_path)

    # Call the create_anim_layer function
    create_anim_layer()

    # Call the copy_and_paste_to_anim_layer function
    copy_and_paste_to_anim_layer()

def create_anim_layer():
    # Create an animation layer
    anim_layer = cmds.animLayer("Idle_AnimLayer", override=True)

    # Set the rotation accumulation to "by layer" using cmds.editAnimLayer
    cmds.editAnimLayer(anim_layer, edit=True, rotationAccumulation="byLayer")

    # Adjust the number of frames to the maximum frame count
    max_time = cmds.playbackOptions(q=True, max=True)
    cmds.animLayer(anim_layer, edit=True, override=True, at=max_time)

def copy_and_paste_to_anim_layer():
    # Select all joints
    cmds.select("Joints", hi=True)

    # Get the time range
    min_time = cmds.playbackOptions(q=True, min=True)
    max_time = cmds.playbackOptions(q=True, max=True)

    # Copy the keyframes with the time range specified
    cmds.copyKey(time=(min_time, max_time), clear=True)

    # Paste the keyframes into the animation layer
    cmds.pasteKey(time=(min_time, max_time), option="replace", targetClip="Idle_AnimLayer")

# Call the import_se_anim_file_and_create_anim_layer function
import_se_anim_file_and_create_anim_layer()

 

this is the full code its higly possible its not a mel command new to python and have been looking up tutorials and using addinal resorces from other places to get a understanding of this however i manged to get it to make the animlayer i just cant get it to change the rotation accumcation to by layer been trying to do it for couple of days now these ones are the only ones i saved 

Message 4 of 5

FirespriteNate
Advocate
Advocate
Accepted solution

I still have no idea where you are getting editAnimLayer from, but if you just want to set the layer's "Rotation Accumulation" mode to "By Layer", don't you just need to do this:

cmds.setAttr(anim_layer+'.rotationAccumulationMode', 1)

 which is basically what the ScriptEditor spits out (but in MEL) when you do it manually?

0 Likes
Message 5 of 5

elfenliedtopfan5
Participant
Participant

yes it does and yes that does work i been going by lable name so rotationaccumulation - bylayer when it is execting ,1 or 0 messed that up badly thank you for your reply been very helpful marked as answer 

0 Likes