
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!
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() ):
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
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:
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:
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:
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.
Fixed it:
You need to escape ALL characters and make an assemblied string:
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;
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).
The latest versions of ARIS caused some issues with the numbers dropping below the graphic, z-order troubles.
The current code fixes this:
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!