On 17/03/2013 at 03:46, xxxxxxxx wrote:
Hi,
i am new to phyton and have a problem regarding the gradient of a material.
I would like to control the knots as shown below but it does not work.
I found a post similar to my problem and tried the adviceses from there but it does not work.
This is my code:
import c4d
def main() :
#this routine shall adjust every other knots position depending on the position of the
#knot before and a customer value so that the distance of Knot 0 to 1, 2 to 3 etc. ist always the same
#a gradient with knots does already exist
mat = doc.GetFirstMaterial() #Gets the first material in the materials manager
shdr = mat[c4d.MATERIAL_COLOR_SHADER] #The shader inside the "texture" option
grad = shdr[c4d.SLA_GRADIENT_GRADIENT] #Get the gradient GUI and assign it to a variable
step = 0.2
knots_count = grad.GetKnotCount() #How many knots are there?
if knots_count > 1: #if more then 1 knot...
for i in range(0, knots_count,2) : #for every other knot (begin with 0)
knots_pos = grad.GetKnot(i) #get the "dict" values like index, pos, bias etc.
position = knots_pos["pos"] #get only the position value
grad.SetKnot(index=i+1, pos=position+step) #set the new position for every second knot does not work
shdr[c4d.SLA_GRADIENT_GRADIENT] = grad #write the value back to the system
shdr[c4d.SLA_GRADIENT_GRADIENT] = grad #Update the gradient data
mat.Message(c4d.MSG_UPDATE ) #Update the material changes
mat.Update( True, True ) #Update the material's icon image
c4d.EventAdd() #Update C4D so things update quickly
if __name__=='__main__':
main()
I cannot set the new position, the knot always jumps to the 0 position. Moreover it seams that i cannot change the first knot witch has the index 0 as far as i know.
Any ideas?
Thanks, CoffeeCup