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.
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
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
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
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);
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
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.
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.
Hi everybody,
I have also a problem while creating a graphic as an excel.
The strang is that the Script works but not every time... Specially when I try to run many modells at the same time, it came this error (see pic.)
I would be thankful, if someone could help.
This is my script:
var C_MAGIC_TWIPS_PER_CHARACTER = 120; //115.90909090909;
var C_MAGIC_TWIPS_PER_PIXEL = 5.0;
var g_oExcel = null;
function main() {
g_oIHelper.INIT_BuildLanguageList();
var omodellist = ArisData.sort(ArisData.getSelectedModels(), Constants.AT_NAME, Constants.SORT_NONE, Constants.SORT_NONE, g_nLoc[0]);
if (omodellist.length == 0) {
Dialogs.MsgBox("Please start the report on at least 1 model!", Constants.MSGBOX_ICON_ERROR, null);
return;
}
if (omodellist.length > 99) {
Dialogs.MsgBox("Please start the report on a maximum of 99 models!", vbCritical);
return;
}
// Initialize Excel file based on C Standards
// 20180620_RS Excel output fix
// OLD: g_oOutfile_2 = Context.createExcelWorkbook(Context.getSelectedFile());
g_oOutfile_2 = Context.createExcelWorkbook("report.xlsx");
for(var i = 0; i < omodellist.length; i++){
Context.writeStatus("Working on model no. " + (i + 1) + " / " + omodellist.length)
createmodelxls(omodellist[i]);
}
g_Sheet_2.write();
}
function createmodelxls(oModel) {
g_Sheet_2 = g_oOutfile_2.createSheet(oModel.Name(g_nLoc[0]));
g_Sheet_2.setFitToPage(true);
var pic = oModel.Graphic(false,false,g_nLoc[0], true);
pic.setZoom(150); // image improvement only(optional)
var g_oOutfile = Context.createOutputObject(Constants.OUTEXCEL, "test.xls");
pic.Save(g_oOutfile, "p1.png");
var firstBytes = Context.getFile("p1.png", Constants.LOCATION_OUTPUT);
var firstDims = calculateImageToExcel(pic, g_Sheet_2);
g_Sheet_2.setPicture(firstBytes, 0,1,1+firstDims.widthcells,2+firstDims.heightcells, 10, 10, firstDims.widthaddtwips, firstDims.heightaddtwips);
}
main();
Hi Med,
what does your log say? (abs log: internalerr.log, jsreport.log, ).
Additionally:
Maybe the new image insertion methods of xlsSheet are worth a try, because their handling is much easier:
sheet.insertCellPicture(int column, int row, byte[] imageData, int imageFormat, double widthMM, double heightMM)
sheet.insertPicture(int column, int row, byte[] imageData, int imageFormat, int insertMethod, double widthMM, double heightMM) BR, Torsten
This problem has turned up on our system too. This earlier post infers that it is a known problem in 9.8 SR2. https://www.ariscommunity.com/users/pamillet/2016-01-19-log-reprt-errors
We are now running V10.0.6 in the cloud and have raised an incident to get it resolved.