Hello,
I'm searching a method to get gradient Knot by position not by index, the problem with gradient->GetKnot(i) is that when user change the knots position and knots order, the knot index stay the same for each knot.
I had create the following python function to get knot by position and I sorted them from lower to higher knot position.
def GetKnotByPos(gradient, index):
KnotDict = {}
knotCount = gradient.GetKnotCount()
for i in range(knotCount) :
KnotDict[gradient.GetKnot(i)['pos']] = gradient.GetKnot(i)
# dictionary’s keys select.
Ks = list(KnotDict.keys())
Ks.sort()
return KnotDict[Ks[index]]['col']
# Use
gradient = op[c4d.MYOBJECT_GRADIENT]
for index in range(gradient.GetKnotCount()):
color = GetKnotByPos(gradient, index)
I'm searching how to do the same thing but using c++.
const Int32 knotCount = gradient->GetKnotCount();
for (Int32 i = 0; i < knotCount; i++)
{
GradientKnot knot = gradient->GetKnot(i);
const Vector color = knot.col;
result += String::VectorToString(color) + "\n";
}