Profile picture for user martens

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!)
        doAddNumbers(oFuncOccs);
        // -- Do picture
        doPicture(oModel);
        // -- Do remove numbers (must be after doPicture!)
        doRemoveNumbers(oModel);
    // End Section
    oOutputFile.EndSection();
} // End of for models

// Send the output to a file
oOutputFile.WriteReport();

// -- START OF FUNCTIONS -- //

// 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
            delObj[j].Remove();
        }
    }
} // 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!

 

by Torsten Haase
Posted on Tue, 12/13/2011 - 14:49

Hi Jef,

using the following lines you can format the numbers using a subset of HTML elements (best practice: format an attribute the way you like & read its content in report using AttrTextDef.getStyledValue().getHTML() ):

var occ = oobjocc.Model().CreateTextOcc(xPos, yPos, inText);
var def = occ.TextDef()
def.Attribute(Constants.AT_NAME, nLocale).setStyledValue(sHtmlFormattedValue))

I would recommend to make a copy of the model, but this is not really runtime-friendly. To increase the speed of script "write" operations you can use on-demand saving (otherwise all changes are saved directly) by calling ArisData.Save(Constants.SAVE_ONDEMAND) / ArisData.Save(Constants.SAVE_NOW).

BR, Torsten

0
by Jef Martens MSc Author
Posted on Fri, 12/16/2011 - 12:15

In reply to by EddyVanderlinden

Hi Torsten,

Thank you for your answers!

Using your hints I've produced this little function that you can invoke for a model if you've only created one text element:

function __doStyle(oModel){
    var txtList = oModel.TextOccList(); // Get the elements from the mode
    var htmlCode = txtList[0].TextDef().Attribute(Constants.AT_NAME, nLocale).getStyledValue().getHTML(); // Get the HTML code for the code:
    oOutputFile.OutputLn("HTML Code: \n" + htmlCode, "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT,  Constants.FMT_LEFT | Constants.FMT_ITALIC, 0); // Send the information to an outputfile
}// End of function __doStyle

 

However, the HTML part is still fuzzy, could you elaborate? It seems that in the help function some parts are missing:

From ARIS Script help:

"setStyledValue( String sHTMLValue )

Sets the styled text value of this attribute of this value. The text given as a parameter needs to start with and end with "

This should be <html> and </html>?

Please consider the code below:

// This function adds textobject with numbers to processes in the model
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!
		var occ = oobjocc.Model().CreateTextOcc(xPos, yPos, inText);
		// Define specific text properties
        var def = occ.TextDef();
        var sHtmlValue = <html><body><p style="margin-left:0;margin-bottom:0;margin-top:0"><span style="font-size:16pt;"><span style="color:#ff0000;"><b></b></span></span></p></body></html>;
        def.Attribute(Constants.AT_NAME, nLocale).setStyledValue(sHtmlValue);
		}
} // End function doAddNumbers

When the code is run, the regular output is presented, however the content of the Name is empty. How to put the variable in the sHtmlValue? When I would break up the stream like this:

        var sHtmlValueStart = <html><body><p style="margin-left:0;margin-bottom:0;margin-top:0"><span style="font-size:16pt;"><span style="color:#ff0000;"><b>; 
        var sHtmlValueEnd =  </b></span></span></p></body></html>;
        var sHtmlValue = sHtmlValueStart+inText+sHtmlValueEnd;
        def.Attribute(Constants.AT_NAME, nLocale).setStyledValue(sHtmlValue);

an error occurs as the HTML parser is not triggered to stop the readout (like </html> does).

 

So in conclusion, how would we see the correct formatting? Could you give the code example, because the help function is unhelping with missing instructions :)

 

On the model saving: great explanation!

The save on demand function [ArisData.Save(Constants.SAVE_ONDEMAND)] is invoked at script start now. While running the script I do not call the save now function so no change is applied.

0
by Jef Martens MSc Author
Posted on Wed, 12/21/2011 - 15:35

Fixed it:

You need to escape ALL characters and make an assemblied string:

// This function adds textobject with numbers to processes in the model
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!
		var occ = oobjocc.Model().CreateTextOcc(xPos, yPos, inText);
        // Define specific text properties
        var def = occ.TextDef();
        var sHtmlValue = "\<html\>\<body\>\<p style\=\"margin-left\:0\;margin-bottom\:0\;margin-top\:0\"\>\<span style\=\"font-size\:16pt\;\"\>\<span style\=\"color\:\#ff0000\;\"\>\<b\>"+inText+"\<\/b\>\<\/span\>\<\/span\>\<\/p\>\<\/body\>\<\/html\>";
        def.Attribute(Constants.AT_NAME, nLocale).setStyledValue(sHtmlValue);
		}
} // End function doAddNumbers	

// This function shows a model picture
function doPicture(oModel){
    // Set model name header
    oModelName = oModel.Name(nLocale);
    // Print the contents set previously to the outputfile
    oOutputFile.OutputLn("Model Graphic", oFont, oTitleFontSize, oTitleFontColor, oTitleFontColorBG,  oTitleAlign, 0);
    //Define picture
    var gColor = false; // Set color mode for the graphic. 
    if (oPicture == "BW"){gColor = true} // If the variable oPicture is other than BW it is output as color. 
    oModelPicture = oModel.Graphic(false, gColor, nLocale);
    // Print picture
    oOutputFile.OutGraphic(oModelPicture, -1, oOutputFile.getCurrentMaxWidth(), oOutputFile.GetPageHeight() - oOutputFile.GetTopMargin() -oOutputFile.GetBottomMargin() -10);
    // Create an empty line to provide some spacing between content
    oOutputFile.OutputLn("", oFont, oTitleFontSize, oTitleFontColor, oTitleFontColorBG,  oTitleAlign, 0);

} // End of function __doPicture

// This function removes textobjects with numbers 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
            delObj[j].Remove();
        }
    }
} // End function doRemoveNumbers
0
by Abdul Ismail
Posted on Mon, 02/25/2013 - 09:50

Hi Jef,

is there any way I can change the color of that text occurrence, because I'm required to display text on a black rectangle, the text is definitely appearing, but not visible when I put it above the rectangle, this is my code right now;

 

var valHeading = newModel.createRoundedRectangle(xaxis, 100, headingWidth, headingHeight);
valHeading.setFillColor(Constants.C_BLACK, Constants.C_BLACK, Constants.FILLTYPE_SOLID);
var valueText = newModel.CreateTextOcc(valTextPositionX, valTextPositionY, "THIS IS MY TEXT");

valueText.setZOrder(valHeading.getZOrder() + 1);
var def = valueText.TextDef();
var sHtmlValue = "\<html\>\<body\>\<p style\=\"font-color\:#000000\;color:#000000;margin-left\:0\;margin-bottom\:0\;margin-top\:0\"\>\<span style\=\"font-color\:#000000\;font-size\:16pt\;\"\>\<span style\=\"color\:\#000000\;\"\>\<b\>THIS IS MY TEXT\<\/b\>\<\/p\>\<\/body\>\<\/html\>";
 def.Attribute(Constants.AT_NAME, lang).setStyledValue(sHtmlValue);
0
by Jef Martens MSc Author
Posted on Mon, 07/22/2013 - 15:07

Hi Abdul,

A quick review of your code shows that your "Rounded Rectangle" has a cell color value of Constants.C_Black and a cell border color set to Constants.C_Black.

The content which should be placed inside the rectangle is also set to black:

...font-color\:#000000

 

Therefore the result would be black text in a black rounded rectangle with black filling and black outline. Please try and change the text value to white to see if the content is available: font-color\:#FFF (you can abbreviate colors when they are basic and repeating, so 000 for 000000 or fff for FFFFFF).

 

0
by Jef Martens MSc Author
Posted on Mon, 07/22/2013 - 15:58

The latest versions of ARIS caused some issues with the numbers dropping below the graphic, z-order troubles.

 

The current code fixes this:

// Put the Labels (TextOccurrences) in front of everything
    // List all objects on the model:
    var putObj = oModel.TextOccList();
    for (var ij=0; ij<putObj.length; ij++){ // For each TextOccurrence ...
        // ... get the value of the occurrence.
        var movObj = putObj[ij].TextDef().Attribute(Constants.AT_NAME, nLocale).getValue();
        // Test the value to be smaller than 100 to make sure only the numbers are targeted
        if (parseInt(movObj) <100){
        // Set the zOrder for each element
        putObj[ij].setZOrder(1);
        }// end if putObj
    }// end for ij putObj
0
by Brittany Trasser
Posted on Fri, 04/03/2015 - 00:57

Hi Guys,

Great Report! Is there anyway this function can populate an attribute and appear next to the process step in the model rather than in a report?

Thanks!

0

Featured achievement

Question Solver
Share your expertise and have your answer accepted as best reply.
Recent Unlocks
  • CR
  • BH
  • Profile picture for user Ivan.Ivanov.softwareag.com
  • Profile picture for user mscheid
  • MS
  • PacMan

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock