Sebastian H. Schmidt | FX - Technical Director | Research & Development
home

HDK - dynamic parameters for an OP-Node


to make a OP capable to hold a dynamic number of attributes you have to do the following steps.

 

Key Words: PRM_MULTITYPE_LIST,PRM_MULTITYPE_SWITCHER


1.) define the elements that should be available multiple times

2.) setup the template

3.) access the data

4.) enable/disable elements

1.)_define the elements that should be available multiple times

 

 

  1. // create enum to access the elements of the veNames much more easier,
  2. // ... you dont have to do that you can also access it using the common index
  3. enum
  4. {
  5.   veNum = 0,
  6.   veName,
  7.   veVal,
  8.         veEnable,
  9. }
  10.  
  11. //Setting up the labels & names  for the elements
  12. static PRM_Name        veNames[] = {
  13.     // Number of Elements
  14.     PRM_Name("numElm"  ,"Number Element"),
  15.     // Name of Element, available mult. times
  16.     PRM_Name("elmName"    ,"Element Name"),
  17.     // Type of Element, available mult. times
  18.     PRM_Name("elmValue"  ,"Element Value"),
  19.     PRM_Name("elmEnable"       ,"Element Enabled"),
  20. };
  21.  

2.) setup the templates

  1. PRM_Template elementTemplates[] ={
  2.  
  3.     // Name of the Element (String)
  4.     PRM_Template(PRM_STRING,  1,   &veNames[veName]  , 0),
  5.     // Value of the Element
  6.     PRM_Template(PRM_FLOAT,   1,  &veNames[veVal]  , 0),
  7.     PRM_Template(PRM_TOGGLE,  1,    &veNames[veEnable] , 0),
  8.    PRM_Template(),
  9. };
  10.  
  11. // Main Template List
  12. PRM_Template myTemplateList[] = {
  13.     [.........]
  14.  
  15.     // create a template entry of the type PRM_MULTITYPE_LIST,
  16.     // using the previous created template as element to be multiplied
  17.     // i dont know why the 2 is is there, works out for me
  18.     // the PRM_Name("numElm"  ,"Number Element") is used to control the number of elements created
  19.     // PRMoneDefault means that the default value for the number of elements is 1
  20.     PRM_Template(PRM_MULTITYPE_LIST, elementTemplates, 2, &veNames[veNum], PRMoneDefaults),  
  21.  
  22.     [.........]
  23.  
  24.  
  25. }

the style how the new attributes, are arranged could be changed using the diffrente PRM_MULTITYPE  constants, (PRM_MULTITYPE_SWITCHER, PRM_MULTITYPE_LIST)

3.) access the data

  1. // returns the number of existing elements
  2. int getElmNum()
  3. {
  4.    return evalInt(veNames[veNum].getToken(),0,0);
  5. }
  6.  
  7. // returns the number of existing elements
  8. int getElmEnabled(int ElmID)
  9. {
  10.    eturn evalIntInst(veNames[veEnable].getToken(),&ElmID,0,0);
  11. }
  12.  
  13. // returns the name of the element specified through ElmID
  14. void getElmName(int ElmID, UT_String &str)
  15. {
  16.   evalStringInst(veNames[veName].getToken(), &ElmID,str,0,0);
  17. }
  18.  
  19. // returns the value of the element specified through ElmID on "pos" (used for int arrays, else pos = 0),
  20. // on moment "time"
  21. float getElmFloat(int ElmID,,int pos,float time)
  22. {
  23.   return evalFloatInst(veNames[veVal].getToken(),&ElmID,pos,time);
  24. }
  25.  
  26. // returns the value of the element specified through ElmID on "pos" (used for int arrays, else pos = 0),
  27. // on moment "time"
  28. int getElmValInt(int AttribID,int pos,float time)
  29. {
  30.   return evalIntInst(veNames[veVal].getToken(),&ElmID,pos,time);
  31. }

4.) enable/disable elements

  1. unsigned  disableParms()
  2. {
  3.     unsigned changed = 0;
  4.  
  5.   [.....]
  6.    if (getElmNum()>=1) // get number of elements to create
  7.     {
  8.       for (int i=1;i<=(getElmNum());i++) // iterate over elements to create
  9.       {
  10.         char _Vname[255];
  11.         char _Vval[255];
  12.         // Stitching names together with their consecutive number
  13.         sprintf(_Vname,"%s%d",veNames[veName].getToken(),i);
  14.         sprintf(_Vval,"%s%d",veNames[veVal].getToken(),i);
  15.         // disable element name-field if element is disabled
  16.         changed += enableParm(_Vname,getElmEnabled(i));
  17.         // disable element value-field if element is disabled
  18.         changed += enableParm(_Vval,getElmEnabled(i))
  19.         
  20.       }
  21.     }
  22.     [.....]
  23.