亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 python 腳本創建多個 PlantUML 圖?

如何從 python 腳本創建多個 PlantUML 圖?

米琪卡哇伊 2023-03-16 09:29:04
設想大多數說明建議您可以使用 python 生成 PlantUML 圖python -m plantuml example_diagram.txt:我想創建一個 python 腳本,它在創建時生成多個 PlantUML 圖,這樣我就可以立即更新一組完整的圖,而無需運行多個命令。示例文件以下文件用于生成 PlantUML 圖:example_flow.txt內容:' http://tonyballantyne.com/graphs.html#orgheadline19' http://graphviz.org/doc/info/shapes.html' Indicate the direction of the flowchartleft to right direction' Give a block the variable name 'first' and define starting point as (*)(*) --> "The first block" as firstfirst --> "A" as A' Give the block a variable name s.t. you can just use its variable name in the next blocks  --> "D" as Dfirst --> "B" as B  --> Dfirst --> "C" as C  --> D  ' Define end point as (*)  D --> (*)Graphviz_example.txt內容:' http://tonyballantyne.com/graphs.html#orgheadline19' http://graphviz.org/doc/info/shapes.htmldigraph summary{    // initialize the variable blocks    start [label="Start with a Node"]    next [label="Choose your shape", shape=box]    warning [label="Don't go overboard", color=Blue, fontcolor=Red,fontsize=24,style=filled, fillcolor=green,shape=octagon]    end [label="Draw your graph!", shape=box, style=filled, fillcolor=yellow]    // Indicate the direction of the flowchart    rankdir=LR; // Rank direction left to right        // Create the connections    start->next    start->warning     next->end [label="Getting Better...", fontcolor=darkblue]}問題如何從單個 python 腳本創建這些圖表?
查看完整描述

1 回答

?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

為同一目錄下的2個文件生成

創建一個以內容命名的 python 文件create_diagrams.py:


from plantuml import PlantUML

from os.path import abspath


# create a server object to call for your computations

server = PlantUML(url='http://www.plantuml.com/plantuml/img/',

                          basic_auth={},

                          form_auth={}, http_opts={}, request_opts={})


# Send and compile your diagram files to/with the PlantUML server

server.processes_file(abspath('./example_flow.txt'))

server.processes_file(abspath('./Graphviz_example.txt'))

并運行它,例如在帶有 python 3.6 的 anaconda 中使用命令:python create_diagrams.py。


為目錄中的所有文件生成

還可以為.txt目錄中的所有文件生成圖表Diagrams:


from plantuml import PlantUML

import os

from os.path import abspath


server = PlantUML(url='http://www.plantuml.com/plantuml/img/',

                          basic_auth={},

                          form_auth={}, http_opts={}, request_opts={})



# create subfolder name

diagram_dir = "./Diagrams"


# loop through all .txt files in the subfolder

for file in os.listdir(diagram_dir):

  filename = os.fsdecode(file)

  if filename.endswith(".txt"):

    # Call the PlantUML server on the .txt file

    server.processes_file(abspath(f'./Diagrams/{filename}'))

筆記

此實現需要有效的互聯網連接,因為您要求 PlantUML 服務器為您生成圖形。要在本地編譯,您還可以下載.jarPlantUML 軟件的文件并從 python 調用它來進行計算。這篇文章的問題中給出了一個更詳細的例子。


查看完整回答
反對 回復 2023-03-16
  • 1 回答
  • 0 關注
  • 84 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號