[VBA, FOSS] SelectAllSubtopics

charles c. shared this idea 14 days ago
Voting Open

'#Language "WWB-COM"

Option Explicit

Sub Main
Dim SelectedTopic As Topic
Dim SelectedObject As DocumentObject

' Check if a single object is selected
If ActiveDocument.Selection.Count = 1 Then
' Get the selected object
Set SelectedObject = ActiveDocument.Selection(1)

' Check if the selected object is a topic
If SelectedObject.Type = 1 Then
' Cast the selected object to a Topic
Set SelectedTopic = SelectedObject

' Clear the current selection
' ActiveDocument.Selection.RemoveAll

' Select all subtopics recursively
SelectAllSubtopics SelectedTopic
Else
MsgBox "Please select a single topic to select its subtopics."
End If
Else
MsgBox "Please select a single topic to select its subtopics."
End If
End Sub

Sub SelectAllSubtopics(ByVal ParentTopic As Topic)
Dim SubTopic As Topic

' Iterate through the subtopics
For Each SubTopic In ParentTopic.SubTopics
' Add the subtopic to the selection
ActiveDocument.Selection.Add SubTopic

' Recursively call this function for the subtopic
SelectAllSubtopics SubTopic
Next SubTopic
End Sub

Replies (2)

photo
1

This script is a macro written in WinWrap Basic for MindManager, a mind mapping and project management software. The script selects all the subtopics of a single selected topic in the active MindManager document, including nested subtopics. Here's a breakdown of the script:

1. Declare variables:
- `SelectedTopic` will hold the Topic object of the single selected topic in the document.
- `SelectedObject` will hold the selected DocumentObject.

2. Check if a single object is selected in `ActiveDocument.Selection`. If so, proceed to step 3, otherwise show a message box instructing the user to select a single topic.

3. Get the selected object in `ActiveDocument.Selection(1)` and check if it's a topic by examining its `Type`. If it's a topic (Type = 1), proceed to step 4, otherwise show a message box instructing the user to select a single topic.

4. Cast the selected object to a Topic, and call the `SelectAllSubtopics` function with the selected topic as an argument.

5. The `SelectAllSubtopics` function:
- This is a recursive function that takes a `ParentTopic` as an input and selects all of its subtopics, including nested subtopics.
- Iterate through each subtopic of the `ParentTopic`.
- Add the subtopic to the document's selection using `ActiveDocument.Selection.Add`.
- Recursively call the `SelectAllSubtopics` function for each subtopic, allowing the script to select subtopics at all levels of nesting.

In summary, this script selects all subtopics, including nested subtopics, of a single selected topic in the active MindManager document.

photo
1

I am thinking to make it go thru official routines,

and become official macros/addons,

provide additional features and support as commercial versions.

Leave a Comment
 
Attach a file