Please enable JavaScript to view this site.

TerraModeler User Guide

Navigation: Programming Interface > MDL Public Functions

Calling Method

Scroll Prev Top Next More

Calling Method

The functions can be called with mdlCExpression_ getValue(). The code example below illustrates the method:

 

void Example( void)

{
char Expr[120] ;
char Name[32] ;
int Ret ;
 
if (TmCall( &Ret, "FnSurfaceCount()") > 0)
       mdlOutput_printf( MSG_PROMPT, “%d surfaces”, Ret) ;
sprintf( Expr, "FnSurfaceName(%ld,%d)", (long) Name, 0) ;
if (TmCall( &Ret, Expr) > 0)
       if (Ret)
               mdlOutput_printf( MSG_MESSAGE, “Name is %s”, Name) ;

}

 

/*-------------------------------------------------------------------

Call a function in TerraModeler. Store return value in *Ret.

 

Return 1 if successful.

Return 0 if TMODEL not found.

Return -1 if failed for another reason.

*/

 

int TmCall( int *Ret, const char *Expr)

{
CExprValue Val ;
CExprResult Res ;
int Ok ;
 
if (!LoadApp( "TMODEL")) return (0) ;
 
Ok = mdlCExpression_getValue( &Val, &Res, Expr, VISIBILITY_CALCULATOR);
if (Ok != SUCCESS) return (-1) ;
if (Ret)
       *Ret = (int) Val.val.valLong ;
 
return (1) ;

}

 

/*-------------------------------------------------------------------

Load MDL application with Name (such as “TMODEL”).

 

Return 1 if succssful.

Return 0 if application not found.

*/

 

int LoadApp( char *Name)

{
void *Ptr ;
int Ok ;
 
/* Is application already loaded? */

 

Ptr = mdlSystem_findMdlDesc( Name) ;
if (Ptr) return (1) ;
 
/* Not loaded, attempt loading */

 

Ok = mdlSystem_loadMdlProgram( Name, NULL, "") ;
if (Ok == SUCCESS) return (1) ;

 

return (0) ;

}

TerraModeler User Guide   1.1.2026   © 2026 Terrasolid Ltd