Get Connector text

Started by freedumz, March 12, 2018, 12:55:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

freedumz

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


Nikolay

You should be able to do it exactly the same way. I.e. connector is just a shape.

Surrogate

#2
cross-post
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

wapperdude

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

Wapperdude
Visio 2019 Pro

freedumz

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
}

wapperdude

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
Visio 2019 Pro

Nikolay

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:


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

Nikolay

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.

wapperdude

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

Visio 2019 Pro

freedumz

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

wapperdude

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

Wapperdude
Visio 2019 Pro