This UDF code is written as an example of how RP variables that
were given values in a Scheme interface can then be read for use by
a User-Defined Function. This UDF can be used in conjunction with
the Dialog Box Example above to show how
RP variables are created and set in a dialog box and then read by
a UDF. This UDF uses a
DEFINE_EXECUTE_FROM_GUI
statement so that
the UDF runs whenever the button is clicked
in a corresponding dialog box. To learn more about the various ways
of invoking a UDF, see
DEFINE Macros.
For information on how to load your UDF into Fluent via compilation,
see Compiling UDFs.
//Required for all UDFs
#include "udf.h"
//Allows UDF to execute when "OK" button is clicked
DEFINE_EXECUTE_FROM_GUI(check, libudf, mode)
{
//Variable Declarations
int listNum;
int dropDownListNum;
int i;
//If "Test Button" was clicked
if(mode == 1){
if(strlen(RP_Get_String("myudf/buttonstr")) != 0){
Message("The test button string is %s\n", RP_Get_String("myudf/buttonstr"));
}else{
Message("The test button string is empty\n");
}
Message("\n");
//If "OK" button was clicked
}else if(mode == 2){
//Check box RP variables are checked
if(RP_Get_Boolean("myudf/checkbox1")){
Message("Check box 1 is checked\n");
}else{
Message("Check box 1 is not checked\n");
}
if(RP_Get_Boolean("myudf/checkbox2")){
Message("Check box 2 is checked\n");
}else{
Message("Check box 2 is not checked\n");
}
//Radio button RP variables are checked
if(RP_Get_Boolean("myudf/radiobutton1")){
Message("Radio button 1 is checked, therefore radio button 2 is not checked\n");
}else if(RP_Get_Boolean("myudf/radiobutton2")){
Message("Radio button 2 is check, therefore radio button 1 is not checked\n");
}else{
Message("Neither radio button is checked\n");
}
//Integer and real number RP variables are checked
Message("The integer is '%d'\n", RP_Get_Integer("myudf/int"));
Message("The real number is '%f'\n", RP_Get_Real("myudf/real"));
//String RP variable checked
if(strlen(RP_Get_String("myudf/string")) != 0){
Message("The string is '%s'\n", RP_Get_String("myudf/string"));
}else{
Message("The string is empty\n");
}
//Test button string RP variable checked
if(strlen(RP_Get_String("myudf/buttonstr")) != 0){
Message("The test button string is '%s'\n", RP_Get_String("myudf/buttonstr"));
}else{
Message("The test button string is empty\n");
}
//List items RP variable checked
if(listNum = RP_Get_List_Length("myudf/list")){
for(i=0; i<listNum; i++){
Message("List item number %d is '%s'\n", i+1, RP_Get_List_Ref_String("myudf/list", i));
}
}else{
Message("The list is empty\n");
}
//Drop-down list RP variable checked
if(dropDownListNum = RP_Get_List_Length("myudf/droplist")){
Message("The drop-down list item is '%s'\n", RP_Get_List_Ref_String("myudf/droplist", 0));
}else{
Message("The drop-down list is empty");
}
Message("\n");
//If neither "Test Button" or "Ok" button was clicked
}else{
Message("Error!\n");
}
}