‘’’
Author: zzx
Date: 2022-07-30 15:52:15
LastEditors: zdl
LastEditTime: 2022-07-30 16:03:20
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\markdown写杂谈\python导出drawio文件
Description:

Copyright © 2022 by zdl, All Rights Reserved.
‘’’

vscode一体化导出drawio

需要的工具:vscode, draw.io扩展,draw.io桌面版 、python

提示:这个方法并没有简化流程,只是能够减少打开窗口,在vscode中直接查看原始文件,导出文件,效率并没有显著提升。

啰嗦的部分:
drawio流程图绘制软件比visio好用。而且vscode有插件。vs插件的优点在于支持mermaid流程图,缺点非常明显不支持指定分辨率图像导出。
网上检索发现drawio的桌面版可以在命令行操作。在drawio安装目录下运行cmd,然后通过draw.io -help 命令可以查看全部命令。
查看命令发现没有针对性的dpi设置。我就想到给图片输入宽度和高度的方式。根据我猜测这个宽度和高度应该对应的就是像素点数量,所以我就按照实际尺寸,以及dpi的定义
写了一个命令, 发现可用。但是每次都要计算宽度、高度、调用cmd命令窗口,太麻烦。功能强大的python加上插件齐全的vscode能不能全部实现呢?
折腾了几个小时,终于搞定了。

进入正题:
1、安装draw.io插件,和桌面版,记住桌面版的路径
2、绘制好的图片有一个实际的尺寸,记住实际尺寸的宽和高
3、python转换 宽度

dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)

4、 构造命令行,不嫌麻烦可以自己写完整目录

inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\算法流程图.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath

5、 改变python文件工作目录并执行命令

path="D:/draw.io/"#安装文件夹
os.chdir( path )# 修改当前工作目录
v2=os.system(commandtext1)

完整的代码

代码量并不大,非常简单

'''
Author: zzx
Date: 2022-07-27 10:12:38
LastEditors: zdl
LastEditTime: 2022-07-30 16:10:22
FilePath: \matlabcodef:\BaiduNetdiskWorkspace\00typora\大论文\drawio\output.py
Description: Copyright (c) 2022 by zdl, All Rights Reserved.
'''
import os
dpivalue=600#dpi
realwidth=89.4#mm
realheight=81.2#mm
width=round(dpivalue*realwidth/25.4)
height=round(dpivalue*realheight/25.4)
inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\算法流程图.drawio'
outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大论文\drawio\test.png'
starttext=r'draw.io -x '
midletext=r" -f png -t --width "+str(width)+r" --height " +str(height)+r" -o "
commandtext1=starttext+inputfilepath+midletext+outputfilepath
path="D:/draw.io/"#安装文件夹
os.chdir( path )# 修改当前工作目录
v2=os.system(commandtext1)# 快速运行F5
# print(v2)#关于python权限的问题
# https://blog.csdn.net/qq_33731081/article/details/103812749
# 如何在python中运行命令行命令
# https://blog.csdn.net/qq_34769162/article/details/119037908
#报错为空值的问题
# https://blog.csdn.net/xiaoxiaogh/article/details/88320102#关于drawio导出命令,灵感来源https://j2r2b.github.io/2019/08/06/drawio-cli.html
'''
Options:-V, --version                      output the version number-c, --create                       creates a new empty file if no file ispassed-k, --check                        does not overwrite existing files-x, --export                       export the input file/folder based on thegiven options-r, --recursive                    for a folder input, recursively convertall files in sub-folders also-o, --output <output file/folder>  specify the output file/folder. Ifomitted, the input file name is used foroutput with the specified format asextension-f, --format <format>              if output file name extension isspecified, this option is ignored (filetype is determined from output extension,possible export formats are pdf, png, jpg,svg, vsdx, and xml) (default: "pdf")-q, --quality <quality>            output image quality for JPEG (default:90)-t, --transparent                  set transparent background for PNG-e, --embed-diagram                includes a copy of the diagram (for PNG,SVG and PDF formats only)--embed-svg-images                 Embed Images in SVG file (for SVG formatonly)-b, --border <border>              sets the border width around the diagram(default: 0)-s, --scale <scale>                scales the diagram size--width <width>                    fits the generated image/pdf into thespecified width, preserves aspect ratio.--height <height>                  fits the generated image/pdf into thespecified height, preserves aspect ratio.--crop                             crops PDF to diagram size-a, --all-pages                    export all pages (for PDF format only)-p, --page-index <pageIndex>       selects a specific page, if not specifiedand the format is an image, the first pageis selected-g, --page-range <from>..<to>      selects a page range (for PDF format only)-u, --uncompressed                 Uncompressed XML output (for XML formatonly)--enable-plugins                   Enable Plugins-h, --help                         display help for command
'''

draw.io插件在vscode中一体化导出高质量图片相关推荐

  1. 【有效】vscode中markdown导出pdf报错解决: ERROR: Navigation Timeout Exceeded: 30000 ms exceeded

    在vscode对markdown文档进行导出pdf时(使用的Markdown PDF1.4.4版本插件),vscode界面弹出报错: ERROR: Navigation Timeout Exceede ...

  2. 值得收藏!VScode 中这 15 个神仙插件写代码必备!

    Visual Studio Code 是一款轻量级但功能强大的源代码编辑器,适用于 Windows.macOS 和 Linux.内置了对 JavaScript.TypeScript 和 Node.js ...

  3. VScode中的神仙插件(写代码必备)

    目录 一.概述 二.使用教程 1.搜索扩展 2.列出已安装的扩展 3.卸载扩展 4.禁用扩展 5.启用扩展 6.更新扩展 三.扩展介绍 1.Python 2.Jupyter 3.C/C++ 4.ESL ...

  4. 绘图神器draw.io(写文必备)

    绘图神器draw.io(写文必备) 作者:毛小悠. 写文时间:2020年10月22日 -- 学习,为了看到更大的世界. 前言 大家早上好,我是毛小悠,一个前端开发工程师. 最近发现一个绘图神器,没错, ...

  5. visio的替代工具 - draw.io

    draw.io 简介 它是一个 web 端的流程图绘制工具,不需要进行安装,只需要打开它的网站 http://draw.io 就可以了.而且界面简洁清晰,最重要的是免费的,visio 不是免费的.还有 ...

  6. 在VS Code上使用draw.io绘制UML图、架构图、原型图、网络拓扑图、组织结构图等,PeocessOn再见

    简介 流程图和UML图估计是程序员偶尔需要的东西,又是话画一个流程图可以理清程序逻辑,之前用windows自带的画图来画流程图,对齐和再次编辑不太好处理,后来室友推荐了processon Proces ...

  7. draw.io绘图工具

    draw.io 绘图工具 文章目录 draw.io 绘图工具 1 庞大且付费的visio工具 2 draw.io 1 庞大且付费的visio工具 这又是一篇工具安利文.好用的东西要推广给更多的人知道. ...

  8. lldb 调试php,linux系统下如何在vscode中调试C++代码

    本篇博客以一个简单的hello world程序,介绍在vscode中调试C++代码的配置过程. 1. 安装编译器 vscode是一个轻量的代码编辑器,并不具备代码编译功能,代码编译需要交给编译器完成. ...

  9. 下载安装Go SDK、命令运行及在Vscode中运行第一个HelloWorld

    文章目录 下载安装Go SDK.命令运行及在Vscode中运行第一个HelloWorld 1.下载Go SDK 2.安装Go SDK 3.go version验证成功 4.go env查看配置信息 5 ...

最新文章

  1. .NET应用三层架构分析
  2. 再见Navicat!这个工具才是YYDS!
  3. 好看的php验证码,一漂亮的PHP图片验证码实例
  4. LINQ to SQL之Step by Step及新手问题小结
  5. ASP.NET2.0_缓存
  6. 固阳一中2021高考成绩查询,中考志愿填报网站
  7. Less颜色混合函数(14)
  8. 计算机科学对社会发展的作用,科学技术在计算机领域对社会发展的作用及影响...
  9. 启用了被称为 HTTP 严格传输安全(HSTS)的安全策略,Firefox 只能与其建立安全连接
  10. uniapp switch按钮的使用开关按钮效果demo(整理)
  11. 双目相机标定Matlab
  12. IN适合于外表大而内表小的情况;EXISTS适合于外表小而内表大的情况。
  13. 广告SDK平台中的CPA、CPS、CPM、CPT、CPC 是什么
  14. 1098:质因数分解(信奥)
  15. Ubuntu mate自启脚本/命令+关闭图形桌面
  16. RMAN的备份与恢复
  17. 《安富莱嵌入式周报》第227期:2021.08.23--2021.08.29
  18. 从一款已上线的MMO手游分析游戏地图的同步方案
  19. 禾赛科技“梦碎”科创板:营收递增、由盈转亏,在专利官司中败退
  20. 流浪的python博客园_python学习心得第二章

热门文章

  1. Jupyter 快捷键 (2)
  2. MacBook Pro 休眠后五国,自动重启报错
  3. java魔方大作业_JAVA实现的魔方
  4. MPEG2相关原理概述
  5. 5G核心网标准化进展及B5G演进初探
  6. i9级E52450处理器_给你的电脑私装蓝牙WIFI?华硕皇帝级主板增加WIFI模块上I9处理器...
  7. 超详解六西格玛管理法与案例分享|优思学院
  8. 捷足先登学用CSS:HTML结构化
  9. 输入框限制只能输入正数
  10. 从零开始学习Linux运维,成为IT领域翘楚(八)