Author Topic: Get Connector text  (Read 1121 times)

0 Members and 1 Guest are viewing this topic.

freedumz

  • Newbie
  • *
  • Posts: 3
Get Connector text
« on: March 12, 2018, 07:55:56 AM »
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

« Last Edit: March 12, 2018, 07:58:01 AM by freedumz »

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Get Connector text
« Reply #1 on: March 12, 2018, 08:45:33 AM »
You should be able to do it exactly the same way. I.e. connector is just a shape.

Surrogate

  • Hero Member
  • *****
  • Posts: 865
    • ShapeSheet™ Knowledge Base
Re: Get Connector text
« Reply #2 on: March 12, 2018, 10:38:41 AM »
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
« Last Edit: March 14, 2018, 09:58:13 AM by Surrogate »

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
  • Ideas Visio-lized into solutions
Re: Get Connector text
« Reply #3 on: March 13, 2018, 12: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

Wapperdude
Visio 2019 Pro

freedumz

  • Newbie
  • *
  • Posts: 3
Re: Get Connector text
« Reply #4 on: March 13, 2018, 03: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
}

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
  • Ideas Visio-lized into solutions
Re: Get Connector text
« Reply #5 on: March 13, 2018, 12: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
Visio 2019 Pro

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Get Connector text
« Reply #6 on: March 13, 2018, 03:56:13 PM »
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:

Code: [Select]
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

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Get Connector text
« Reply #7 on: March 14, 2018, 05: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.

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
  • Ideas Visio-lized into solutions
Re: Get Connector text
« Reply #8 on: March 14, 2018, 09:54:54 AM »
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

  • Newbie
  • *
  • Posts: 3
Re: Get Connector text
« Reply #9 on: March 14, 2018, 10:28:16 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
  • Ideas Visio-lized into solutions
Re: Get Connector text
« Reply #10 on: March 14, 2018, 12: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

Wapperdude
Visio 2019 Pro