Title Box Label

When the title box label is updated, the initial text possibly defined in the startup script (or its subroutine) is replaced with data extracted from the database. The data extraction and formatting routine is RETRIEVE_TITLEBOX_DATA() in the labels script.

In this example, the time of saving a diagram is stored in the database (in PI_CATALOG) and the status is taken from the COS attribute "Diagram status" (dSt).

Modifications in set_defaults

To save the saving time in the database, you have to add the required fields to PI_CATALOG and add the following functions to the set_defaults script:

Copy
/*
**    Script adds saving time in PI_CATALOG card if field exists
**
**    SaveTimeInt field should be type int and it has value of saving time
**    in integer format. By CNV_TIME() and CNV_DATE() functions time can be
**    converted to time and date.
**    SaveTime field must be string field and time in string format will be
**    added to this field.
**    SaveDate field must be string field and date in string format will be
**    added to this field.
**
**    save_last_save_time_to_diagram_header(status) saves time to Diagram 
**    DB header card.
**
**    PdSaveDiagram()-save data to edit card (status == 0)
**    PdSaveRevision()-save data to check in card (status == 1)
*/

PdSaveDiagram()

{
    save_last_save_time_to_diagram_header(0);
}

PdSaveRevision()

{
    save_last_save_time_to_diagram_header(1);
}

save_last_save_time_to_diagram_header(status)
{
    diagram = PD_GET_NAME_OF_ACTIVE_DIAGRAM();
    
    sel = "SELECT * FROM PI_CATALOG WHERE Name = '"+diagram+"' AND Status = " + ITOASCII(status);
    
    tbl = DB_TBL_OPEN_SQL_QUERY("PI_CATALOG", sel);
    if(tbl == 0)
        return(0);
    
    st = 0;
    image = DB_FULL_IMAGE(tbl);
    rec    = DB_NEXT_REC(tbl, image, st);
    
    if(!ISINT(rec)){
        time = GET_TIME();
        if(DB_FIELD_EXIST(image, "SaveTimeInt"))
            DB_SET_FIELD(image, "SaveTimeInt", time);
        
        date = CNV_TIME(time, 1);
        if(DB_FIELD_EXIST(image, "SaveTime"))
            DB_SET_FIELD(image, "SaveTime", date);
        
        date = CNV_DATE(time, 1);
        if(DB_FIELD_EXIST(image, "SaveDate"))
            DB_SET_FIELD(image, "SaveDate", date);
        
        DB_UPDATE_REC(tbl, rec, image);
    }
    pd_close_table(tbl, image);
}

Retrieve Title Box Data

Copy
RETRIEVE_TITLEBOX_DATA(image, STRING titleboxstr)
{
    st = 0;
/*
**    Next lines are example how to get attribute data of Diagram from COS.
**
**    first get Diagram oid from DB
**        oid = DB_GET_FIELD( image, "PdObjectId", st);
**    then read COS object
**        r = COS_READ_OBJECT(oid);
**    If r == 0 then read of COS objects succeeded
**    and then arrtibute data can bee read
**        name = DM_GET_TAGVAL(attrs, DM_COSA_NAME);
**    COS object must be set free before continuing
**        COS_FREE_OBJECT(oid);
*/
    oid = DB_GET_FIELD(image, "PdObjectId", st);
    r = COS_READ_OBJECT(oid);
    attrs = COS_GET_OBJECT_ATTRIBUTES(oid);
    if(! ISINT(attrs)) {
        diag_status = DM_GET_TAGVAL(attrs, "dSt"); /* Document status */
        s16 = diag_status;    
        DM_FREE_TAGREC(attrs);
        COS_FREE_OBJECT(oid);
    }

/*
**    Modified in version 18.1.1
**    Field separator changed from "\\" to ";"
*/
    s1  = DB_GET_FIELD(image, "DrawingNumber", st) +";";
    s2  = ITOASCII(DB_GET_FIELD(image, "Revision", st)) +";";
    s3  = DB_GET_FIELD(image, "DescriptionRow1", st) +";";
    s4  = DB_GET_FIELD(image, "DescriptionRow2", st) +";";
    s5  = DB_GET_FIELD(image, "DescriptionRow3", st) +";";
    s6  = DB_GET_FIELD(image, "DescriptionRow4", st) +";";
    s7  = DB_GET_FIELD(image, "DesignedBy", st) +";";
    s8  = DB_GET_FIELD(image, "DesignDate", st) +";";
    s9  = DB_GET_FIELD(image, "CheckedBy", st) +";";
    s10 = DB_GET_FIELD(image, "CheckDate", st) +";";
    s11 = DB_GET_FIELD(image, "ApprovedBy", st) +";";
    s12 = DB_GET_FIELD(image, "ApprovalDate", st) +";";
    s13 = DB_GET_FIELD(image, "RevisionId", st)+";";
    s14 = DB_GET_FIELD(image, "SaveDate", st) +";";
    s15 = DB_GET_FIELD(image, "SaveTime", st) +";";
    
    titleboxstr = s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12+s13+s14+s15+s16;

    return(0);
}