Adding Modifiers to Objects

When a modifier is created using CreateInstance() it is then added using the function Interface7::AddModifier(). The following code demonstrates the process:

INode* MakeBentCylinder(float radius, float height, int segments, float angle)
{
     // Create a new object using CreateInstance()
     Object *obj = (Object*)CreateInstance(GEOMOBJECT_CLASS_ID, Class_ID(CYLINDER_CLASS_ID,0));

     // Get ahold of the parameter block
     IParamArray *iCylParams = obj->GetParamBlock();

     // Get the current animation time
     TimeValue time = GetCOREInterface()->GetTime();

     // Set the value of radius, height and segments.
     iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_RADIUS), time, radius);
     iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_HEIGHT), time, height);
     iCylParams->SetValue(obj->GetParamBlockIndex(CYLINDER_SEGMENTS), time, segments);

     // Create the object
     INode *node = ip->CreateObjectNode(obj);

     // Create a bend modifier
     Modifier *bend = (Modifier*)ip->CreateInstance(OSM_CLASS_ID, Class_ID(BENDOSM_CLASS_ID,0));

     // Set the bend angle
     IParamBlock2* ipBendBlock = ((Animatable*)bend)->GetParamBlock(0);  //only one pblock2
                    ipBendBlock->SetValue(BEND_ANGLE,time,angle);

     // Create a node in the scene for the object
     // Note that COREInterface12 derives from Interface7
     GetCOREInterface12()->AddModifier(*node, *bend);
     return node;     
}