Scripts for importing your mindmaps from MindJet and Freemind

99 views
Skip to first unread message

Fidel N

unread,
Jun 21, 2014, 6:43:08 AM6/21/14
to leo-e...@googlegroups.com
Hi, I just made two scripts for importing from MindJet and Freemind.
I really think those two should be in the menu "File -> import ->"
Because when a new user comes to Leo, he most likely comes from any other of the most famous outliners (IE freemind or mindjet).
So it will feel very good to import their mindmaps with two clicks. I know for sure I would have loved it.

For importing your MindJet mindmap, first you have to export it to CSV, using the following options:
- Select the 'outline' layout when exporting
- Tick all the options but the 'inlcude topic properties'

Now you are ready to import your mindmap to Leo with this script. Copy it and paste it into a node, replace the path with your mindmap path, and execute the script (with the hotkey control + B):

#Your currently selected node will be replaced with the outline you are importing.
#Replace the path with the path of your file:


file_path
= 'D:/exmample/mymindmap.csv'


max_chars_in_header
= 80 #Nodes with more characters than that (or with line jumps) will be inserted as bodies instead of as header.


#INSTRUCTIONS FOR EXPORTING FROM MINDJET: You need a csv file exported from MindJet. When exporting, make sure you:
# - Use the layout "outline"
# - Tick all the options but "inlcude topic properties"




import csv


def get_row_level(row):
    count
= 0
   
while count<=len(row):
       
if row[count]:
           
return count+1
       
else:
            count
= count+1
   
return -1


def get_row_string(row):
    count
= 0
   
while count<=len(row):
       
if row[count]:
           
return row[count]
       
else:
            count
= count+1
   
return None


reader
= csv.reader(open(file_path))


initial_level
= c.p.level()
last_created_level
= c.p.level()
last_created_node
= c.p.copy()




for row in list(reader)[1:]:
    new_level
= get_row_level(row) + initial_level
    get_row_string
(row)
   
if new_level > last_created_level:
        last_created_node
= last_created_node.insertAsLastChild().copy()
        last_created_node
.b = get_row_string(row)
        last_created_level
= last_created_level+1
   
elif new_level == last_created_level:
        last_created_node
= last_created_node.insertAfter().copy()
        last_created_node
.b = get_row_string(row)
   
elif new_level < last_created_level:
           
       
for item in last_created_node.parents():
           
if item.level() == new_level-1:
                last_created_node
= item.copy()
               
break


        last_created_node
= last_created_node.insertAsLastChild().copy()
        last_created_node
.b = get_row_string(row)
        last_created_level
= last_created_node.level()
       
for p in c.p.unique_subtree():
   
if len(p.b.splitlines())==1:
       
if len(p.b.splitlines()[0])<max_chars_in_header:
            p
.h = p.b.splitlines()[0]
            p
.b = ""
       
else:
            p
.h = "@node_with_long_text"
   
else:
        p
.h = "@node_with_long_text"


c
.redraw()

If you are coming from Freemind, you just have to export your freemind mindmap into html, then use this script.
Copy and paste this script into a node, replace the path inside it with the path where you have your mindmap.html file, then run the script (hotkey control + B)


#Your currently selected node will be replaced with the outline you are importing.
#Replace the path with the path of your file:
   
file_path
= 'D:/exmample/mymindmap.mm.html'


max_chars_in_header
= 80 #Nodes with more characters than that (or with line jumps) will be inserted as bodies instead of as header.


#INSTRUCTIONS FOR EXPORTING FROM FREEMIND: Export your outline into html, then you can use this script.


import lxml.html


global outline_dict


outline_dict
= {}


global count
count
= 0


def element_to_node(parent_node, element ):
   
global count
   
global outline_dict
    count
= count+1
    my_actual_count
= int(count)


   
if len(list(element.iterchildren())):
       
# if len(list(list(element.iterchildren())[0].iterchildren())):


        outline_dict
[str(my_actual_count)] = {}
        outline_dict
[parent_node]['children'].append(str(my_actual_count))
       
if len(list(list(element.iterchildren())[0].iterchildren())):
            outline_dict
[str(my_actual_count)]['string'] = list(list(element.iterchildren())[0].iterchildren())[0].text
       
else:
            outline_dict
[str(my_actual_count)]['string'] = list(element.iterchildren())[0].text
        outline_dict
[str(my_actual_count)]['children'] = list()
       
if len(list(element.iterchildren()))>1:
           
for child in list(element.iterchildren())[1].iterchildren():
                element_to_node
(str(my_actual_count),child)


htmltree
= lxml.html.parse(file_path)


root
= htmltree.getroot()


body
= root.findall('body')[0]
outline_dict
[str(0)] = {}
outline_dict
[str(0)]['children'] = list()
outline_dict
[str(count)]['string'] = list(list(body.iterchildren())[0].iterchildren())[0].text
outline_dict
[str(count)]['children'] = list()


for item in list(list(body.iterchildren())[1].iterchildren()):
   
    element_to_node
(str(0), item )
   






#Up to here, the script was for importing into a dict. Now we export that dict into nodes:
   
def add_children_as_nodes(node_id_to_add, parent_id):


   
global outline_dict


   
for node in c.p.unique_subtree():
       
if node.h == parent_id:
            my_parent
= node.copy()
           
    newchild
= my_parent.insertAsLastChild().copy()
    newchild
.h = node_id_to_add
    newchild
.b = outline_dict[node_id_to_add]['string']
   
   
for child_id in outline_dict[node_id_to_add]['children']:
        add_children_as_nodes
(child_id, node_id_to_add)
   


c
.p.h = str(0)
c
.p.b = outline_dict['0']['string']
for child_id in outline_dict['0']['children']:
    add_children_as_nodes
(child_id, '0')


for p in c.p.unique_subtree():
   
if len(p.b.splitlines())==1:
       
if len(p.b.splitlines()[0])<max_chars_in_header:
            p
.h = p.b.splitlines()[0]
            p
.b = ""
       
else:
            p
.h = "@node_with_long_text"
   
else:
        p
.h = "@node_with_long_text"


c
.redraw()

And there you go, you just got your most loved mindmaps in Leo!

Just one thing to add, you are only importing the text /data of your mindmap, not the formats, colors, or media!

Terry Brown

unread,
Jun 21, 2014, 10:44:38 AM6/21/14
to leo-e...@googlegroups.com
On Sat, 21 Jun 2014 03:43:08 -0700 (PDT)
Fidel N <fidel...@gmail.com> wrote:

> Hi, I just made two scripts for importing from MindJet and Freemind.
> I really think those two should be in the menu "File -> import ->"
> Because when a new user comes to Leo, he most likely comes from any
> other of the most famous outliners (IE freemind or mindjet).
> So it will feel very good to import their mindmaps with two clicks. I
> know for sure I would have loved it.

https://github.com/leo-editor/leo-editor/issues/32

:)

Cheers -Terry
> list(list(element .iterchildren())[0].iterchildren())[0].text
> else:
> outline_dict[str(my_actual_count)]['string'] =
> list(element. iterchildren())[0].text
> outline_dict[str(my_actual_count)]['children'] = list()
> if len(list(element.iterchildren()))>1:
> for child in
> list(element.iterchildren())[1].iterchildren():
> element_to_node(str(my_actual_count),child)
>
>
> htmltree = lxml.html.parse(file_path)
>
>
> root = htmltree.getroot()
>
>
> body = root.findall('body')[0]
> outline_dict[str(0)] = {}
> outline_dict[str(0)]['children'] = list()
> outline_dict[str(count)]['string'] =
> list(list(body.iterchildren())[0]. iterchildren())[0].text

Fidel N

unread,
Jun 21, 2014, 11:41:24 AM6/21/14
to leo-e...@googlegroups.com
Thanks for that Terry.

Given there are no attachments in github, here are both the updated scripts (I have already translated more than 40 mindmaps with them, so found a couple of things to update) and two exported mindmaps ready for testing (the html and csv files).

Instructions remain the same.

The sources for both of the mindmaps are (Just for reference):
and


PLE_(Personal_Learning_Environment).mm.html
PLE_(Personal_Learning_Environment).mm
TED - 10 Most Popular Talks.csv
TED - 10 Most Popular Talks.mmap
freemindScript.txt
MindjetScript.txt

Fidel N

unread,
Jun 21, 2014, 1:51:02 PM6/21/14
to leo-e...@googlegroups.com
Im updating the scripts, I will upload a final version soon. 
Just saying in case someone was going to use them, better wait for tomorrow.
Now nodes with long bodies go to new nodes, and a header "@node_with_long_text".
But when the nodes are the last node in the outline, it would be great for those to become the body of the parent node. So will update that and post both scripts again.

Terry Brown

unread,
Jun 21, 2014, 3:06:38 PM6/21/14
to leo-e...@googlegroups.com
Feel free to update the scripts at
https://github.com/leo-editor/snippets/tree/master/issue_attach/32
if you can.

Cheers -Terry

Fidel N

unread,
Jun 23, 2014, 5:46:17 PM6/23/14
to leo-e...@googlegroups.com
Updated. I didn't end up going for that change, because it was a bit straightforward.
An easy correction script can be made in case the user wants to.
The idea would be to replace node bodies for the body of the child when both they only have one child and the child body was too long to be displayed in the header (meaning, that child is containing long info, and its better displayed in the header).
But sometimes the user wont want that, so I decided to leave them as they were, after updating a small thing with f.close()

Thanks for hanging them in github Terry.




--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Edward K. Ream

unread,
Jun 24, 2014, 8:26:24 AM6/24/14
to leo-editor
On Sat, Jun 21, 2014 at 5:43 AM, Fidel N <fidel...@gmail.com> wrote:
> Hi, I just made two scripts for importing from MindJet and Freemind.
> I really think those two should be in the menu "File -> import ->"

I agree completely.

I wonder whether these scripts could become official Leo commands.
There is (was??) precedent for using the clipboard: the Import MORE
outline command. Not sure what happened to that.

Your excellent instructions could become the basis for
help-for-importing-freemind/mindjet commands.

This is a great idea. Let's create some official command asap. Let
me know if I can help.

Edward

Offray Vladimir Luna Cárdenas

unread,
Jul 12, 2014, 8:24:34 PM7/12/14
to leo-e...@googlegroups.com
Fidel and Terry,

Thanks a lot! I was saving this mail because I was interested in some
kind of templating system for Leo, being able to define "@template"
nodes and using them as a way to insert new nodes with the content
(children) of the templates and using the Fildel script stored by Terry
was a source for my solution. I hope to share that custom Leo scripts
with the community before the month ends.

Cheers and thanks again,

Offray

On 06/23/2014 04:45 PM, Fidel N wrote:
> Updated. I didn't end up going for that change, because it was a bit
> straightforward.
> An easy correction script can be made in case the user wants to.
> The idea would be to replace node bodies for the body of the child when both
> they only have one child and the child body was too long to be displayed in the
> header (meaning, that child is containing long info, and its better displayed in
> the header).
> But sometimes the user wont want that, so I decided to leave them as they were,
> after updating a small thing with f.close()
>
> Thanks for hanging them in github Terry.
>
>
>
> On Sat, Jun 21, 2014 at 9:06 PM, 'Terry Brown' via leo-editor
> <leo-e...@googlegroups.com <mailto:leo-e...@googlegroups.com>> wrote:
>
> Feel free to update the scripts at
> https://github.com/leo-editor/snippets/tree/master/issue_attach/32
> if you can.
>
> Cheers -Terry
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to leo-editor+...@googlegroups.com
> <mailto:leo-editor%2Bunsu...@googlegroups.com>.
> To post to this group, send email to leo-e...@googlegroups.com
> <mailto:leo-e...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to leo-editor+...@googlegroups.com
> <mailto:leo-editor+...@googlegroups.com>.
> To post to this group, send email to leo-e...@googlegroups.com
> <mailto:leo-e...@googlegroups.com>.

Fidel N

unread,
Jul 13, 2014, 4:21:43 AM7/13/14
to leo-e...@googlegroups.com
Will be glad to see those scripts, happy that mine helped you, regards!


     <mailto:leo-editor%2Bunsu...@googlegroups.com>.

     To post to this group, send email to leo-e...@googlegroups.com
     <mailto:leo-editor@googlegroups.com>.

     Visit this group at http://groups.google.com/group/leo-editor.
     For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email

To post to this group, send email to leo-e...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscribe@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages