Adding a primary topic and it becoming the selected(focused?) topic by VBA
Hi,
Using VBA, I would like that when I have selected a topic, I can then run a macro that produces topics at the same level and populates each of the new topics from an array. The original selected topic would contain the first element of the array.
I have managed to get close in that I can build sub-topics from the currently selected topic and populate them.
Here is a portion of the code:
'With MMapp.ActiveDocument
'For counter = 0 To UBound(MyArray)
'Set currentTopic = .Selection.PrimaryTopic.AllSubTopics.Add
'currentTopic.Text=MyArray(counter)
'Next counter
'End With
I then have to delete the original selected topic in order to leave the created sub-topics behind.
I am sure the problem is around this line: 'Set currentTopic = .Selection.PrimaryTopic.AllSubTopics.Add
But I cannot work it out.
Many thanks in advance for any suggestions.
I think you can do that with the databaser linker addin.
And with excel datamapper
https://youtu.be/Ho1PJv6Ih9c
I think you can do that with the databaser linker addin.
And with excel datamapper
https://youtu.be/Ho1PJv6Ih9c
Hello MichaelThere is no method for directly adding a sibling topic, so your code will need to add subtopics to the parent of the current selection. The quick and dirty way would be:
With ActiveDocument.Selection
Set currentTopic = .PrimaryTopic.ParentTopic.AllSubTopics.Add
End With
This will always add new topics at the end of the set of siblings, which may not be what you need if the selected topic is in the middle. You can use the Insert method to move a topic to a new position amongst its siblings.
As far as I know there is no property for the index of a topic in its parent collection, but it does not take long to find:Function IndexOf(ByVal m_Topic As Topic) As Integer
Dim i_1 As Integer
IndexOf = 0
If Not (m_Topic.IsCentralTopic Or m_Topic.IsFloatingTopic) Then
For i_1 = 1 To m_Topic.ParentTopic.AllSubTopics.Count
If m_Topic Is m_Topic.ParentTopic.AllSubTopics(i_1) Then
IndexOf = i_1
Exit For
End If
Next
End If
End Function
Collection indexes are all 1-based in MindManager, not 0-based. Note that the above will fail if the Central Topic is selected (as there is no parent) and will give unexpected results if a floating topic or callout topic are selected. Some extra code to protect against these situations would be good.
Hello MichaelThere is no method for directly adding a sibling topic, so your code will need to add subtopics to the parent of the current selection. The quick and dirty way would be:
With ActiveDocument.Selection
Set currentTopic = .PrimaryTopic.ParentTopic.AllSubTopics.Add
End With
This will always add new topics at the end of the set of siblings, which may not be what you need if the selected topic is in the middle. You can use the Insert method to move a topic to a new position amongst its siblings.
As far as I know there is no property for the index of a topic in its parent collection, but it does not take long to find:Function IndexOf(ByVal m_Topic As Topic) As Integer
Dim i_1 As Integer
IndexOf = 0
If Not (m_Topic.IsCentralTopic Or m_Topic.IsFloatingTopic) Then
For i_1 = 1 To m_Topic.ParentTopic.AllSubTopics.Count
If m_Topic Is m_Topic.ParentTopic.AllSubTopics(i_1) Then
IndexOf = i_1
Exit For
End If
Next
End If
End Function
Collection indexes are all 1-based in MindManager, not 0-based. Note that the above will fail if the Central Topic is selected (as there is no parent) and will give unexpected results if a floating topic or callout topic are selected. Some extra code to protect against these situations would be good.
Hi Nick, thank you for the confirmation that there is no method for directly adding a sibling topic. That answers my query and stops me from looking for a method that does not exist.
Hi Nick, thank you for the confirmation that there is no method for directly adding a sibling topic. That answers my query and stops me from looking for a method that does not exist.
---