Make basic Math in Draw.io (diagrams.net)

1k views Asked by At

I want to make some basic math stuff like Sum in Diagrams.net (old Draw.io).Is it possible ?

Exemple : I create a new parameter on a shape, like "Elec : T16" and make several copy on this shape. Is it possible to have a Text which can give me the total of the shape with this parameter ?

Best Regards.

I search a lot in the Diagrams.net blog but anything relevent.

2

There are 2 answers

0
Marija On

This is not supported.

Regards,

0
David Harrison On

I also wanted to do something similar and while it doesn't seem possible to do it completely in the software (as of v20.3.0), I did find a bit of a workaround: If you add properties to the shape data, then do File > Export As > XML, the properties will be there in the XML data. You can then count them one of two ways:

  • Open the XML file with a text editor like Notepad++, do a find on the value you want to count. If you choose "Find All" it will tell you how many times it appears.
  • Use a programming language like Python to read through the file and count the instances of that value.

Example:

I created a red circle in a new diagram, edited the text to say "RedCircle" and used Edit Data to add a property called TestValue, to which I assigned a value of 1. When I exported to XML it contained this element:

<object label="RedCircle" TestValue="1" id="6byQ5fOap-RXn7mFit_J-1">

Notes

  • When you export, make sure you turn off the Compressed option, this will create an unusable file.
  • Don't use Save As > XML, this will also use compression.
  • Diagrams.net natively saves in a compressed XML format, with only slight differences between that and the other compressed XML options, but it seems happy to also read in the exported uncompressed XML. I didn't test but if you go the programming route and want to take it a step further, it seems you could have the program update the value of a given "counter" element with the count, then open the XML file in diagrams.net to see the updated value and save it as a native .drawio file or publish in whatever format you like.
  • Edit: I discovered that under File > Properties you can turn off the compression on the actual .drawio file. If you do that you can just work from this file instead of exporting, but you might want to check the size of your file with and without it.
  • I'm sure a plugin could be created to do all of that within the app itself, but the other methods are enough for me at this point.

Hope this helps you!