archi-scripting-plugin
archi-scripting-plugin copied to clipboard
[feature request] Set viewBox Bounds during SVG export
Hi! Current API allows to export to SVG using $.model.renderViewToSVG(view, filePath, setViewBox)
Would it be possible to add viewBoxBounds optional parameter to enter min_x, min_y, width and height as seen in GUI?
For example:
var viewBoxBounds = {min_x: 0, min_y: 0, width: 1000, height: 495};
$.model.renderViewToSVG(view, "myView.svg", "true", viewBoxBounds);
Thanks, David
I'll look at it. It requires a change to Archi itself as well as jArchi so would have to tie in with the next Archi release.
Just FYI, for now I'm using this simple Python script to set minimum width of exported SVG files. Could be useful workaround.
from bs4 import BeautifulSoup
import os
import os.path
def setViewBox(fileName):
with open(fileName, 'r') as f:
data = f.read()
svg_xml = BeautifulSoup(data, 'xml')
svg = svg_xml.find('svg')
viewBox = svg.get('viewBox')
values = viewBox.split()
if (int(values[2]) < 1200):
svg['viewBox'] = values[0] + ' ' + values[1] + ' 1200 ' + values[3]
with open(fileName, 'w') as f:
f.write(str(svg_xml))
for dirpath, dirnames, filenames in os.walk("."):
for filename in [f for f in filenames if f.endswith(".svg")]:
setViewBox(os.path.join(dirpath, filename))
This will be implemented as part of the new API with options. You'll be able to set an option like:
var options = {setViewBox: true, viewBoxBounds: "0 0 1000 495"};
$.model.renderViewToSVG(view, "pathTo/test.svg", options);
See https://github.com/archimatetool/archi-scripting-plugin/issues/130#issuecomment-2295300342