Nov 04 2022 04:10 AM - edited Nov 04 2022 04:12 AM
I have made some Shapes on a WorkSheet - like this:
I want to switch the arrows so they are NOT crossing each other and it should be the right (the head) end of the arrows that should be switched.
Let's say the shapes have these names:
"1" for the blue person
"6" for the pink person
"1+6" for the green couple
"1->1+6" for the climbing arrow
"6->1+6" for the descending arrow
I have tried some code like this but with no luck:
Public Sub bytPileTilPAR(f1 As String, f2 As String)
Dim namePIL As String
' trying to guess the name of the couple
If ActiveSheet.Shapes.Item(f1 & "+" & f2).Name = f1 & "+" & f2 Then
' then the name of the arrows - one by one
namePIL = f1 & "->" & f1 & "+" & f2
ActiveSheet.Shapes(f1).Connector.ConnectorFormat.BeginConnect ActiveSheet.Shapes(f1), 1
ActiveSheet.Shapes(f1).Connector.ConnectorFormat.EndConnect ActiveSheet.Shapes(namePIL), 5
Else
some code if the couple-name was wrong
End If
End Sub
I focus on the TRUE part of the IF-THEN in the first place - I think I can manage to do the other part when the TRUE-part is working right.
How can the arrows be switched around ?
Nov 05 2022 01:25 AM
Nov 05 2022 06:04 AM
It is a few years since I have controlled shapes using VBA. One of the tricks I remember using was to generate the diagram by hand and then limit the code to toggling the visibility of alternative shapes to create dynamic shape diagrams. Since I was drawing the shapes by hand, I needed to read the connection port numbers but not to change the linkage. Drawing with freeform connection objects was fun though.
Nov 05 2022 06:10 AM
Nov 05 2022 06:45 AM
That gets 'interesting' quite quickly. What is your data structure to hold the family tree? Assuming the diagram covers the entire tree, as opposed to navigating a restricted view, you have two persistent (still there after switching the application off and on again) representations of the tree (data and diagram). Which is the master? It is possible to require the diagram to update when you change the data held within linked tables or to change the data when you add elements to the diagram. Or you could accept both and use VBA Class modules (a transient representation) and events to synchronise the other whenever either representation is changed.
Nov 05 2022 07:08 AM
Nov 05 2022 07:52 AM
If you restrict the view too much, one loses the sense of location as one navigates the tree. On the other hand, include too many generations and diagram layout issues become a nightmare! You mention the QAT. One thing I found useful was the shape's 'on action' event handling which would allow you to click a person icon with the implied question of "tell me more about ...".
Nov 05 2022 11:38 PM
Nov 06 2022 02:06 AM
SolutionI had wondered whether to send you a copy of a program I wrote years ago (2014) to analyse diagrams and plot fragments of the graph dynamically. The problem is that it would take me a week to remember and get to grips with the techniques I used, so I am not sure how you would fare.
It uses Class modules for the Graph object itself and for the GraphNode and GraphEdge collections that comprise it. In your case, that might mean having a Class 'FamilyTree' with methods to Add people as instances of the Person class. Each oPerson ('o' for Object) might have properties such as '.Name', '.DOB' and relationships such as .Parent, .Partner, .EldestChild or .Sibling that have other objects from the Person Class as their values.
If that isn't bad enough, I also adopted someone else's central error checking code, so every module starts with standard set of module name identifiers and initialises the error variable to show an error unless the module subsequently reaches the 'success' setting.
It is odd how one's own past work can lie so far outside one's comfort zone!
Nov 06 2022 06:02 AM
Nov 06 2022 02:06 AM
SolutionI had wondered whether to send you a copy of a program I wrote years ago (2014) to analyse diagrams and plot fragments of the graph dynamically. The problem is that it would take me a week to remember and get to grips with the techniques I used, so I am not sure how you would fare.
It uses Class modules for the Graph object itself and for the GraphNode and GraphEdge collections that comprise it. In your case, that might mean having a Class 'FamilyTree' with methods to Add people as instances of the Person class. Each oPerson ('o' for Object) might have properties such as '.Name', '.DOB' and relationships such as .Parent, .Partner, .EldestChild or .Sibling that have other objects from the Person Class as their values.
If that isn't bad enough, I also adopted someone else's central error checking code, so every module starts with standard set of module name identifiers and initialises the error variable to show an error unless the module subsequently reaches the 'success' setting.
It is odd how one's own past work can lie so far outside one's comfort zone!