如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片_第1頁
如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片_第2頁
如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片_第3頁
如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片_第4頁
如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第如何使用draw.io插件在vscode中一體化導(dǎo)出高質(zhì)量圖片Author:zzx

Date:2025-07-3015:52:15

LastEditors:zdl

LastEditTime:2025-07-3016:03:20

FilePath:\matlabcodef:\BaiduNetdiskWorkspace\markdown寫雜談\python導(dǎo)出drawio文件

Description:

Copyright2025byzdl,AllRightsReserved.

vscode一體化導(dǎo)出drawio

需要的工具:vscode,draw.io擴(kuò)展,draw.io桌面版、python

提示:這個(gè)方法并沒有簡化流程,只是能夠減少打開窗口,在vscode中直接查看原始文件,導(dǎo)出文件,效率并沒有顯著提升。

啰嗦的部分:

drawio流程圖繪制軟件比visio好用。而且vscode有插件。vs插件的優(yōu)點(diǎn)在于支持mermaid流程圖,缺點(diǎn)非常明顯不支持指定分辨率圖像導(dǎo)出。

網(wǎng)上檢索發(fā)現(xiàn)drawio的桌面版可以在命令行操作。在drawio安裝目錄下運(yùn)行cmd,然后通過draw.io-help命令可以查看全部命令。

查看命令發(fā)現(xiàn)沒有針對(duì)性的dpi設(shè)置。我就想到給圖片輸入寬度和高度的方式。根據(jù)我猜測(cè)這個(gè)寬度和高度應(yīng)該對(duì)應(yīng)的就是像素點(diǎn)數(shù)量,所以我就按照實(shí)際尺寸,以及dpi的定義

寫了一個(gè)命令,發(fā)現(xiàn)可用。但是每次都要計(jì)算寬度、高度、調(diào)用cmd命令窗口,太麻煩。功能強(qiáng)大的python加上插件齊全的vscode能不能全部實(shí)現(xiàn)呢?

折騰了幾個(gè)小時(shí),終于搞定了。

進(jìn)入正題:

1、安裝draw.io插件,和桌面版,記住桌面版的路徑

2、繪制好的圖片有一個(gè)實(shí)際的尺寸,記住實(shí)際尺寸的寬和高

3、python轉(zhuǎn)換寬度

dpivalue=600#dpi

realwidth=89.4#mm

realheight=81.2#mm

width=round(dpivalue*realwidth/25.4)

height=round(dpivalue*realheight/25.4)

4、構(gòu)造命令行,不嫌麻煩可以自己寫完整目錄

inputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\算法流程圖.drawio'

outputfilepath=r'F:\BaiduNetdiskWorkspace\00typora\大論文\drawio\test.png'

starttext=r'draw.io-x'

midletext=r"-fpng-t--width"+str(width)+r"--height"+str(height)+r"-o"

commandtext1=starttext+inputfilepath+midletext+outputfilepath

5、改變python文件工作目錄并執(zhí)行命令

path="D:/draw.io/"#安裝文件夾

os.chdir(path)#修改當(dāng)前工作目錄

v2=os.system(commandtext1)

完整的代碼

代碼量并不大,非常簡單

'''

Author:zzx

Date:2025-07-2710:12:38

LastEditors:zdl

LastEditTime:2025-07-3016:10:22

FilePath:\matlabcodef:\BaiduNetdiskWorkspace\00typora\大論文\drawio\output.py

Description:

Copyright(c)2025byzdl,AllRightsReserved.

importos

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"-fpng-t--width"+str(width)+r"--height"+str(height)+r"-o"

commandtext1=starttext+inputfilepath+midletext+outputfilepath

path="D:/draw.io/"#安裝文件夾

os.chdir(path)#修改當(dāng)前工作目錄

v2=os.system(commandtext1)

#快速運(yùn)行F5

#print(v2)

#關(guān)于python權(quán)限的問題

#/qq_33731081/article/details/103812749

#如何在python中運(yùn)行命令行命令

#/qq_34769162/article/details/119037908

#報(bào)錯(cuò)為空值的問題

#/xiaoxiaogh/article/details/88320102

#關(guān)于drawio導(dǎo)出命令,靈感來源https://j2r2b.github.io/2025/08/06/drawio-cli.html

Options:

-V,--versionoutputtheversionnumber

-c,--createcreatesanewemptyfileifnofileis

passed

-k,--checkdoesnotoverwriteexistingfiles

-x,--exportexporttheinputfile/folderbasedonthe

givenoptions

-r,--recursiveforafolderinput,recursivelyconvert

allfilesinsub-foldersalso

-o,--outputoutputfile/folderspecifytheoutputfile/folder.If

omitted,theinputfilenameisusedfor

outputwiththespecifiedformatas

extension

-f,--formatformatifoutputfilenameextensionis

specified,thisoptionisignored(file

typeisdeterminedfromoutputextension,

possibleexportformatsarepdf,png,jpg,

svg,vsdx,andxml)(default:"pdf")

-q,--qualityqualityoutputimagequalityforJPEG(default:

-t,--transparentsettransparentbackgroundforPNG

-e,--embed-diagramincludesacopyofthediagram(forPNG,

SVGandPDFformatsonly)

--embed-svg-imagesEmbedImagesinSVGfile(forSVGformat

only)

-b,--borderbordersetstheborderwidtharoundthediagram

(default:0)

-s,--scalescalescalesthediagramsize

--widthwidthfitsthegeneratedimage/pdfintothe

specifiedwidth,preservesaspectratio.

--heightheightfitsthegeneratedimage/pdfintothe

specifiedheight,preservesaspectratio.

--cropcropsPDFtodiagramsize

-a,--allsexportallpages(forPDFformatonly)

-p,indexpageIndexselectsaspecificpage,ifnotspecified

andtheformatisanimage,thefirstpage

isselected

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論