Label Script Example
This example shows how to get data from the PIPELINES table to a label. In the CADMATIC example project, data such as NS and PN can be given to a pipeline or pipe run. Usually the label shows the data given to the pipe run. If no data has been given to the pipe run, you can think that for example the size of that specific pipe run is the same as that defined to the pipeline. In this case you probably want to show the data of the pipeline in the label.
The example labels script uses the function GetNsOfDiagramPipeline to get the nominal size, but you can get more data from the pipeline by using the function get_pline_data: with this function you get the image of the pipeline, and you can read the values of several fields. After you have read all the needed data, call the function free_pline_data to free the image and to close the PIPELINES table.
get_pline_data(pipeline, p_tbl, p_image)
{
sel = pd_make_sql_query_by_posid( "PIPELINES", pipeline, PD_SQL_QUERY_ALL );
p_tbl = DB_TBL_OPEN_SQL_QUERY( "PIPELINES", sel);
if( p_tbl == 0 )
return(0);
st = 0;
p_image = DB_FULL_IMAGE(p_tbl);
rec = DB_NEXT_REC(p_tbl, p_image, st );
if( ISINT( rec )){
return( ER_RET );
}
return(0);
}
free_pline_data(p_tbl, p_image)
{
if( ISINT( p_tbl ))
return( 0 );
DB_FREE_IMAGE(p_image);
DB_TBL_CLOSE(p_tbl);
return(0);
}
In the query data function:
...
if(ns == "" ){
get_pline_data(pipeline, p_tbl, p_image );
if(ns == ""){
xx = DB_GET_FIELD( p_image, "NS", st );
if( xx > -0.1 & xx < 0.1 )
xx = "";
if( xx != "" )
S_PRINTF(ns,"%Q00%.0f",DM_Q_NS,xx);
}
...
After reading all the needed data:
...
free_pline_data(p_tbl, p_image);
...