ARIS Community - We Love BPM

Output picture of model in Microsoft Excel

Eva Klein's picture
by Eva Klein in Reports & Macros posted on 2010-08-24

Today, I want to show you how easy it is to export the image of an ARIS model using a small ARIS Report. The simple report exports the images of the selected models into a MS Excel sheet.

First, we need to know which model should be exported. This is done as follows:

var models = ArisData.getSelectedModels();

We can create a new MS Excel workbook by calling the method “createExcelWorkbook”. The parameter specifies the file to be created.

var workbook = Context.createExcelWorkbook(Context.getSelectedFile());

To create a sheet for every selected model you have to call the method “createSheet”. The parameter specifies the name of the new sheet. Below, I use the name of the model as the name of the new sheet.

var sheet = workbook.createSheet(oModel.Name(g_nLoc));    

Getting the graphic of a model can be done by calling the Graphic method of the model object. This method takes three parameters. The first parameter means the object is always visible on a part of the graphic. The second parameter defines if the returned graphic should be black & white or contain colors (false = color, true = black and white). The last parameter specifies the language to be returned.

var pic = oModel.Graphic(false,false,g_nLoc);

To get the width and height of the graphic, we use the methods “getWidth” and “getHeight”.

var width = pic.getWidth(Constants.SIZE_PIXEL ) * 20 * (100.0/125.0)
var height = pic.getHeight(Constants.SIZE_PIXEL ) * 20 * 20*(100.0/133.0)

To add the model graphic to the MS Excel table, we have to call the method “setPicture”. The parameters describe the picture to be added and the cells and rows where the picture starts and ends.

sheet.setPicture (data, 0, 4, 0+xCells, 4+yCells, 0, 0, xTwips, yTwips);

Those are the most important commands used in the script. Everything else is just iterating over the list of models, etc. Below is the complete script code.

var g_nLoc = Context.getSelectedLanguage();
var models = ArisData.getSelectedModels();
var workbook = Context.createExcelWorkbook(Context.getSelectedFile());
var dummyOutput = Context.createOutputObject();
main();
dummyOutput.WriteReport() //otherwise it would overwrite the excel output!
workbook.write();

function main(){
    for(var i=0;i<models.length;i++){
        var oModel = models[i];
        var sheet = workbook.createSheet(oModel.Name(g_nLoc));    
        pictureOfModel(oModel,sheet);
    }
}

function pictureOfModel(oModel, sheet) {
    var pic = oModel.Graphic(false,false,g_nLoc);
    var sfileName = oModel.GUID() + ".png";
    var width = pic.getWidth(Constants.SIZE_PIXEL ) * 20 * (100.0/125.0) //twips, correction factor because of excel anomaly (X): * (100.0/125.0)
    var xCells = width / 1024;
    var xTwips = width % 1024;
    var height = pic.getHeight(Constants.SIZE_PIXEL ) * 20*(100.0/133.0) //twips, correction factor because of excel anomaly (Y): \*(100.0/133.0)*/
    var yCells = height / 256;
    var yTwips = height % 256;
    pic.setZoom(150) // image improvement only(optional)
    pic.Save(dummyOutput, sfileName);
    var data = Context.getFile(sfileName, Constants.LOCATION_OUTPUT);

    sheet.setPicture ( data, 0, 4, 0+xCells, 4+yCells, 0, 0, xTwips, yTwips);
    Context.deleteFile(sfileName);
}

Here you can download the entire source code from the "Output picture of model" report.

Note: Make sure to join the Reports & Macros group. You will find additional tutorials and a list of free ARIS reports and macros.

24638 Views
0 Likes
29 Comments
There are no attachments
Mia van Rooyen posted on 2010-12-07

Hey Eva,

How can one highlight the path in a model?

Thanks,

Mia

Eva Klein posted on 2010-12-07

Hi Mia,

I'm not sure if I understand you correctly. What do you mean with path, the connections between functions? Could you give me an example, please.

Regards
Eva

Mia van Rooyen posted on 2010-12-07

I have to draw a rectangle around the function in the model graphic as per SAP->General Test Case Documentation Script. 

Thanks in advance,

Mia

Eva Klein posted on 2010-12-08

If you copy this function into the script you should be able to achieve the required result. When calling the function in the script, the ObjOcc and color information must be included.

function drawrectangle(oobjocc, ncolor) {

    var aPoints = new Array();
    aPoints.push(new java.awt.Point(oobjocc.X() - 5, oobjocc.Y() - 5));    
    aPoints.push(new java.awt.Point(oobjocc.X() + oobjocc.Width() + 5, oobjocc.Y() - 5));    
    aPoints.push(new java.awt.Point(oobjocc.X() + oobjocc.Width() + 5, oobjocc.Y() + oobjocc.Height() + 5));    
    aPoints.push(new java.awt.Point(oobjocc.X() - 5, oobjocc.Y() + oobjocc.Height() + 5));    
    aPoints.push(new java.awt.Point(oobjocc.X() - 5, oobjocc.Y() - 5));        

    var oPolygon = oobjocc.Model().createPolygon(aPoints, false);
    oPolygon.setPenStyle(Constants.PS_SOLID);
    oPolygon.setPenColor(ncolor);    
    oPolygon.setPenWidth(5); 
    oPolygon.setZOrder((oobjocc.getZOrder() - 1));   

    return oPolygon;
}

I hope this information is useful for you.

Regards
Eva

Sebouh Havatian posted on 2010-12-09

Hi

Is there a way to output the graphic of an object instead of the entire model?

Thanks

Eva Klein posted on 2010-12-09

Hi Sebouh,

Unfortunately this does not work.  You can try the following: create a new model via report, insert the object into the model, export the graphic and then delete the model.

Regards
Eva

Ciska de Jager posted on 2010-12-17

Hi Eva,

Thank you for all your valuable inputs, maybe you can help me with how to delete graphical objects from a model, for example Polygons. As they are not occurrences the deleteocc command doesn't work, is there any other way, to delete them using script and not a macro.

Ciska

Eva Klein posted on 2010-12-20

Hi Ciska,

there is a special method in the model which removes the graphic object.

deleteGfxObj ( GfxObj p_gfxToBeDeleted )

I hope this helps you.

Regards
Eva

Ciska de Jager posted on 2010-12-20

Hi Eva,

Thank you, I will give this a try later on, I believe this will help a lot.

Ciska

jay olvey posted on 2011-05-25

Eva - any way we could have this as a .arx?

Eva Klein posted on 2011-05-26

Here you can download the entire source code from the "Output picture of model" report as .arx file.

jay olvey posted on 2011-05-26

Hi Eva - when I try this, I get an error in line 43?

Eva Klein posted on 2011-05-27

Hi Jay - what error message do you get?

jay olvey posted on 2011-05-27

Eva - interestingly, I am no longer receiving an error.  hmm.  must be 'user error'  :)

Ignacio Arriagada posted on 2011-08-05

I'm trying to insert a rectangle in a ModelPicture, with the Picture.Rectangle() method.

In theory, the Picture methods are available for a ModelPicture object. Then, i can use getWidth(), getHeight(), etc., but when using Rectangle(), SelectBrush(), SelectPen(), etc. i get a Wrapped java.lang.NullPointerException.

Can i use these functions that "write" on the picture or have to find other solution? I'm using ARIS 7.1 SR 2010_09

ravi kiran posted on 2011-08-11

hi eva

this is very helpful for me thnks.How to add some text under hedding could u help me

 

Eva Klein posted on 2011-08-11

Hi Ravi,

why do you want to add text below a heading if there is no text in the report?

Julien Job posted on 2011-10-19

Hi,

for of all, thanks for this script.

I have just one question :

How adapt this script for generation one Excel for each model of my BDD ?

 

Thank you in advance

Eva Klein posted on 2011-10-19

Hi Julien,

to make sure that I understand you correctly: do you want to have a separate Excel output for each model? Another question: what do you mean by BDD?

Julien Job posted on 2011-10-19

You understand me correctly ! :)

BDD = DataBase (.adb)

I have several models in my adb and i would like one file for each model

 

Thanks

Julien Job posted on 2011-10-19

Otherwise, I have each GUID of model but how create oModel object with GUID ?

Julien Job posted on 2011-10-19

With oModel, Can I recover GUID ?

Exemple :
 guid =  oModel.getGUIDAsString();

I have an error with this line :

Cannot find function getGUIDAsString in object Model@270 ...

Why ?

 

edit :

guid =  oModel.GUID;  It okey

Julien Job posted on 2011-10-19

My Script :

var workbook;
var sheet;
var g_nLoc = Context.getSelectedLanguage();
var models = ArisData.getSelectedModels();
//guid =  ArisData.getActiveDatabase().getSelectedModels());
var dummyOutput = Context.createOutputObject();
var guid = "_Blank";

main();

dummyOutput.WriteReport() //otherwise it would overwrite the excel output!


function main(){
    for(var i=0;i<models.length;i++){
        var oModel = models[i];
       guid = oModel.GUID();
        
        //Creation fichier Excel
        workbook = Context.createExcelWorkbook("m" + guid + "_gfx.xls");
        
        sheet = workbook.createSheet(oModel.Name(g_nLoc));    
        pictureOfModel(oModel,sheet);
        
        workbook.write();
    }
}

function pictureOfModel(oModel, sheet) {
    var pic = oModel.Graphic(false,false,g_nLoc);
    var sfileName = oModel.GUID() + ".png";
    var width = pic.getWidth(Constants.SIZE_PIXEL ) * 20 * (100.0/125.0) //twips, correction factor because of excel anomaly (X): * (100.0/125.0)
    var xCells = width / 1024;
    var xTwips = width % 1024;
    var height = pic.getHeight(Constants.SIZE_PIXEL ) * 20*(100.0/133.0) //twips, correction factor because of excel anomaly (Y): \*(100.0/133.0)*/
    var yCells = height / 256;
    var yTwips = height % 256;
    pic.setZoom(150) // image improvement only(optional)
    pic.Save(dummyOutput, sfileName);
    var data = Context.getFile(sfileName, Constants.LOCATION_OUTPUT);

    sheet.setPicture ( data, 0, 4, 0+xCells, 4+yCells, 0, 0, xTwips, yTwips);
    Context.deleteFile(sfileName);
Brooke Baker posted on 2011-11-06

Hi,

I realise this thread is old, but is there anyway to create the picture in the current worksheet rather than creating a new sheet? I have already output a table of data and want the graphic beneath.

Thanks

 

Torsten Haase posted on 2011-11-07

Hi,

this should be possible. Just replace the

sheet = workbook.createSheet(...)

by

sheet = workbook.getSheetAt(your sheet's index)

and adjust the column and row in line 42 (sheet.setPicture(imagedata, column, row,...) )

 

Frank Beyer posted on 2012-08-08

Hi Eva,

thanks for your report, we are using it since 1 year. Now we have updated our ARIS to 7.2 and the files produced by the report are bigger (two times as big as before). Is there a version 7.2 of this report or is it normal?

Thanks in advance and kind regards,

Frank

Eva Klein posted on 2012-08-08

Hi Frank,

It is possible that the size of the graphics the Designer component provides has increased with version 7.2.

Regards

Eva

Alikhan Dan posted on 2013-04-12

Hi Eva!

I wonder if you could help me to solve some problem. Above you provided a great scrip for the report using pictures. But I would like to ask you if you could further the report.

Is it posible to export every models from different diagrams form ARIS I've drawn to excel file as pictures, with all their relations? So I can go through the entire chain because I can see not only the individual models on different sheets (as it is on you example report) but also relationships between them (links).

Thank you very much!

All the best.

 

 

Sandeep Nikwade posted on 2013-08-26

Hi Eva

I’m new to this group and read all your reporting related articles and did the implementation of some report on my ARIS 7.1, some of run fantastic and some gave the error which is not yet solve ( will see those later) but I need help on report / script which are  -

  • To extract a map image (in JPEG  / JPG format) in excel with separate sheet for each process map, if I run that report on process folder which is contain ‘N’ number of maps.
  • A excel sheet containing the list of map with its vertical linkage, the background is we follow the vertical flow from level 1 to level 4 (Level 1 is SIPOC, Level 2 is EPC row display, level 3 is VACD and level 4 is EPC) and they are connected to each other. So I want a report which shows the list of level 4 which is under each level 3, list of level 3 which is under level 2 and so on once I click the home or process folder. So basically report look like below way..

Level 1   |     level 2     |     level 3     |        Level 4      |        other few details|||||

Is that possible through script or through WYSIWYG Editor?? if through WYSIWYG editor then how? 

  • Other report/template for object placement & flow, the basic background is that we map the EPC process in horizontal way because our default template and filter and customer wanted (to convert) those in to vertical way, how we can do that with help of report or any readymade template, is that possible? Because we have ARIS portal where we have option to view the map in vertical but not in the ARIS architect database.

Very appreciate if you can provide some help or clue on above issue / requirements.

BR

Sandy.