The labels Script

The labels script includes the CADMATIC version detector described in Version Detector.

Extracting Data for Label

The scriptlib routines call a set of user-definable script routines that are expected to be coded in the labels script. The following functions must be defined:

  • GET_DEF_ARM_LBL_DATA(....)
  • GET_DEF_EQ_LBL_DATA(...)
  • GET_DEF_INST_LBL_DATA(...)
  • GET_DEF_PLINE_LBL_DATA(...)
  • RETRIEVE_TEXT_LBL_DATA(...)
  • RETRIEVE_TITLEBOX_DATA(...)

GET_DEF_xxx_LBL_DATA(...)

These functions specify the data needed by the scriptlib to insert a default label immediately after inserting the PD object (armatures, equipments, instruments and pipelines).

If instant labeling is enabled in the settings, the label defined in this routine will be called each time a new PD object is inserted.

GET_DEF_xxx_LBL_DATA(dg_symb, lbl_class, lbl_type, digit_mode, sym_name, sc_x, sc_y, rot_angle)

dg_symb

Object handle of the selected diagram object.

lbl_class

A classifier which could be used to control e.g. the formatting of the label ID string. Labels in the same class share the same data extraction routine.

lbl_type

"TEXT" or "SYMBOL"

digit_mode

The digitizing mode. Specifies whether there will be a label with or without a reference line etc. The digitizing mode defined for the Diagram Object Template overrides this value. See Digitizing mode.

sym_name

Name of the 2D symbol which is used to visualize the extracted label data. For TEXT this is the text number; for others the plain name of the 2D symbol.

sc_x, sc_y

Symbol scaling in X and Y direction.

rot_angle

Symbol rotation.

Example of Getting a Default Label for Armature

Copy
GET_DEF_ARM_LBL_DATA(dg_symb, lbl_class, lbl_type, digit_mode, symname, sx, sy, r)
{
    lbl_class    = "DIN_APOS1";
    lbl_type    = "TEXT";    
    digit_mode    = "DW_TXT_PNT_OG_RN";
    symname        = "26";
    sx            = 1.0;
    sy            = 1.0;
    r            = 0.0;
}

RETRIEVE_TEXT_LBL_DATA(...)

This function is called every time when a text type label is created or updated. It creates the data string which will be set in the label.

RETRIEVE_TEXT_LBL_DATA(dg_symb, STRING lbl_class, STRING datastr, query_userdata)

dg_symb

Object handle of the selected diagram object.

lbl_name

The name of the label class.

datastr

The data extracted from database according to the selected object (dg_symb) and the label class. This function is a general interface to query data for a text symbol. Typically the routine branches according to the label classes.

query_userdata

This is a Boolean flag (1=yes, 0=no). The value is only interesting if you are using labels which directly query some data from the user rather than from the database. If you want to let the user to edit the data (when the label is created or updated). Sometimes the system should just draw the label without interactions with the user (massive "update all labels", or when some plain database data has been edited).

Example of Retrieving Text Label Data

Label class is "ARMATURE_LABEL" and new query data function will be get_new_armature_label().

Create label text string NS-PosId. If no NS has been given for the armature itself, it is taken from the pipeline.

Copy
RETRIEVE_TEXT_LBL_DATA(dg_symb, STRING label_name, STRING datastr, query_userdata)

    {

        if(label_name == "DIN_PLID1")
            return(get_din_plid(dg_symb, datastr));

        else if(label_name == "DIN_APOS1")
            return(get_din_apos(dg_symb, datastr));
        
        else if(label_name == "DIN_POSID1")
            return(get_din_posid(dg_symb, datastr));
    
        /* NEW LABEL */
        else if(label_name == "ARMATURE_LABEL")
            return(get_armature_label(dg_symb, datastr));

        /* undefined label_name?! */
        else if(query_userdata)
                return(query_users_txtlbldata(dg_symb, label_name, datastr));

        else return(1);
    }

    get_armature_label(dg_symb, string label_text)
    {
        /* Open images to the main and sub-tables referenced via the handle to the DG object
        ** Variables:
        **
        ** main_img = image to object main table
        ** sub_img = image to object sub-table
        ** subtbln = name ob objects sub-table
        */
        main_img = 0;
        sub_img = 0;
        subtbln = "";
        /* open_imgs_to_obj is a local tool function in labels script,
        ** which opens tables of object and reads data to image variables
        ** The type of the object must be defined in the function call
        */

        if(open_imgs_to_obj(dg_symb, "ARMATURES", subtbln, main_img, sub_img)){
            return(-1);
        }

        st = 0;
        /*
        ** Read PosId from database
        */
        vpos = DB_GET_FIELD(main_img, "PosId", st);
            
        if(st){
            close_imgs_to_obj();
            U_MESSAGE("Cannot extract PosId");
            return(-1);
        }

        /*
        ** Build label of type NS-PosId
        ** The format depends on the field values so that empty fields are
        ** not printed.
        ** If NS has not been given to the armature itself, we assume it to
        ** be the same as NS of the pipeline and we take from the pipeline
        **

        ns="";
        /* is there "NS" in the sub-table image */
        if(DB_FIELD_EXIST( sub_img, "NS")){
            q_ns = DB_GET_FIELD(sub_img, "NS", st);
            
            /* if "ns" is 0 then read "ns" from pipeline */

            if(st | (q_ns > -0.1 & q_ns < 0.1)){
                pipeline = DB_GET_FIELD(main_img, "Pipeline", st);
                q_ns = GetNsOfDiagramPipeline(pipeline);

            }

            if( st | q_ns > -0.1 & q_ns < 0.1 )
                ns = "";
                
                else {
                /* print in memory formatted, use first unit of quantity NOMINALSIZE, do not print the unit */
                S_PRINTF(ns,"%Q00%.0f",DM_Q_NS,q_ns);
            }
        }

        else ns = "";

        /* code the argument string for the 2D symbol */
        /* Don't print NS if ns is empty */

        if(ns != "")

            label_text = ns;

        /* add pos id to the label string */
        label_text = label_text + "-" + vpos;

        /* close tables */
        close_imgs_to_obj();

        if( label_text == "" ){
            label_text = "???";
            return(0);
        }

        return(0);
    }

See also Label Script Example.

RETRIEVE_TITLEBOX_DATA(image, STRING titleboxstr)

image

Full image of the PI_CATALOG table.

titleboxstr

A string argument storing the result of the retrieval.

This function is a formatting function which gets data from the image and then stores it into titleboxstr in a format which the associated 2D symbol (title box) is able to interpret. Since "text" 2D symbols have a fixed argument list, you must pass the whole set of items coded into a single string argument. It does not matter how the coding is done as long as the particular 2D symbol is built so that it can decode the information. In the CADMATIC example project the coding is done by using "\" character as a field separator.

See also Title Box Label.

Visualizing Labels

Labels are visualized either via 2D symbols or as plain text. The text symbols have a fixed argument list. Most of the arguments are values of the current text drawing attributes.

text3(string datastr, x, y, len, height, width, spc, lorg, ldir, slant, color, pen)

datastr

Text string.

x, y

Location of the reference point.

len

Length.

height, width, spc

Height, width and spacing.

lorg

Current local text origin (1–9).

ldir

Current text line direction (angle).

slant

Current text slant angle.

color

Current text color ID.

pen

Current pen id. References the line width.

Symbol type labels use plain 2D symbols which should not have any arguments.