Hi all,
I encountered a very weird behaviour. I tried to write a script in python which reads all the knot-values of one gradient and set those value to another gradient.
I can read the knots by calling GetKnot().
BUT when I try to extract a certain info from a Knot (for example the position) I get wrong results. So when transfering these infos to another gradient, the gradient is shown wrong.
Thats the Code:
import c4d
from c4d import gui
def main():
mat = doc.GetFirstMaterial() #Gets the first material in the materials manager
shdr1 = mat[c4d.MATERIAL_COLOR_SHADER]
shd = c4d.BaseList2D(1011100) # Gradient
mat[c4d.MATERIAL_DIFFUSION_SHADER] = shd
mat.InsertShader(shd)
mat.Message(c4d.MSG_UPDATE)
mat.Update(True, True)
shdr2 = mat[c4d.MATERIAL_DIFFUSION_SHADER]
grad1 = shdr1[c4d.SLA_GRADIENT_GRADIENT]
grad2 = shdr2[c4d.SLA_GRADIENT_GRADIENT]
grad1_knot1 = grad1.GetKnot(0)
print("Knot1 = " + str(grad1_knot1))
grad1_knot2 = grad1.GetKnot(1)
print("Knot2 = " + str(grad1_knot2))
grad1_knot3 = grad1.GetKnot(2)
print("Knot3 = " + str(grad1_knot3))
index1 = grad1_knot1['index']
print("Index" + " " + str(index1))
index2 = grad1_knot2['index']
print("Index" + " " + str(index2))
index3 = grad1_knot3['index']
print("Index" + " " + str(index3))
pos1 = grad1_knot1['pos']
print("Position" + " " + str(pos1))
pos2 = grad1_knot2['pos']
print("Position" + " " + str(pos2))
pos3 = grad1_knot2['pos']
print("Position" + " " + str(pos3))
col1 = grad1_knot1['col']
print("Color" + " " + str(col1))
col2 = grad1_knot2['col']
print("Color" + " " + str(col2))
col3 = grad1_knot2['col']
print("Color" + " " + str(col3))
bri1 = grad1_knot1['brightness']
print("Brightness" + " " + str(bri1))
bri2 = grad1_knot2['brightness']
print("Brightness" + " " + str(bri2))
bri3 = grad1_knot2['brightness']
print("Brightness" + " " + str(bri3))
grad2.FlushKnots()
grad2.InsertKnot(col=col1, pos=pos1,index=index1)
grad2.InsertKnot(col=col2, pos=pos2,index=index2)
grad2.InsertKnot(col=col3, pos=pos3,index=index3)
shdr2[c4d.SLA_GRADIENT_GRADIENT] = grad2
mat.Message(c4d.MSG_UPDATE)
mat.Update(True, True)
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
And thats the result I get from the console and obviously the second gradient looks like that (wrong), too.
"Knot1 = {'index': 1, 'bias': 0.5, 'pos': 0.3, 'col': Vector(1, 1, 1), 'brightness': 1.0}
Knot2 = {'index': 2, 'bias': 0.5, 'pos': 1.0, 'col': Vector(1, 1, 1), 'brightness': 1.0}
Knot3 = {'index': 3, 'bias': 0.5, 'pos': 0.5, 'col': Vector(1, 0.6, 0.5), 'brightness': 1.0}
Index 1
Index 2
Index 3
Position 0.3
Position 1.0
Position 1.0
Color Vector(1, 1, 1)
Color Vector(1, 1, 1)
Color Vector(1, 1, 1)
Brightness 1.0
Brightness 1.0
Brightness 1.0
"
As you can see: When calling GetKnot() the infos of the Knots are right. But when extracting for example col of those Knots, The results are wrong. They all show Vector(1, 1, 1).
What is happening here?
Cheers,
PdZ