MySQL Blog Archive
For the latest blogs go to
Automate Figure Arrangement In Workbench

Initiated by a question on the forum I took some time to exercise my Workbench-Scripting-Knowledge. The question was, if it’s possible to do some figure-arrangement/organizing via scripts. To be more precise, the task I had to master was to get tables that have names starting with a given prefix moved into a new layer using scripts.

The function to create a new object – layer in this case – was an easy one. All you have to do is to use the function grtV.newObj(“workbench.model.Layer”). This function returns a handle to the created Layer. Finally, set the visual properties (color, position) and most important, the owner has to be set to the containing Diagram-object. Last step is to add the layer to the “layers” property of the Diagram-object.
The second step, which i put into a separate function, is to ask the user for the prefix to filter the desired tables/objects that should get grouped onto the new layer. Next, loop through the figures on the rootLayer, compare the names with the given prefix and if match add the object to the “figures” property of the destination layer, remove it from rootLayer.figures and adjust the figure coordinates to line them up in a cascading arrangement.

Fetch the attached .zip file and follow the instructions in the README to add the script to your copy of workbench. This is only a basic implementation so feel free to expand/improve it to perform more sophisticated operations on your models.

Download the scriptfile: