|
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
// create enum to access the elements of the veNames much more easier,
// ... you dont have to do that you can also access it using the common index
enum
{
veNum = 0,
veName,
veVal,
veEnable,
}
//Setting up the labels & names for the elements
static PRM_Name veNames[] = {
// Number of Elements
PRM_Name("numElm" ,"Number Element"),
// Name of Element, available mult. times
PRM_Name("elmName" ,"Element Name"),
// Type of Element, available mult. times
PRM_Name("elmValue" ,"Element Value"),
PRM_Name("elmEnable" ,"Element Enabled"),
};
2.) setup the templates
PRM_Template elementTemplates[] ={
// Name of the Element (String)
PRM_Template(PRM_STRING, 1, &veNames[veName] , 0),
// Value of the Element
PRM_Template(PRM_FLOAT, 1, &veNames[veVal] , 0),
PRM_Template(PRM_TOGGLE, 1, &veNames[veEnable] , 0),
PRM_Template(),
};
// Main Template List
PRM_Template myTemplateList[] = {
[.........]
// create a template entry of the type PRM_MULTITYPE_LIST,
// using the previous created template as element to be multiplied
// i dont know why the 2 is is there, works out for me
// the PRM_Name("numElm" ,"Number Element") is used to control the number of elements created
// PRMoneDefault means that the default value for the number of elements is 1
PRM_Template(PRM_MULTITYPE_LIST, elementTemplates, 2, &veNames[veNum], PRMoneDefaults),
[.........]
}
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
// returns the number of existing elements
int getElmNum()
{
return evalInt(veNames[veNum].getToken(),0,0);
}
// returns the number of existing elements
int getElmEnabled(int ElmID)
{
eturn evalIntInst(veNames[veEnable].getToken(),&ElmID,0,0);
}
// returns the name of the element specified through ElmID
void getElmName(int ElmID, UT_String &str)
{
evalStringInst(veNames[veName].getToken(), &ElmID,str,0,0);
}
// returns the value of the element specified through ElmID on "pos" (used for int arrays, else pos = 0),
// on moment "time"
float getElmFloat(int ElmID,,int pos,float time)
{
return evalFloatInst(veNames[veVal].getToken(),&ElmID,pos,time);
}
// returns the value of the element specified through ElmID on "pos" (used for int arrays, else pos = 0),
// on moment "time"
int getElmValInt(int AttribID,int pos,float time)
{
return evalIntInst(veNames[veVal].getToken(),&ElmID,pos,time);
}
4.) enable/disable elements
unsigned disableParms()
{
unsigned changed = 0;
[.....]
if (getElmNum()>=1) // get number of elements to create
{
for (int i=1;i<=(getElmNum());i++) // iterate over elements to create
{
char _Vname[255];
char _Vval[255];
// Stitching names together with their consecutive number
sprintf(_Vname,"%s%d",veNames[veName].getToken(),i);
sprintf(_Vval,"%s%d",veNames[veVal].getToken(),i);
// disable element name-field if element is disabled
changed += enableParm(_Vname,getElmEnabled(i));
// disable element value-field if element is disabled
changed += enableParm(_Vval,getElmEnabled(i))
}
}
[.....]
|