archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

[feature request] Set viewBox Bounds during SVG export #99

Open davidsara opened 2 years ago

davidsara commented 2 years ago

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?

image

For example:

var viewBoxBounds = {min_x: 0, min_y: 0, width: 1000, height: 495};
$.model.renderViewToSVG(view, "myView.svg", "true", viewBoxBounds);

Thanks, David

Phillipus commented 2 years ago

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.

davidsara commented 1 year ago

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))