Reputation: 519
I am using a python script and the getAttr and setAttr Maya commands on 2d ramp textures in Maya 2022. The ramp attrs are saved out to a text file and read back in and applied to other ramps so the values can be shared. Sometimes, it works perfectly, but other times I am getting extra red points added to the ramp and it seems to go haywire. The expected ramp result after reading the file containing the attribution data would look like the image below, but without the red points. I can not find a pattern as to when it will work or break. However, once the ramp node has the issue, it seems to keep having the issue, but other ramp nodes work fine. Has anyone else experienced this problem and what causes the ramp to trigger extra red colored points when being called by a getAttr command?
for attr in attributes:
attr_value = cmds.getAttr(ramp + '.' + attr)
ramp_preset_text = attr + ':' + str(attr_value) + '\n'
ramp_preset_file.write(ramp_preset_text)
n = 0
if cmds.attributeQuery('colorEntryList',node = ramp, ex = True ):
number_of_entries = cmds.getAttr(ramp + '.colorEntryList', size = True)
number_of_entries_text = 'entry number:' + '*' + str(number_of_entries) + '*' + '\n'
ramp_preset_file.write(number_of_entries_text)
print('number_of_entries_text', number_of_entries_text)
print('n', n)
while n < number_of_entries:
print('while n', n)
entry_position = cmds.getAttr(ramp + '.colorEntryList[' + str(n) + '].position')
entry_color = cmds.getAttr(ramp + '.colorEntryList[' + str(n) + '].color')
entry_preset_text = ('entry_' + str(n) + ' ' + ' position:' + str(entry_position) + ' color:' + str(entry_color) + '\n')
ramp_preset_file.write(entry_preset_text)
n = n + 1
ramp_preset_file.close()
Upvotes: 1
Views: 58
Reputation: 519
I believe I know what was causing the error. I was assuming the point index's would always start at 0 and not skip increments. So, if there were a total of 3 points, I was assuming the index's would be 0,1,2. This is not the case. They can be 3,7, and 9, etc. My code was creating a red point at any index where there was no data. I have to adjust the code and solve for the index's not starting at 0 or being sequential.
Upvotes: 0
Reputation: 12218
I'm not able to repro this, but your screenshot shows two control points both at zero. Is it possible that your interpolated color has gone to a NAN value -- like, something in Maya is trying to divide by zero because of the interpolation through those two colocated points?
The first thing I'd try would be to loop through the color entry list and print out the values:
ramp = "ramp1"
for n in range(cmds.getAttr(f"{ramp}.colorEntryList", size=True)):
pos = cmds.getAttr(f"{ramp}.colorEntryList[{n}].position")
col = cmds.getAttr(f"{ramp}.colorEntryList[{n}].color")
print (f"{n}:\t{col} @ {pos}")
if you're seeing red in the color printout the issue is with bad data in the node proper, if not it's probably an issue with GL drivers not handling the two-samples-extremely-close issue properly.
I'd also check the results in renders to see if hardware and software renderers handle it differently.
Upvotes: 0