Speed up Visio drop :-(

Started by andrekiba, November 10, 2016, 11:09:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

andrekiba

Hi and thanks in advance.
I'm working with visio (2016) automation with C# project using an InvisibleApp visio instance.
I have a quiet big C# tree (from 10 to 500 nodes) in memory and I'm using organization chart template to draw the tree.
I chose organization chart because in this way a have the automatic layout and spacing capabilities that belog to the template.
Each node is a rectangular "Vacancy Belt" shape with Prop.Name and Prop.Title.
Each node can also have 0 or more datagraphic shape as attributes (title collout) and it takes data from document datarecordset based on xml.
I walk the tree with depth first traversal and for each node:
1) drop the shape based on master in calculated position

shape = page.Drop(master, xPosition, yPosition);

2) set the name and title property

shape.Cells["Prop.Name"].Formula = node.Item.Name.ToVisioFormula();
shape.Cells["Prop.Title"].Formula = node.Item.Id.ToVisioFormula();

3) connect the shape with father (dropping connector shape in 0,0 and then using glueto)

var connector = DropConnectorOnPage(shapeFrom.ContainingPage, connectorMaster, 0.0, 0.0);
connector.CellsU["BeginX"].GlueTo(shapeFrom.CellsU["PinX"]);
connector.CellsU["EndX"].GlueTo(shapeTo.CellsU["PinX"]);


It works but it is very slow.
With 60 shapes (14 connectors, 34 datagraphic, 12 rectangle (nodes)) it takes about 15 seconds...and the time increases exponentially with increasing of the nodes.
0.3 --> 0.4 --> 0.6 --> 0.9 --> 1.1 ... seconds for each drop (composed of the three previous step)
The visio InvisibleApp has these properties set when starts

DeferRecalc = 1,
ScreenUpdating = 0,
ShowChanges = false,
LiveDynamics = false,
AutoLayout = false,
UndoEnabled = false

If I also set

EventsEnabled = 0

and then re-enable it before save the document the speed up is remarkable (half time) but Title and Name of rectangular shapes are not drawn and I no longer have the organization chart re-layout capabilities.
I also think that the connection step is slow.
What can I improve to speed up visio drop?
I don't think a possibile DropMany solution may be faster (and child-father connections are difficult to manage after the node shapes are dropped)...  :'( :'( :'(

AndyW

It should be quicker to drop the shape at 0,0 and then set the shape position after.

You can also use DropMany to drop more than one shape at a time.

Live life with an open mind

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

andrekiba

Thanks @Paul I had already seen your link :-(
Unfortunately @AndyW DropMany is not faster than single drop sequence (total time is equal, I already tried...).
Slowness is related to EventsEnabled and shape connections with dynamic connector...
But I don't know how to improve these aspects... :-(

andrekiba

Another question:
why if events are disabled the Title and Name of rectangular (nodes) shapes are not displayed?
As I said these shapes are generated from "Vacancy Belt" master of organization chart stencil
Watching ShapeSheet these properties are correctly set...  :'(

andrekiba

Does anyone know if there is a way to disable the autoconnect behavior (if child si dragged over a father shape) of organization chart shapes? I want to connect the shapes only after all of them were dropped. And I still need help for previous post question...if you open new organization chart document, disable automation events, drag a master from any org chart stencil...shape's title, ID and others do not appear (the rectangular is empty). Now if I re-enable events and change some shape data properties in Shape Sheet these properties are correctly set but shapes inside doc are still empty... Please help!!  :'(  :'(

Nikolay

#6
These functions (auto-layout of chart on shape drop and populating shape text) are not "native" visio functions (therefore cannot be controlled with shape-sheet or vba) but are actually provided by the built-in orgchart addin (think "Org Chart" tab). Therefore, answering your first question, if you disable events, that addin also gets disabled, and text does not get populated. As for the second question - as far as I know, this cannot be controlled - the "auto-layout" behavior is provided again by that addin, and it is not really configurable.

There is a long-standing feature request to provide API for the org-chart. You can vote for it here.
https://visio.uservoice.com/forums/368205-visio-for-developers/suggestions/4982614-open-api-of-org-chart

As for the performance. Maybe it's not even your code that is slow; remember that almost every shape modification you do is also processed also by that other add-in.
And devil only knows what exactly it is doing :)

As a result, I would recommend you to avoid messing around with other closed-code solutions (like org chart);
If you create your own shapes and your own template, you may see significant performance improvements.

andrekiba

#7
Very thanks @Nikolay
I know the org chart add-in is quite slow...but implement from zero a template with org chart capabilities (re-layout, spacing...) it seems to be a too expensive task for budget and time :-(
Another solution?

vojo

IMHO...might be better off using Excell to create a table for org chart you want
   - PinX  PinY, user attributes, prop attributes, etc

then use a simple VBA engine to read spreadsheet and plop down shapes
(maybe even do the connections between them)

Nikolay

Quote from: andrekiba on November 15, 2016, 08:45:51 AM
Very thanks @Nikolay
I know the org chart add-in is quiet slow...but implement from zero a template with org chart capabilities (re-layout, spacing...) it seems to be a too expensive task for budget and time :-(
Another solution?

Another solution for what exactly? :)
That is, the answer actually depends on what you are trying to achieve by creating custom solution. I.e. why out-of-the box org. chart solution doesn't fit your needs?

andrekiba

The explanation of what I'm trying do is in my first post 😀
I don't understand why Excel plus macro could be faster...but the thought of having to use Excel makes me unhappy and so I will not even trying!! 😀
I have a C# tree in memory and I need to draw it...simple...
The org char it's almost fine for re-layout capabilities (do a custom template with re-layout capabilities it's not trivial)...but auto connections of org chart shapes slow down awfully all the process!!
I need to solve this problem...and the solution seem to be that of disable events and write text (using Characters property) inside node shapes (because set shape data it's not sufficient, view not update).
Thanks to all!!