在Sublime Text 3安装PlantUML插件

在Sublime Text 3安装PlantUML插件

安装插件重新打开sublime时报错:unable to load diagram plugin, check console for details.

敲击快捷键alt+M时显示No diagrams overlap selections.nothing to process.

网上通常的解决办法是:修改\Sublime Text 3\Packages\plantumlpluginDiagram.sublime-settings,其中第三行将编码方式”charset”: null改为”charset”: “UTF-8”,关掉sublime Text 3重启,但是该方法并没有解决我的问题。

最简单的方法就是去查看console日志。

查看sublime的console

点击 Sublime 菜单 View -> Show Console,分析错误log。

reloading plugin plantumlplugin.diagram_plugin
plugins loaded
Viewer Setting: Preview
Loading processor class: <class 'plantumlplugin.diagram.plantuml.PlantUMLProcessor'>
Detected 'C:\\Users\\chaos\\AppData\\Roaming\\Sublime Text 3\\Packages\\plantumlplugin\\diagram\\plantuml.1.2018.1.jar'
Version Detection:
b'PlantUML version 1.2018.01 (Mon Jan 29 02:08:22 CST 2018)\r\n(GPL source distribution)\r\nJava Runtime: Java(TM) SE Runtime Environment\r\nJVM: Java HotSpot(TM) 64-Bit Server VM\r\nJava Version: 1.7.0_80-b15\r\nOperating System: Windows 7\r\nOS Version: 6.1\r\nDefault Encoding: GBK\r\nLanguage: zh\r\nCountry: CN\r\nMachine: pc-hz20096829\r\nPLANTUML_LIMIT_SIZE: 4096\r\nProcessors: 4\r\nMax Memory: 1,879,048,192\r\nTotal Memory: 126,877,696\r\nFree Memory: 123,201,280\r\nUsed Memory: 3,676,416\r\nThread Active Count: 1\r\n\r\nThe environment variable GRAPHVIZ_DOT has not been set\r\nDot executable is null\r\nError: No dot executable found\r\nError: only sequence diagrams will be generated\r\n'
PlantUML Smoke Check:
b'The environment variable GRAPHVIZ_DOT has not been set\r\nDot executable is null\r\nError: No dot executable found\r\nError: only sequence diagrams will be generated\r\n'
Unable to load processor: <class 'plantumlplugin.diagram.plantuml.PlantUMLProcessor'>
Traceback (most recent call last):
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\__init__.py", line 45, in setup
    proc.load()
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\plantuml.py", line 121, in load
    self.check_plantuml_functionality()
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\plantuml.py", line 153, in check_plantuml_functionality
    raise Exception('PlantUML does not appear functional')
Exception: PlantUML does not appear functional
error: Unable to load diagram plugin, check console for details.
Traceback (most recent call last):
  File "D:\Program Files\Sublime Text 3\sublime_plugin.py", line 283, in on_api_ready
    m.plugin_loaded()
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram_plugin.py", line 26, in plugin_loaded
    setup()
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\__init__.py", line 52, in setup
    raise Exception('No working processors found!')
Exception: No working processors found!
Unable to fetch update url contents
Processing diagrams in <sublime.View object at 0x0000000003909EB8>...
error: No diagrams overlap selections.

Nothing to process.

发现:The environment variable GRAPHVIZ_DOT has not been set

解决办法:原来安装Graphviz之后,还需要配置环境变量。

D:\Program Files (x86)\Graphviz2.38\为我的解压目录
变量名:PATH
变量值:D:\Program Files (x86)\Graphviz2.38\bin
变量名:GRAPHVIZ_DOT
变量值:D:\Program Files (x86)\Graphviz2.38\bin\dot.exe

配置之后重新运行,console日志又报错:

b'The environment variable GRAPHVIZ_DOT has been set to D:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe\r\nDot executable is D:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe\r\nDot version: dot - graphviz version 2.38.0 (20140413.2041)\r\r\nInstallation seems OK. File generation OK\r\n'
Loaded processor: <plantumlplugin.diagram.plantuml.PlantUMLProcessor object at 0x0000000003A8BEB8>
Loading viewer class from configuration: <class 'plantumlplugin.diagram.preview.PreviewViewer'>
Unable to load configured viewer, falling back to autodetection...
Traceback (most recent call last):
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\__init__.py", line 59, in setup
    vwr.load()
  File "C:\Users\chaos\AppData\Roaming\Sublime Text 3\Packages\plantumlplugin\diagram\preview.py", line 8, in load
    raise Exception("Currently only supported on MacOS")
Exception: Currently only supported on MacOS
Trying Viewer Sublime3Viewer
Loading viewer class: <class 'plantumlplugin.diagram.sublime3.Sublime3Viewer'>
Loaded viewer: <plantumlplugin.diagram.sublime3.Sublime3Viewer object at 0x0000000003A8BFD0>
Processors: [<plantumlplugin.diagram.plantuml.PlantUMLProcessor object at 0x0000000003A8BEB8>]
Viewer: <plantumlplugin.diagram.sublime3.Sublime3Viewer object at 0x0000000003A8BFD0>
Processing diagrams in <sublime.View object at 0x0000000002734080>...
error: No diagrams overlap selections.

Nothing to process.
Unable to fetch update url contents

代码\Sublime Text 3\Packages\plantumlplugin\diagram\preview.py如下:

from .base import BaseViewer
from subprocess import check_call, Popen as run_command
from sublime import platform

class PreviewViewer(BaseViewer):
    def load(self):
        if platform() not in ("osx",):
            raise Exception("Currently only supported on MacOS")
        if not check_call("which open > /dev/null", shell=True) == 0:
            raise Exception("Can't find open")

    def view(self, diagram_files):
        displaycmd = ['open', '-a', 'Preview']
        displaycmd.extend(diagram_file.name for diagram_file in diagram_files)
        run_command(displaycmd).wait()

原来下载的插件版本不正确,后续会更新windows下可用的plantuml for sublime插件下载地址。

使用jar包绘制UML图

  1. 下载plantuml.jar,地址
  2. test.txt里写plantuml代码
  3. java -jar ./plantuml.jar test.txt
  4. 图片test.png效果展示

实际上,插件也主要是依靠jar包绘图Sublime Text 3\Packages\plantumlplugin\diagram\plantuml.1.2018.1.jar
不过也许是版本的原因,插件里的jar包也不能成功绘图。

plantuml生成的图片中文注释乱码问题解决

java -Dfile.encoding=utf-8 -jar ./plantuml.jar test.txt

简单说就是默认字符集是在 java 虚拟机启动时决定的,依赖于 java 虚拟机所在的操作系统的区域以及字符集。
在java.nio.charset包中的 Charset.java 中可以看到,默认字符集就是从 file.encoding 这个属性中获取的。

参考地址:

Windows上Sublime+graphviz+PlantUML for Sublime 插件安装教程

windows下Graphviz安装及入门教程

Ubuntu上Sublime+graphviz+PlantUML for Sublime 插件安装教程

chrome+plantumlviewer,实时查看。

在线画图processon可以实现协作,并且可以根据标签推荐不同风格的模板。

几款画UML图的工具初步比较

plantuml语法:类图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值