Visio Guy

Visio Discussions => Programming & Code => Topic started by: freedumz on March 12, 2018, 12:55:56 PM

Title: Get Connector text
Post by: freedumz on March 12, 2018, 12:55:56 PM
Hi everyone
I'm trying to do a tree which calculates automatically its values
So I have a first shape with a value for example 10, on each branch, I put a weight a what's I'd like to get it's that my macro does the calculus, I attached a sample to have a better understanding

So I use the command  to read the value in my shapes:

CInt(ActivePage.Shapes.ItemFromID(*Here my ID*).Text)

But now I'm looking for something similar to read the values on my connector, is it a way to do that?
Many thanks in advance for your help

Title: Re: Get Connector text
Post by: Nikolay on March 12, 2018, 01:45:33 PM
You should be able to do it exactly the same way. I.e. connector is just a shape.
Title: Re: Get Connector text
Post by: Surrogate on March 12, 2018, 03:38:41 PM
cross-post (https://social.technet.microsoft.com/Forums/office/en-US/f758f2cf-331f-4da0-9344-e2610f4ea3fd/probability-tree-automatic?forum=visiogeneral)
Do you have special master/or shape for create probabilty tree diagram ?
If YES, then this master-shape with well known structure and no need analyze connectors
Title: Re: Get Connector text
Post by: wapperdude on March 13, 2018, 05:51:19 AM
For a selected connector, it is possible to find the shapes connected at both ends, at least in VBA.  See https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-connectedshapes-method-visio (https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-connectedshapes-method-visio)

Wapperdude
Title: Re: Get Connector text
Post by: freedumz on March 13, 2018, 08:27:54 AM
I think I'm stuck in a very stupid thing
I'm trying to get the values I need but I can't find a way to do that
So what I'd like to is, I select a shape, for this shape I look for all shaped on its left ( so in my case)
Is there a way to check if a connector (1D) is connected to which shapes?
Probably with that
I could do an if (my connector is connected to this.shape)
{
Make the calculation
}
Title: Re: Get Connector text
Post by: wapperdude on March 13, 2018, 05:26:44 PM
That's the point of the link.  Connectivity is contained in the connectors...no pun I intended.  Each connector can tell you the shapes at each end.  Knowing the "input" shape, the connector value, you then do your calculation and push results into the subsequent shape.   These are the "from" and "to" shapes.

Hope that makes sense, and, that I understood your question.

Wapperdude
Title: Re: Get Connector text
Post by: Nikolay on March 13, 2018, 08:56:13 PM
Quote from: freedumz on March 13, 2018, 08:27:54 AM
I think I'm stuck in a very stupid thing
I'm trying to get the values I need but I can't find a way to do that
So what I'd like to is, I select a shape, for this shape I look for all shaped on its left ( so in my case)
Is there a way to check if a connector (1D) is connected to which shapes?

Yes, you can try shape.GluedShapes (https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-gluedshapes-method-visio):


var connectedShapeIds = shape1.ConnectedShapes(VisConnectedShapesFlags.visConnectedShapesOutgoingNodes, string.Empty);
foreach (int connectedShapeId in connectedShapeIds)
{
    Shape shape2 = page.Shapes.ItemFromID[connectedShapeId];

    // HERE WE GO - note "shape2" here, the last argument !!!
    var connectorIds = shape1.GluedShapes(VisGluedShapesFlags.visGluedShapesOutgoing1D, string.Empty, shape2);

    /// normally should get single connectorId here (if shapes are connected with a single connector)
    foreach (int connectorId in connectorIds)
    {
        var connector = page.Shapes.ItemFromID[connectorId];

        /// your shape1 text is: shape1.Text
        /// your connector text is: connector.Text
        /// your shape2 text is: shape2.Text
    }
}


Note that you can also use an "old-school" approach eploying .FromSheet / .Connects method to get the connections
Title: Re: Get Connector text
Post by: Nikolay on March 14, 2018, 10:12:46 AM
Please note that such a calculation, with some drawings may not be even possible. For example, consider the following schema:
Now matter where you start, if you try to calculate it, you will end up with all values equal to infinity.
Title: Re: Get Connector text
Post by: wapperdude on March 14, 2018, 02:54:54 PM
It would seem that the algorithm for your calculations would go something like this...

1) initiate by setting all calculations to zero.
2) step thru each connector, do the math, add result to previous stored value. 

Thus if only 1 connector, it gets just that value.  If multiple connectors, the results accumulate.


Wapperdude

Title: Re: Get Connector text
Post by: freedumz on March 14, 2018, 03:28:16 PM
Thank you for your help
I finally something which working well (I will do some optimizations on it but it's work well)
A last question, to save time
I'd like to get a report with all shapes which are connected between them
Is there something existing in Visio? Or I have to code that? (I have all of my connector, so I have to write a small program which store all my data in a file)

Ps: Once again thank you because of you I learnt a lot of things
Title: Re: Get Connector text
Post by: wapperdude on March 14, 2018, 05:37:57 PM
Good. 

The Visio report wizard might might meet your needs. If not, check out this post, reply 16, I think.  Either copy code to  your file, or, copy your drawing to the provided file.  The report feature should work ok.  Been awhile, so no guarantees.

http://visguy.com/vgforum/index.php?topic=6314.msg31205#msg31205 (http://visguy.com/vgforum/index.php?topic=6314.msg31205#msg31205)

Wapperdude