On 09/12/2016 at 14:45, xxxxxxxx wrote:
Since we are heading into the weekend and the support guys will be gone for a couple of days.
I'll post my solution for you.
//This code changes the color of the knots in a UserData based gradient gizmo
Bool MyPlugin::Execute(BaseDocument *doc)
{
BaseObject *obj = doc->GetActiveObject();
if (!obj) return false;
//Get the object's master UD container that holds all the UserData entries
DynamicDescription *dd = obj->GetDynamicDescription();
if (!dd) return FALSE;
//Get the gradient gizmo from the UD manager
GeData d;
Int32 gizmoID = 1; //The ID# assigned to the UD entry in the UD manager
DescID udEntry(DescLevel(ID_USERDATA, DTYPE_SUBCONTAINER, 0), DescLevel(gizmoID));
obj->GetParameter(udEntry, d, DESCFLAGS_GET_0);
//For safety reasons we should check that the gizmo is a gradient type gizmo
if (d.GetType() != CUSTOMDATATYPE_GRADIENT)
{
GePrint("Wrong Data type");
return false;
}
Gradient *gd = (Gradient* )d.GetCustomDataType(CUSTOMDATATYPE_GRADIENT);
//Get the number of knots
Int32 kcnt = gd->GetKnotCount();
//GePrint(String::IntToString(kcnt));
//We need to delete(flush) all of the knots to change them (yes..this is stupid...But that's how it's changed)
//So we first need to grab and store the current knots data in a list
maxon::BaseArray<GradientKnot> knots;
for(int i=0; i<kcnt; i++)
{
GradientKnot knot = gd->GetKnot(i);
Vector col = knot.col;
Float32 pos = knot.pos;
knots.Append(knot);
}
//Delete the existing knots
gd->FlushKnots();
//Use the stored knot values to re-create them with a different color value
for(int i=0; i < knots.GetCount(); i++)
{
if(i==0) knots[i].col = Vector(1,0,0); //Set the first knot color to red
else knots[i].col = Vector(0, 1, 0); //Set the rest of the knot's colors the green
gd->InsertKnot(knots[i]);
gd->SetKnot(i, knots[i]);
}
//Update the object to reflect the changes
obj->SetParameter(udEntry, d, DESCFLAGS_SET_0);
EventAdd();
return true;
}
-ScottA