Visio Guy

Visio Discussions => General Visio => Topic started by: friesstefan@gmx.de on September 15, 2021, 11:13:07 AM

Title: Visio connector
Post by: friesstefan@gmx.de on September 15, 2021, 11:13:07 AM
Hello together,
i hope there is anybody who can help me.

I have in my Visio over 100 Shapes. These shapes i want to connect with connectors.
Each shape need an entrance and exit. (from Shape and to the next shape).
I want to do this with an external Data from Excel sheet.

The connector thickness should based on a value (shape date 0-100%). (external Data).

Shapes in Visio named for example A; B; C etc.

External Data like this (i can chance it if is neccessary - is not settled)
Connector: A to B Value: 80%
Connector: A to C value: 40%
Connector: B to C value: 50%

Is it possible to connect each connector automatic based on the external data list?
If yes? How can i do this? :-\ :-\ :-\

best regards
Stefan
Title: Re: Visio connector
Post by: Surrogate on September 15, 2021, 03:13:39 PM
Hi there, Stefan !
Quote from: friesstefan@gmx.de on September 15, 2021, 11:13:07 AM
i hope there is anybody who can help me.
Hyperlink for your initial cross-post (https://docs.microsoft.com/en-us/answers/questions/548224/externe-daten-und-verbinder-formatieren-und-mit-2.html)
Quote from: friesstefan@gmx.de on September 15, 2021, 11:13:07 AM
External Data like this (i can chance it if is neccessary - is not settled)
You already have connectors which are assigned with External data ?
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 15, 2021, 04:23:33 PM
Hi,
thanks for help.

No i don`t have connectors.
Is it possible to add the connectors to the shape automatic? VBA?


(Yes in the other forum the recommend me to go to the most popular forum...)
Yes I`m new and my english is not perfect.

I´m not good in VBA, too.

I still have to create the Visio file, so any kind of implementation is still possible.

Unfortunately, I can't do it manually because I get this task every second day and I would need some kind of automatism.
That means I would create the shapes which should be connected manually. I hoped to get the connector and the thickness of the connector solved via VBA and the external data ... 

Best regards
Stefan
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 15, 2021, 04:27:25 PM
Shape manually
Connectors automatic
Title: Re: Visio connector
Post by: Surrogate on September 15, 2021, 04:49:07 PM
Quote from: friesstefan@gmx.de on September 15, 2021, 04:23:33 PM
my english is not perfect
I also have this problem!
You can automatcally connect shapes with connectors using GlueTo method
Quote from: wapperdude on September 03, 2021, 06:06:08 PM
Check out glueto method:  https://docs.microsoft.com/en-us/office/vba/api/visio.cell.glueto (https://docs.microsoft.com/en-us/office/vba/api/visio.cell.glueto)

There are many topics in forum wrt glueto.
but i am afraid that is so hard for newbie
Title: Re: Visio connector
Post by: wapperdude on September 15, 2021, 05:45:40 PM
QuoteI want to do this with an external Data from Excel sheet.
@Stefan:  What do you mean?  Since the shapes are already placed, are you wanting to only automate adding connectors with desired width?  Or, do you want to automate full process:  drop 2 shapes and connect them with properly sized connector?

Setting up Excel pretty easy:  1st row has column header info, then each row would have 1st shape, 2nd shape, and connector weight.  Visio names shapes as Sheet.1, sheet.2, etc. ... for all shapes.  Getting correspondence between Excel and Visio is tricky part.  You must create an identifier for each shape that would also be entered into Excel.

Setting up correspondence for existing shapes will be tedious and much work.  If starting from scratch, as shapes are added, the correspondence can be created automatically.  The tricky part is telling Visio where to place the shapes such that drawing isn't cluttered.

If you're merely adding connectors, then somehow Visio still needs to know which which shapes are paired, what Excel row corresponds to these shapes, and then add connectors.  Even if shapes are already connected correspondence needs to be established.

Here are some related links:
https://templates.office.com/en-us/basic-flowchart-from-data-tm12176896 (https://templates.office.com/en-us/basic-flowchart-from-data-tm12176896)
https://support.microsoft.com/en-us/office/create-a-data-visualizer-diagram-17211b46-d144-4ca2-9ea7-b0f48f0ae0a6 (https://support.microsoft.com/en-us/office/create-a-data-visualizer-diagram-17211b46-d144-4ca2-9ea7-b0f48f0ae0a6)
https://support.microsoft.com/en-us/office/automatically-link-imported-data-to-shapes-be56f5ff-9b13-4311-9a6c-b27dd243dbea (https://support.microsoft.com/en-us/office/automatically-link-imported-data-to-shapes-be56f5ff-9b13-4311-9a6c-b27dd243dbea)
https://www.google.com/url?q=https://m.youtube.com/watch%3Fv%3DQ6_vop2kHCg&sa=U&ved=2ahUKEwiczu6lwoHzAhUxKX0KHTIqBTkQtwJ6BAgCEAE&usg=AOvVaw1bP9DD2us7KGEA7Cx8mvJp (https://www.google.com/url?q=https://m.youtube.com/watch%3Fv%3DQ6_vop2kHCg&sa=U&ved=2ahUKEwiczu6lwoHzAhUxKX0KHTIqBTkQtwJ6BAgCEAE&usg=AOvVaw1bP9DD2us7KGEA7Cx8mvJp)



Title: Re: Visio connector
Post by: Surrogate on September 15, 2021, 06:50:09 PM
Quote from: wapperdude on September 15, 2021, 05:45:40 PM
Here are some related links:
https://templates.office.com/en-us/basic-flowchart-from-data-tm12176896 (https://templates.office.com/en-us/basic-flowchart-from-data-tm12176896)
https://support.microsoft.com/en-us/office/create-a-data-visualizer-diagram-17211b46-d144-4ca2-9ea7-b0f48f0ae0a6 (https://support.microsoft.com/en-us/office/create-a-data-visualizer-diagram-17211b46-d144-4ca2-9ea7-b0f48f0ae0a6)
https://support.microsoft.com/en-us/office/automatically-link-imported-data-to-shapes-be56f5ff-9b13-4311-9a6c-b27dd243dbea (https://support.microsoft.com/en-us/office/automatically-link-imported-data-to-shapes-be56f5ff-9b13-4311-9a6c-b27dd243dbea)
https://www.google.com/url?q=https://m.youtube.com/watch%3Fv%3DQ6_vop2kHCg&sa=U&ved=2ahUKEwiczu6lwoHzAhUxKX0KHTIqBTkQtwJ6BAgCEAE&usg=AOvVaw1bP9DD2us7KGEA7Cx8mvJp (https://www.google.com/url?q=https://m.youtube.com/watch%3Fv%3DQ6_vop2kHCg&sa=U&ved=2ahUKEwiczu6lwoHzAhUxKX0KHTIqBTkQtwJ6BAgCEAE&usg=AOvVaw1bP9DD2us7KGEA7Cx8mvJp)
@wapperdude, all these hyperlinks related with Visio Plan 2. Another Visio editions dont support these opportunities!
Title: Re: Visio connector
Post by: wapperdude on September 15, 2021, 07:15:22 PM
Thanks Surrogate, didn't catch that.

Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 15, 2021, 07:42:55 PM
Oh my God,
I suspect that the topic is overwhelming for me.
I was hoping it would be easier to solve ...

:'( :'( :'( :'( :'(
Title: Re: Visio connector
Post by: wapperdude on September 15, 2021, 11:13:23 PM
Most likely, but perhaps it can be workable.  Need more info to understand.
The 100's of shapes:
1) is this a single file?
2) are there the shapes scattered over multiple pages or just one large page?
3) are these just stock Visio shapes?
4) have any properties been added?
5) How many inputs and outputs per shape?
6) are there "stylistic" differences...shape, functional, etc?
7) are there grouped shapes?
8) what type of diagram...electrical, organization, process


Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 16, 2021, 06:08:49 AM
Hello
it's a file. The shapes are on one large side. Each shape should once show a workstation by showing the utilization of this space from 0-100%.
The connector should display the orders (thick or color) that run from one to the other workstation per year.
The orders run through our production in the most varied of value streams. Based on the graphics I would like to try to change the workplaces so that the value stream is better.
We have around 100 workstations. I wanted to pull the data from SAP and export it to Excel in order to visualize it in Visio. The connectors must be properly connected to the workstations so that when the workstations are moved, the connector is still connected to the workstations.
The number of inputs and outputs varies from 1 to 30.
I want to show the process flow with Visio.
The file doesn't exist yet, so I can't answer the other questions. I would then do this as the program allows ...
Title: Re: Visio connector
Post by: Surrogate on September 16, 2021, 06:56:02 AM
Quote from: friesstefan@gmx.de on September 16, 2021, 06:08:49 AM
The number of inputs and outputs varies from 1 to 30.
I want to show the process flow with Visio.
IMHO you must connect these outputs in your diagram manually.
Quote from: friesstefan@gmx.de on September 15, 2021, 04:27:25 PM
Connectors automatic
Because it is very complex task via code!
Title: Re: Visio connector
Post by: Surrogate on September 16, 2021, 12:19:59 PM
Quote from: friesstefan@gmx.de on September 16, 2021, 06:08:49 AMI wanted to pull the data from SAP and export it to Excel in order to visualize it in Visio.
can you share screenshoot which contain this data ?
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 16, 2021, 01:20:38 PM
it's internal company data, so I can't do screen shorts.

Workplace: utilization in%
Number of orders from workstation x to workstation Y
There is nothing more in the data.

Number of different products from workstation to workstation (connector)

Title: Re: Visio connector
Post by: wapperdude on September 16, 2021, 02:45:09 PM
Hmmm.  Let me see if I understand...
1) You've not created the file yet.  So, this is more planning / strategy phase.
2) 
QuoteThe shapes are on one large side.
By side, do you mean page?
3) Each shape (workstation) would display % utilization
4) Each shape can have multiple inputs
5) Each shape can have multiple outputs
6) Any shape can listen to / talk to any other shape
7) Connectors, using color and / or line width display amount of traffic between any two shapes.

Does that cover it?  Yikes!!!  All of that on a single page strikes me as a bowl of spaghetti.  Visually, there would be such a tangle of connectors there would be no value gained from such a drawing.  This strikes me as being like a printed circuit board layout connecting multi-pin FPGAs.  No one does that by hand.  There are (expensive) auto-routers to do that.  Way beyond Visio's capability.  It's not just about connectivity, but also about shape placement.  While Visio's connectors will keep connectivity and re-route themselves as shapes are moved, the result is not intelligent, logically controlled, and usually very messy visually.

Perhaps some order can be established thru some refined drawing concepts...
1) is there hierarchical element?  That is, are some shapes senders, some just receivers, and others that do both?  This would lend to a flow pattern, e.g., left to right, top to bottom
2) can some shapes be grouped, this would allow use of multiple pages
      > say shape A mainly talks to shapes 1 - 30, and never to some of the others?
      > shapes located in different physical areas
3)  If all shapes must be placed on single page, perhaps the connectors can be placed on layers.
     > each layer would represent a certain traffic load.  Layers can be on or off. This would minimize clutter
     > each layer represents a process/product type.

I'm sure there are other means of organizing the presentation to convey the desired info in a more readily understandable way.
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 16, 2021, 04:46:40 PM
Hi,
1) Yes, everything can still be adjusted
2) ups of course page :-[
3) yes. I would position the workstation manually at the respective position in the layout.
4) Yes
5) Yes
6) ? sorry i dont understand what you mean ??
7) yes

That`s it.
Yes is also like a spaghetti plate.
The aim should be to organize this spaghetti plate a little better.
So that, for example, a clear stream of values can be seen in one direction in the future. Especially with connectors that have a lot of jobs. In the case of value streams with fewer orders, it would be manageable. I am also familiar with such an autorouter, but it does not show the position of the workstations in the layout.
Years ago I did this manually for another area. With 5000 connectors, however, you go crazy trying to build that. Visio also has the advantage that I can visualize the current inventory between the stations.

But I can already see that I will probably have to do it manually. Was naive as I am, hoped that this would be solved with simple VBA steps.

Thanks for your assessment
Stefan


Title: Re: Visio connector
Post by: wapperdude on September 16, 2021, 05:09:10 PM
5000!!!  Ouch.

Ok.  You clearly understand the scope of this and Visio's capabikities/short comings.

Thought:  might it be possible to create a less detailed (connector-wise) drawing, and then on separate page import Excel worksheet?  Worksheet could easily be organized to show shape utilization as 1st sort priority and then connection workload as 2nd sort priority.

That has possibility of conveying all desired info, being less cluttered, and much less work.  Just a thought.

Regarding (6):  is the communication typically bi-directional or just one way for sale of diagramming purposes.  Answer not important as you already have been thru this.  If bi-directional, then connector count is minimized, and specific ports need not be shown.
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 16, 2021, 07:59:39 PM
will probably be the best.

Thanks to everyone who helped me to form an opinion here, even if it wasn't the way I actually wanted to go.

Thanks. Have a good evening
Title: Re: Visio connector
Post by: wapperdude on September 17, 2021, 02:51:24 PM
More thoughts:
1)  Does the number of workstations change from time to time...deletions, New ones added?
2)  Does the number of connectors change
3)  Presumably, the desktop / connector loading/utilization changes, how often is the drawing updated?
4)  Are non-Visio copies distributed?  How is the file used?

So a thought occurred.  Still requires manual intervention, still has potentially bowl of spaghetti, but does, ultimately, place and connect all workstations, plus configure connector loading, and finally, accommodate updating.  So, it goes like this...
1) Excel file properly configured, each row has workstation pairing info.
2) Program goes thru each row, checks if workstations on drawing are included, if not deletes it and connectors from drawing
3) Then, loops thru file again, searches for missing workstations, drops that station onto drawing, adds the connector, then pauses.
4)  User manually positions the workstation(s) on the drawing, and tells program to resume...via non-modal form???
5)  program continues until all missing workstations placed
6)  program loops one more time updating all stations/connectors to latest data...without moving anything.

I believe such is doable.  Because each loop operation is essentially separate, development may not be too bad...separate routines.

However, you then need to address the spaghetti issue.  All connections can be shown by default.  But each connector could be placed on one (and only one) of several weighting category layers.  When layer selected those connectors shown.  Could be another macro with user form, which would allow display of just the selected weighting.

Just some thoughts...
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 17, 2021, 03:47:39 PM
Hello, you describe 100% what I was thinking. But I've now learned that the effort to program this would go beyond the scope.
Unfortunately, my VBA is only so good that I can change existing codes every now and then ...
Unfortunately...
Title: Re: Visio connector
Post by: wapperdude on September 17, 2021, 03:54:11 PM
Well, necessity is the mother of invention and a great motivator.  If you're willing to invest some time, perhaps a joint adventure??? 

So, you've looked at existing code, you know the basic structure of a macro.  I presume you're familiar with the shapesheet too.  Before any coding, need to nail down some specifics wrt the concept goal...

1)  how to identify each workstation.  The most common, but not the preferred approach is changing shape name.  The better approach is to create a User defined entry in shapesheet.  Think of naming convention.  Drag your workstation shape onto blank page, open shapesheet, add User Defined section, rename the row, e.g., reName.  Whatever you'd like.  The macro will reference this row, so, not too long.  Then add name in cell, something like WK1.  Duplicate a couple more times, update the name for each shape.  In select the shapes when done.

2)  program development.  1st, let's just loop thru the shapes and disply the results.  To do this...
   > open Vba window (F11).  Tile the drawing and VVA Windows so they're side by side.
   > in the VBA window, open the This Drawing window.  It'll be blank.
   > add a sub () section, with Name...e.g., sub FindWKs()
   > inside this sub ...
           Add Dim statement declaring vsoShp as Visio.Shape.  I like to indent one tab stop.
           Skip a line. (for readability)
           Add For Next loop.   (Each shape on the page.  You can Google this.  I like using this search: Visio vba whatever.  Thus, Visio vba find shapes on page.)
           Before the "next" statement at end of loop, add the line:  debug.print vsoShape.name.  That will show
           Think that does it.  Place cursor anywhere inside the macro.  Press F8 to step thru code.


       
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 17, 2021, 07:33:27 PM
Hi there,
my little VBA knowledge is limited to very small VBA codes and that in Excel and not even in Visio. I fear it is beyond my abilities.
On the other hand, I think that drawing 5000 connectors manually is motivating enough.

I didn't understand this topic at all:
"open shapesheet, add User Defined section, rename the row, e.g., reName. Whatever you'd like. The macro will reference this row, so, not too long. Then add name in cell, something like WK1."

I just tried to start like this:

Sub FindWKs ()
Dim shp As Visio.Shapes
Dim intShapeCount as integer

intShapeCount = vsoShapes.Count
    If intShapeCount = 0 Then exit sub
'????
'Step with Macrorecorder and change code

'???
end sub

Macrorecoder (Input Connector MasterShape):
    Dim Diagram Services As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Application.Windows.ItemEx ("ME-Wertstrom3.vsdx"). Activate
    Application.ActiveWindow.Page.Drop Application.Documents.Item ("C: \ Users \ xxxxxxx.vsdx"). Masters.ItemU ("Serial connector"), 1514.89766, 1070.36222 'change

    Dim UndoScopeID1 As Long
    UndoScopeID1 = Application.BeginUndoScope ("Change object size")
    Dim vsoCell1 As Visio.Cell
    Dim vsoCell2 As Visio.Cell
    Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID (104) .CellsU ("BeginX")
    Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID (52) .CellsSRC (1, 1, 0)
    vsoCell1.GlueTo vsoCell2
    Application.EndUndoScope UndoScopeID1, True

    Dim UndoScopeID2 As Long
    UndoScopeID2 = Application.BeginUndoScope ("Change object size")
    Dim vsoCell3 As Visio.Cell
    Dim vsoCell4 As Visio.Cell
    Set vsoCell3 = Application.ActiveWindow.Page.Shapes.ItemFromID (104) .CellsU ("EndX")
    Set vsoCell4 = Application.ActiveWindow.Page.Shapes.ItemFromID (90) .CellsSRC (1, 1, 0)
    vsoCell3.GlueTo vsoCell4
    Application.EndUndoScope UndoScopeID2, True

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices


I thought that I would get a little smarter from the macro recording. However, that is not the case.
I still don't even know how to address a shape.
Inserting a connector from the master shape would work.
Actually, the next step would be to rename the connector so that it can be addressed.
The same would have to be done with the workplace, which should be included in the sheet.

I recorded a macro on each of 2 different shapes to see how the shapes are addressed differently. However, the recordings are identical, so I didn't get a step further ... :-(
Title: Re: Visio connector
Post by: Surrogate on September 17, 2021, 08:02:52 PM
Quote from: wapperdude on September 17, 2021, 03:54:11 PM
I presume you're familiar with the shapesheet too.
Absolutely right !
Quote from: friesstefan@gmx.de on September 17, 2021, 07:33:27 PM
"open shapesheet
How open ShapeSheet window (https://docs.microsoft.com/en-us/office/client-developer/visio/open-the-shapesheet-for-a-shape-page-or-document)
Quote from: friesstefan@gmx.de on September 17, 2021, 07:33:27 PMadd User Defined section
Add, Show, Hide, or Delete a Section (https://docs.microsoft.com/en-us/office/client-developer/visio/add-show-hide-or-delete-a-section)
Quote from: friesstefan@gmx.de on September 17, 2021, 07:33:27 PM
rename the row
video started at this moment (https://youtu.be/jOC5TLziBw0?t=380)
Hope this article about named connection points (https://bvisual.net/2013/05/21/getting-the-name-of-glued-connection-points/) can help with inputs/outputs...
Title: Re: Visio connector
Post by: wapperdude on September 17, 2021, 11:50:03 PM
OK.  I guess 1st question of order is, do you have a timeline for doing this?  That will help determine how to approach this in terms of the amount of hands on work needed to help you.

There are similarities between VBA for Excel and Visio.  But, the bulk revolves around the object models for both, and those are quite different.

There is a lot to attack for this project in terms of your knowledge base.  One of the 1st things is for you to become familiar with the shapesheet.  There are resources on-line, so Google.  For convenience, here's one that ought to be helpful: 

For general treatment of Visio, this is my favorite, even though it's dated:  [url=http://Docs Office XP Visio 2002 SDK Documentation Developing Microsoft Visio Solutions Developing Microsoft Visio Solutions Copyright Information]Docs Office XP Visio 2002 SDK Documentation Developing Microsoft Visio Solutions Developing Microsoft Visio Solutions Copyright Information
(https://docs.microsoft.com/en-us/office/client-developer/visio/about-the-shapesheet-spreadsheet%5B/url)

Some other good reference items:
https://docs.microsoft.com/en-us/office/client-developer/visio/reference-visio-shapesheet (https://docs.microsoft.com/en-us/office/client-developer/visio/reference-visio-shapesheet)
https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa200961(v=office.10) (https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa200961(v=office.10))

That's a lot info.  The last two links are more resource reference material.  The 1st two are meat and potatoes.

Probably, code-wise, is to feed you snippets.  Haven't had a chance to review what you just sent.  I'm hoping that as this progresses, other Visio regulars might chime in.

Cheers.
Title: Re: Visio connector
Post by: wapperdude on September 18, 2021, 01:14:27 AM
As a launching point, attached file drops two shapes, names them, and connects them.

There is a wrapper module which calls two sub-modules.  Much editing is needed: to read an Excel file, add the non-modal user interface.  But, it provides a basic structured idea.  Modular approach should facilitate editing.
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 18, 2021, 06:11:31 AM
Hi,
thanks for your support.

Thanks for the links. The first thing I will do is read through the topic "shapesheet" carefully and I hope I understand all of this.
Then I'll take a look at the file you sent me. I hope the little example gives me a little more information so that I can continue working on my topic.
Thank you for that.
If I have any questions about this, I would contact you again if I am allowed to.

Thanks for supporting an absolute beginner
Title: Re: Visio connector
Post by: wapperdude on September 18, 2021, 10:01:53 PM
Definitely post questions...that's why the forum is here,  it's key feature is the number of experienced users whom are happy to help and share.

For someone just beginning to explore Visio, it's tough to even know what to ask.  We've all been there.
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 19, 2021, 02:45:41 PM
Hello (again :-))
I watched a couple of Youtube videos and thought about my implementation again.
It currently looks like this:
I set the shapes of the workstations as well as all the necessary connectors by hand. I do this using external data and it is not a great effort.
It is also very easy to delete connectors that are no longer available using the external data.

That means I now have a drawing sheet on which everything I need is already on it.
The only thing I need is that the existing connectors must be linked to the workstations.

I've already received a small code for this.
However, I don't know exactly how to do that



Sub GlueToPos(vShp1, vShp2)
'This method allows you to glue to a specific spot on the 2D shape without
'previously adding a connection point.

    Dim connShp As Visio.Shape
    Dim BegCell1 As Visio.Cell
    Dim EndCell2 As Visio.Cell

    ActiveWindow.DeselectAll
   
'Drop connector shape
    ActiveWindow.Page.Drop Documents.Item("Drawing1").Masters.ItemU("Dynamic connector"), 0#, 0#
    Set connShp = ActiveWindow.Selection(1)
    Set BegCell1 = connShp.CellsU("BeginX")
    Set EndCell1 = connShp.CellsU("EndX")
   
'Use the GlueToPos method to glue the begin point of the 1D shape
'to the right side, mid height of 1st shape and left side, mid height of 2nd shape.
    BegCell1.GlueToPos vShp1, 1, 0.5
    EndCell1.GlueToPos vShp2, 0, 0.5

End Sub

I once created (look download) an example file of how I could imagine it. (But you can also customize it)

Now I could use a few good tips from you on how I can best go about this ...

best regards
Stefan
Title: Re: Visio connector
Post by: wapperdude on September 19, 2021, 07:26:13 PM
QuoteI set the shapes of the workstations as well as all the necessary connectors by hand. I do this using external data and it is not a great effort.
It is also very easy to delete connectors that are no longer available using the external data.

Yes.  You can do everything manually.  Tedious.  Error prone.  Lot of time

You can also do it using code.  Which I thought was the whole point, to use your external data.  The file shows how to grab 2 shapes and places them on drawing, then drops connector and glues to the shapes. 

That code looks like it's from the file I sent.  Here's what's going on.
> 1st, vShp1 and vShp2 are globally defined variables.  That makes them available for all macros.  Convenient, but there are alternative techniques.
> 2nd, the first listed sub is what I call a wrapper, it calls the subs that do the work. 
... If you left mouse click anywhere  in this macro, you can proceed line by line using <F8>.  Plus, if you tile the drawing window and VBA Windows side-by-side, as you step thru the code, you can watch what happens.  BEFORE trying it out, delete the existing shapes, and make sure that there's valid reference to the dropped shape's source.

>Lacking external data source, the next macro drops two shapes, and assigns them to globally defined variables vShp1 & vShp2, creates a User entry in the shapesheet which can be used for future referencing.  In addition, code be embellished to accommodate other pertinent external data.

>Subsequently, the wrapper calls a 3rd macro that drops a connector and glues to the two shapes.  It references the currently assigned vShp1 and vShp2.  At this point, the macro could also use connector data to set,e.g., line weight, color.

This process would be repeated for all paired workstations.  There's still much to implement.  For example, if a shape is connected to multiple shapes, the code should not drop it repeatedly.

Hope this helps.


Title: Re: Visio connector
Post by: wapperdude on September 20, 2021, 12:11:09 AM
Forgot to add macro to delete connectors that aren't fully connected.

Updated on  9/20/2021 at 01:00:26 PM

A subsequent post by Surrogate made me realize that as exists, the code deletes all 1D shapes, not just connectors.  There are two additions to needed to limit deletion to just connectors.  Both codes have been updated.


Sub delConns()
'Step thru all shapes on a page.  Filter for 1D shapes
'Delete connectors that have less than two connections
'Stepping must be backwards to preserve shape IDs established for the loop
'Edit update:  checks that 1D shapes have Master = Dynamic connector such that only connectors are deleted.

    Dim shp As Visio.Shape

    For iCnt = ActivePage.Shapes.Count To 1 Step -1         'Checks every shape on each page
        Set shp = ActivePage.Shapes(iCnt)
        If shp.OneD And (Not shp.Master Is Nothing) Then    'Look only at 1D shapes with a Master shape
            If shp.Master.Name = "Dynamic connector" Then    'Only consider 1D shapes whose Master is a Dynamic connector.
                If shp.Connects.Count < 2 Then                  'Check if connector has both ends connected.  Set equality to <= will eliminate all connecctors
                    shp.Delete
                End If
            End If
        End If
    Next
End Sub


Since this is educational as well as practical, below is modified version that only deletes fully disconnected connectors, and flags those with merely 1 end floating


Sub ckConns()
'Step thru all shapes on a page.  Filter for 1D shapes
'Delete connectors that are floating
'Flag connectors that have 1 disconnected ened
'Stepping must be backwards to preserve shape IDs established for the loop
'Edited to include if 1D shape has Dynamic connector as master, to eliminate potential 1D shapes being deleted

    Dim shp As Visio.Shape
    Dim shpIDs() As Long

    For iCnt = ActivePage.Shapes.Count To 1 Step -1         'Checks every shape on each page
        Set shp = ActivePage.Shapes(iCnt)
        If shp.OneD And (Not shp.Master Is Nothing) Then    'Look only at 1D shapes with a Master shape
            If shp.Master.Name = "Dynamic connector" Then    'Only consider 1D shapes whose Master is a Dynamic connector.
                If shp.Connects.Count = 0 Then                 'Check if connector has both ends disconnected
                    shp.Delete
                ElseIf shp.Connects.Count = 1 Then                 'Check if connector has both 1 end connected
                    shp.Cells("LineColor").Formula = "RGB(255,0,0)"
                    shp.Cells("LineWeight").Formula = "3 pt"
                End If
            End If
        End If
    Next
End Sub
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 20, 2021, 09:12:34 AM
Hi,
I'm just trying to understand how your code (wrapper) that you sent me works.
F8 step by step... as you told me.

Can you explain to me what you need the "user-defined cells" (User.dtName) for?
I see the new line in the ShapeSheet data, but I just don't know when it will be needed.

To understand the code, I added a 3rd shape.(Terminal) And change your code...


Sub GlueToPos (vShp1, vShp2)
vShape = "Terminal.35"  'I set the name of the new shape to the variable VSh2
...
BegCell1.GlueToPos vShp1, 1, 0.5
EndCell1.GlueToPos vShp2, 0, 0.5


I thought, that it would then connect the connector from PC to the terminal I added, but he didn't?

best regards
Stefan


Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 20, 2021, 09:19:45 AM
sorry
vshp2 ="Terminal.35" of course, not vShape...
Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 20, 2021, 02:09:43 PM
Hello everyone,
because of your help, I have now been able to implement my example.
I can now automatically connect all connectors to the workplace.

I also created a small example file of how it works now.

There are just a few little things left that I have to solve.
For example, I still have to specify the number of connectors that have to be linked. (external data)

However, I would need your help again very briefly.
Who knows the code which you can delete all connectors from the drawing sheet? (Even those who are already connected)

Thanks for help
Stefan

Title: Re: Visio connector
Post by: Surrogate on September 20, 2021, 02:49:55 PM
Hi, Stefan !
Quote from: friesstefan@gmx.de on September 20, 2021, 02:09:43 PM
Who knows the code which you can delete all connectors from the drawing sheet?
This code can look like this
QuoteSub DeleteAllConnectors()
Dim shp As Shape
For Each shp In ActivePage.Shapes ' iterate all shapes per active page
If (Not shp.Master Is Nothing) Then ' check is shape have parent master
If shp.Master.Name = "Connector" Then shp.Delete ' if parent shape name is "Connector" delete shape
End If
Next
End Sub
Title: Re: Visio connector
Post by: wapperdude on September 20, 2021, 03:11:55 PM
QuoteCan you explain to me what you need the "user-defined cells" (User.dtName) for?
I see the new line in the ShapeSheet data, but I just don't know when it will be needed.

This entry is where a workstation name is placed.  It is how you identify one workstation from the others.  Your Excel data file would provide the names, e.g., WS1 connected to WS97.

For example, let's say the external data file lists WS1 25 times.  That is, it connects to 25 other workstations and needs 25 Connectors.  The initial code I provided needs editing and begins to get complicated.  You don't want to have 25 copies of the WS1 workstation.  So, the code, before dropping any workstation, should search the shapes on the page to check if any shape has that name.  If so, it uses that shape, assigning it to the appropriate vShp1 or vShp2, rather than dropping a duplicate copy.  Code-wise, it requires a loop to search all of the shapes on the page, exams each for existence of indicated name by using resultstr, if found, skips dropping that shape, otherwise, drops a new shape. 

You can also create additional  User Defined entries, same technique, or, perhaps to, say, different shapesheet sections.  Perhaps to store utilization as a shape property (shape data). 

QuoteI'm just trying to understand how your code (wrapper) that you sent me works.
F8 step by step... as you told me.
The way the wrapper sub is just an ordinary macro.  Unique only in that it runs first and calls other macros in the correct order.  It could have additional statements preceding, between, or after each Call.  The Call causes the code to jump to the indicated macro, which executes and upon completion returns to whence it was called.  The code then continues with next line.  All of that should have been revealed using <F8>.

QuoteWho knows the code which you can delete all connectors from the drawing sheet? (Even those who are already connected)
You can modify the delConns macro.  After the code checks for OneD shape, there is a subsequent IF statement construct that checks for number of connections, you could merely change that to <=

Updated on  9/20/2021 at 01:00:26 PM
Alternatively, use code that Surrogate provides.  Surrogate's code made me realize that my code needed additional update such that only Dynamic connectors are deleted.  The code has been updated.  Likewise, his code needs updating too.  Because Visio re-assigns shape ID's after each deletion, his loop must be modified to start at lst shape ID and work backwards by 1, as I have shown in the delConns macro. Secondly, the Master name needs to be changed from "Connector" to read "Dynamic connector".  With updates, both codes will delete only Dynamic connectors.



Title: Re: Visio connector
Post by: friesstefan@gmx.de on September 20, 2021, 05:34:55 PM
Danke an alle Beteiligten für euren großartigen Support. ;D ;D ;D ;D ;D ;D