DMelt:Plots/Technical Drawings

From HandWiki
Jump to: navigation, search

Technical drawings

DMelt supports technical drawings using net.sf.drawj2d.Drawj2d net.sf.drawj2d.Drawj2d class. One advantage of the package is that you create images directly in the SVG file format, thus images are fully scalable.

Let us consider an example.

from jhplot import *
from net.sf.drawj2d import Drawj2d


f="drawing.hcl"
out="/home/sergei/work/dmelt/Drawj2d/drawing.svg"

s="""
# variables
set dx 50
set dy 20
# draw
moveto 20 10
label P NW
rectangle $dx $dy
pen 0.35 red
arrowrel $dx $dy
label Q SE
# dimension lines
pen black
moveto 20 42
dimlinerel $dx 0
moveto 82 10
dimlinerel 0 $dy
"""
with open(f, "w") as xfile:
    xfile.write(s)

args=["-T" "svg", "-W", "100", "-H", "60", "-o", out, f]
c=Drawj2d.Run(args)
IViewSVG(out)

This example creates a file with the commands to draw a technical image. Then we read this file, create a SVG scalable image and open this image in jhplot.IViewSVG jhplot.IViewSVG viewer. The output is:


DMelt example: Showing techical rectangle


The complete syntax of the files where drawings are defined is this manual:


<addthis />