Home Coding, Scripting, Shaders

Maya/Python - How to Save Object Inputs/History

Hey magicians. I have something here which is causing me a fair but of trouble.

I'm still relatively new to Maya scripting, so I would like to know if this is feasible.

- Take one or more objects in the scene - Done
- Get their input/history attributes - Done
- Save those to a variable. This is used so for example only the top 3 will be saved. - Done
- Go over each object and it's Inputs/History and delete the top 3. - Done
- "Delete History" Command (so it applies it) - Done
- Reapply/Copy the saved inputs to each object. - Partially Done

I create a dictionary that for each object contains another dict with the input name and its attributes.

Iterating through each object I could gain this info via the following commands:

for node in cmds.listHistory(selection, pdo=2):
    nodes.append(node)


for input_name in object_library[maya_object]:
    attr_list = cmds.listAttr(input_name)
    per_input_data = {} # DICTIONARY PER INPUT DATA


for attribute in attr_list:
    a = str(input_name + "." + attribute)
    try:
        a_attr = cmds.getAttr(a)

The final workable (I believe) data dictionary looks something like so for one object:

{'pCube4': {'polyBevel7': {'offsetAsFraction': True, 'forceParallel': False, 'offset': 0.2, 'fraction': 0.10999999999999995, 'segments': 1, 'depth': 1.0, 'mitering': 0, 'miterAlong': 0, 'chamfer': True, 'angleTolerance': 180.0, 'subdivideNgons': True, 'mergeVertices': True, 'mergeVertexTolerance': 0.0001, 'smoothingAngle': 30.0}, 'polyCube4': {'width': 1.0, 'height': 1.0, 'depth': 1.0, 'subdivisionsWidth': 1, 'subdivisionsHeight': 1, 'subdivisionsDepth': 1}}}


Now, I can then iterate again and apply the operations, with some relative hacking, the issue lies in that I cannot seem to figure out a way to access what edges/faces were affected for those operations.
So for example, I would like to know that for operation "polyBevel7" edges [34, 56, 57, 98] were selected and were affected by the bevel, instead of the entire mesh.

Some attributes return an error stating "# Error: The data is not a numeric or string value, and cannot be displayed. # ". Unsure if these will be relevant.
I've tried several options to retrieve them with the .output or cmds.polyOutput() methods but no dice so far.


I'd really appreciate some input on this! Thanks for taking the time to read through! Much appreciated.

Edit: corrected output dictionary

Replies

  • tsungyuw
    Options
    Offline / Send Message
    tsungyuw polycounter lvl 8
    It's very tricky to do those kinds of things in Maya, you probably need to store that information when you apply bevel.
    Just wonder what would you do to those edges? be carefully after you apply bevel edge ID may change as well.
  • r0fld4nc3
    Options
    Offline / Send Message
    tsungyuw said:
    It's very tricky to do those kinds of things in Maya, you probably need to store that information when you apply bevel.
    Just wonder what would you do to those edges? be carefully after you apply bevel edge ID may change as well.

    Thanks for your reply! I really appreciate it.
    Yes I'm aware that the vert order may change. I've prepared for that :) Just needed to know if there's a way to basically point to a node and store it to a variable such that later on I could place it again on the object.

    I'm sure Maya isn't built for this but there could be a way.

    Right now I need to check for each stored input what type of node it is and recreate it's command structure in MEL based on what the inputs are. It works fairly well, to some degree, it's just going to take too much time and work to go over each possible node entry.
  • Klaudio2U
    Options
    Offline / Send Message
    Klaudio2U polycounter lvl 8
    r0fld4nc3 said:

    Right now I need to check for each stored input what type of node it is and recreate it's command structure in MEL based on what the inputs are. It works fairly well, to some degree, it's just going to take too much time and work to go over each possible node entry.

    You could maybe simply use "nodePreset" command in Maya. If i am not wrong it is one of those functions in Attribute Editor where you can store attribute values as presets.
    In your case you can temporary save preset of certain node values. For example, if you do extrude:
    1. adjust it as you want then run the command to save values as preset and call it something like "_TEMP_extrude". 
    2. When you run extrude again make sure to include command to now load the saved values from "_TEMP_extrude"
    3. At the end you can build cleanup action where it just deletes all temporary saved presets if you don't need them.

    Or something like that. Needs a bit of a thinking about the UI/UX on how to execute it for what you need. At least you don't need to deal with individual attirbutes and writing some hacks with dictionary or something. 
Sign In or Register to comment.