Python使⽤Python操作xmind⽂件
使⽤Python操作xmind⽂件
by:授客 QQ:1033553122
测试环境
Win10
Python 3.5.4
XMind-1.2.
下载地址:
创建及更新xmind⽂件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import xmind
onst import TOPIC_DETACHED
arkerref import MarkerId
opic import TopicElement
# 加载已有xmind⽂件,如果不存在,则新建
workbook = xmind.load('D:\\example\\ind')
first_sheet = PrimarySheet() # 获取第⼀个画布
first_sheet.setTitle('First Sheet') # 设置画布名称
root_topic1 = RootTopic() # 获取画布中⼼主题,默认创建画布时会新建⼀个空⽩中⼼主题
root_topic1.setTitle('Example Topic') # 设置主题名称
sub_topic1 = root_topic1.addSubTopic() # 创建⼦主题,并设置名称
css3动画无缝衔接
sub_topic1.setTitle("first sub topic")
sub_topic2 = root_topic1.addSubTopic()
sub_topic2.setTitle("second sub topic")
sub_topic3 = root_topic1.addSubTopic()
sub_topic3.setTitle("third sub topic")
# 除了新建⼦主题,还可以创建⾃由主题(注意:只有中⼼主题⽀持创建⾃由主题)
detached_topic1 = root_topic1.addSubTopic(topics_type=TOPIC_DETACHED) detached_topic1.setTitle("detached topic")
detached_topic1.setPosition(0, 30)
# 创建⼀个⼦主题的⼦主题
sub_topic1_1 = sub_topic1.addSubTopic()
sub_topic1_1.setTitle("I'm a sub topic too")
url代码大全second_sheet = ateSheet() # 创建新画布
second_sheet.setTitle('Second Sheet')
root_topic2 = RootTopic()
root_topic2.setTitle('Root Node')
# 使⽤其它⽅式创建⼦主题元素
topic1 = TopicElement(ownerWorkbook=workbook)
topic1.setTopicHyperlink(ID()) # 为画布创建⼀个来⾃第⼀个画布的主题链接topic1.setTitle("redirection to the first sheet")
topic2 = TopicElement(ownerWorkbook=workbook)
topic2.setTitle("topic with an url hyperlink")
topic2.setURLHyperlink("wwwblogs/shouke") # 为⼦主题元素设置URL超链接
topic3 = TopicElement(ownerWorkbook=workbook)
topic3.setTitle("third node")
topic3.setPlainNotes("notes for this topic") # 为⼦主题设置备注 (F4 in XMind)
topic3.setTitle("topic with \n notes")
topic4 = TopicElement(ownerWorkbook=workbook)
topic4.setFileHyperlink("d:\\example\demo.jpg") # 为⼦主题元素设置⽂件超链接
topic4.setTitle("topic with a file")
topic1_1 = TopicElement(ownerWorkbook=workbook)
topic1_1.setTitle("sub topic")
springfestival作文40个单词topic1_1.addLabel("a label") # 为⼦主题添加标签(official XMind only can a one label )# 添加⼦主题到⾮中⼼主题
topic1.addSubTopic(topic1_1)
topic1_1_1 = TopicElement(ownerWorkbook=workbook)
topic1_1_1.setTitle("topic can add multiple markers")
# 为主题添加标记
topic1_1_1.addMarker(MarkerId.starBlue)
topic1_1_1.addMarker(MarkerId.flagGreen)
# 为⼦主题添加⼦主题
topic1_1.addSubTopic(topic1_1_1)
topic2_1 = TopicElement(ownerWorkbook=workbook)
topic2_1.setTitle("topic can add multiple comments")
# 为主题添加评论
topic2_1.addComment("I'm a comment!")
topic2_1.addComment(content="Hello comment!", author='devin')
topic2.addSubTopic(topic2_1)
# 添加⼦主题元素到中⼼主题
root_topic2.addSubTopic(topic1)
root_topic2.addSubTopic(topic2)
root_topic2.addSubTopic(topic3)
root_topic2.addSubTopic(topic4)
# 遍历⼦主题
topics = SubTopics()
for index, topic in enumerate(topics):
topic.addMarker("priority-" + str(index + 1)) # 为主题添加标记(优先级图标)
# 为⼦主题1和⼦主题2创建关系
ID(), ID(), "relationship test")
# xmind.save(workbook) # 保存并覆盖原始⽂件
# 仅保存l
# xmind.save(workbook=workbook, path="d:\\example\\ind", only_content=True) # 不改动原始⽂件,另存为其它xmind⽂件
# 仅保存l、l、l
# xmind.save(workbook=workbook, path="d:\\example\\ind", except_revisions=True) # 不改动原始⽂件,另存为其它xmind⽂件
# 保存所有东西,Revisions除外,以节省空间(推荐)
# xmind.save(workbook=workbook, path="d:\\example\\ind", except_revisions=True) # 不改动原始⽂件,另存为其它xmind⽂件
# 保存所有内容,并且另存为其它xmind⽂件(推荐)
xmind.save(workbook=workbook, path='d:\\example\\ind') # 不改动原始⽂件,另存为其它xmind⽂件,等同 xmind.save(workbook, 'd:\\example\\ind')
运⾏结果
解析xmind⽂件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json
import xmind
import pipes
def dict_to_prettify_json(data):
print(json.dumps(data, indent=4, separators=(',', ': ')))
def custom_parse_xmind(workbook):
elements = {}
def _echo(tag, element, indent=0):
title = Title()
ID()] = title
print('\t' * indent, tag, ':', pipes.quote(title))
def dump_sheet(sheet):
root_topic = RootTopic()
_echo('RootTopic', root_topic, 1)
for topic in SubTopics() or []:
_echo('AttachedSubTopic', topic, 2)
狮驼岭克制哪个门派for topic in onst.TOPIC_DETACHED) or []: _echo('DetachedSubtopic', topic, 2)
for rel Relationships():
id1, id2 = End1ID(), End2ID()
print('Relationship: [%s] --> [%s]' % ((id1), (id2)))
# 遍历画布
for sheet Sheets():
_echo('Sheet', sheet)
dump_sheet(sheet)
# 加载已有xmind⽂件,如果不存在,则新建
workbook = xmind.load('D:\\example\\ind')
Data()) # 获取整个xmind数据(字典的形式)
dict_to_prettify_Data())
ppt模板下载免费版优美
# 获取某个画布的数据(字典的形式)
first_sheet = PrimarySheet()
dict_to_prettify_json(Data())
python解析json文件# 获取某个主题数据(字典的形式)
root_topic = RootTopic()
dict_to_prettify_json(Data())
# 获取评论数据
commentsbook = workbookmentsbook
Data())
# ⾃定义解析
custom_parse_xmind(workbook)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论