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
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.
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.