Jef Martens MSc's picture

Hello all,

In my search to create a few nice options for my reports, I was wondering about the following:

How to add numbers to a graphic representation of a model for each process.


I've managed this piece of code so far based on the "Add Polygon"  reference:

//Script setup
var nLocale = Context.getSelectedLanguage();
var oOutputFile = Context.createOutputObject();    // Set output file variable
// Get the selected models
    var models = ArisData.getSelectedModels();
    // For each model, work through following script functions:
    for (i=0; i<models.length; i++) {
        // Define some variables
        var oModel = models[i];                                                     // Current model    
        var sModelName = oModel.Name(nLocale);                                      // Name of current model
        var funcOccs = oModel.ObjOccListFilter(Constants.OT_FUNC);                    // Get all function occurrences from the model...    
        var oFuncOccs = ArisData.sort(funcOccs,Constants.SORT_GEOMETRIC, nLocale);    //... sorted geometrically   
    // Create a section
    oOutputFile.BeginSection(false, Constants.SECTION_DEFAULT);
        // -- Do numbers (must be before doPicture!)
        // -- Do picture
        // -- Do remove numbers (must be after doPicture!)
    // End Section
} // End of for models

// Send the output to a file


// This function adds numbers to processes in the model to be represented in the model picture
function doAddNumbers(oFuncOccs) {
	for (var i=0; i<oFuncOccs.length; i++){    // for each process do:
		var oobjocc = oFuncOccs[i];
		// Top Right corner positioning of the object 
		var xPos = oobjocc.X() + oobjocc.Width() + 10;
		var yPos = oobjocc.Y() - 10;
		var inText = ""+parseInt(i+1);        // Hard to find  trick: define text first, then add the number!
		oobjocc.Model().CreateTextOcc(xPos, yPos, inText);
		// Define specific text properties
} // End function doAddNumbers

// This function writes the current model as a picture to the outputfile
function doPicture(oModel){
    // Set model name header
    oModelName = oModel.Name(nLocale);
    // Print the contents set previously to the outputfile
    oOutputFile.OutputLn("Process: "+ oModelName, "Arial", 14, Constants.C_BLACK, Constants.C_TRANSPARENT,  Constants.FMT_BOLD  |  Constants.FMT_LEFT, 0);
    //Define picture
    oModelPicture = oModel.Graphic(false, false, nLocale);
    // Print picture
    oOutputFile.OutGraphic(oModelPicture, -1, oOutputFile.getCurrentMaxWidth(), oOutputFile.GetPageHeight() - oOutputFile.GetTopMargin() -oOutputFile.GetBottomMargin() -10)
} // End of function __doPicture

// This function removes textnumbers from the model smaller than 100
function doRemoveNumbers(oModel) {
    // List all objects on the model:
    var delObj = oModel.TextOccList();
    for (var j=0; j<delObj.length; j++){ // For each TextOccurrence ...
        // ... get the value of the occurrence.
        var tryObj = delObj[j].TextDef().Attribute(Constants.AT_NAME, nLocale).getValue();
        if (parseInt(tryObj) <100){// Test the value to be smaller than 100
} // End function doRemoveNumbers


I'd like to do two things but am stuck at:

- How to precisely define what the added numbers look like (font formatting BOLD and coloring) to show them better in a highly squeezed picture.

- Avoid, in a database and runtime friendly way, to change the current model. doAddNumbers creates new objects to the model, which should not be permanent. Furthermore, the report intended to use doAddNumbers needs to display the last change date and user, not being the person running the script / system user.  How would this best be achieved? Making a copy of the model in a temporary place? Make a backup of the database first and run it as a local copy? Is there some way not to change the content permanently?

Thank you in advance!


Tags: ARIS script ARIS Report