Monitoring Parameter Changes

Developers can monitor parameter changes using a call-back mechanism, by overriding the PBAccessor class. This allows continuous monitoring of the parameter change. PBAccessor has a get method, PBAccessor::Get(), and three set methods, PBAccessor::PreSet(), PBAccessor::PostSet(), and PBAccessor::Set(). As of 3ds Max 2018, plug-ins should generally use PreSet(), as the state of the value returned by GetValue() inside this method is guaranteed to be the "original" value. (In PostSet(), it's guaranteed to be the new value).

In the bend modifier in the below example, the function Set() has been used to check the values of bend_from and bend_to.

PBAccessor::Set() is passed a PB2Value structure which holds the data being changed and an ID of the parameter changing. The following PBAccessor changes the value of bend_from and bend_to depending on a comparison of each other.

class bendPBAccessor : public PBAccessor
{
public:
   void Set(PB2Value& v, ReferenceMaker* owner, ParamID id, int tabIndex, TimeValue t)
   {
     BendMod* u = (BendMod*)owner;
     IParamMap2* pmap = u->pblock2->GetMap();
     float from, to;

     switch(id)
     {
      case bend_from:
         u->pblock2->GetValue(bend_to,t,to,FOREVER);
         from = v.f;
         if (from >to) {
          u->pblock2->SetValue(bend_to,t,from);
         }
         break;

      case bend_to:
         u->pblock2->GetValue(bend_from,t,from,FOREVER);
         to = v.f;
         if (from>to) {
          u->pblock2->SetValue(bend_from,t,to);
         }
         break;
     }
   }
};