Last active
March 30, 2023 08:01
-
-
Save BigRoy/2b220611a86ca1c5e666df4937c619f4 to your computer and use it in GitHub Desktop.
Maya: Export ramp attribute samples to JSON. Sample multiple times along the ramp curve for its value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as cmds | |
import maya.api.OpenMaya as om | |
import json | |
def get_ramp_attribute(attr): | |
"""Return MRampAttribute for attribute name.""" | |
sel = om.MSelectionList() | |
sel.add(parm) | |
plug = sel.getPlug(0) | |
return om.MRampAttribute(plug) | |
node = cmds.ls(selection=True)[0] # first selected node | |
attr = node + '.value' | |
ramp = get_ramp_attribute(attr) | |
samples = 100 # amount of samples | |
step = 1.0 / (samples - 1.0) | |
values = {} | |
for sample in range(samples): | |
position = sample * step | |
value = ramp.getValueAtPosition(position) | |
values[position] = value | |
# Write out to json | |
with open("S:/maya_ramp_attribute_samples.json", "w") as f: | |
json.dump(values, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment