Author Topic: Visio connector  (Read 1934 times)

0 Members and 1 Guest are viewing this topic.

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #15 on: September 16, 2021, 11:46:40 AM »
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



wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #16 on: September 16, 2021, 12: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.
Visio 2019 Pro

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #17 on: September 16, 2021, 02: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

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #18 on: September 17, 2021, 09:51:24 AM »
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...
Visio 2019 Pro

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #19 on: September 17, 2021, 10:47:39 AM »
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...

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #20 on: September 17, 2021, 10:54:11 AM »
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.

 
       
« Last Edit: September 17, 2021, 11:34:36 AM by wapperdude »
Visio 2019 Pro

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #21 on: September 17, 2021, 02: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 ... :-(

Surrogate

  • Hero Member
  • *****
  • Posts: 1359
    • ShapeSheet™ Knowledge Base
« Last Edit: September 17, 2021, 06:28:51 PM by Surrogate »

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #23 on: September 17, 2021, 06: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


Some other good reference items:
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)

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.
« Last Edit: September 17, 2021, 11:38:06 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #24 on: September 17, 2021, 08:14:27 PM »
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.
« Last Edit: September 17, 2021, 11:33:24 PM by wapperdude »
Visio 2019 Pro

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #25 on: September 18, 2021, 01: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

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #26 on: September 18, 2021, 05: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.
Visio 2019 Pro

friesstefan@gmx.de

  • Jr. Member
  • **
  • Posts: 16
Re: Visio connector
« Reply #27 on: September 19, 2021, 09:45:41 AM »
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

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #28 on: September 19, 2021, 02:26:13 PM »
Quote
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.

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.


« Last Edit: September 19, 2021, 02:33:31 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4057
  • Ideas Visio-lized into solutions
Re: Visio connector
« Reply #29 on: September 19, 2021, 07:11:09 PM »
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.

Code
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

Code
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
« Last Edit: September 20, 2021, 01:05:06 PM by wapperdude »
Visio 2019 Pro