MCPcopy
hub / github.com/CadQuery/cadquery / getSVG

Function getSVG

cadquery/occ_impl/exporters/svg.py:128–308  ·  view source on GitHub ↗

Export a shape to SVG text. :param shape: A CadQuery shape object to convert to an SVG string. :type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound. :param opts: An options dictionary that influences the SVG that is output. :type opts: Dictionary, keys are as follow

(shape, opts=None)

Source from the content-addressed store, hash-verified

126
127
128def getSVG(shape, opts=None):
129 """
130 Export a shape to SVG text.
131
132 :param shape: A CadQuery shape object to convert to an SVG string.
133 :type Shape: Vertex, Edge, Wire, Face, Shell, Solid, or Compound.
134 :param opts: An options dictionary that influences the SVG that is output.
135 :type opts: Dictionary, keys are as follows:
136 width: Width of the resulting image (None to fit based on height).
137 height: Height of the resulting image (None to fit based on width).
138 marginLeft: Inset margin from the left side of the document.
139 marginTop: Inset margin from the top side of the document.
140 projectionDir: Direction the camera will view the shape from.
141 showAxes: Whether or not to show the axes indicator, which will only be
142 visible when the projectionDir is also at the default.
143 strokeWidth: Width of the line that visible edges are drawn with.
144 strokeColor: Color of the line that visible edges are drawn with.
145 hiddenColor: Color of the line that hidden edges are drawn with.
146 showHidden: Whether or not to show hidden lines.
147 focus: If specified, creates a perspective SVG with the projector
148 at the distance specified.
149 """
150
151 # Available options and their defaults
152 d = {
153 "width": 800,
154 "height": 240,
155 "marginLeft": 200,
156 "marginTop": 20,
157 "projectionDir": (-1.75, 1.1, 5),
158 "showAxes": True,
159 "strokeWidth": -1.0, # -1 = calculated based on unitScale
160 "strokeColor": (0, 0, 0), # RGB 0-255
161 "hiddenColor": (160, 160, 160), # RGB 0-255
162 "showHidden": True,
163 "focus": None,
164 }
165
166 if opts:
167 d.update(opts)
168
169 # need to guess the scale and the coordinate center
170 uom = guessUnitOfMeasure(shape)
171
172 # Handle the case where the height or width are None
173 width = d["width"]
174 if width != None:
175 width = float(d["width"])
176 height = d["height"]
177 if d["height"] != None:
178 height = float(d["height"])
179 marginLeft = float(d["marginLeft"])
180 marginTop = float(d["marginTop"])
181 projectionDir = tuple(d["projectionDir"])
182 showAxes = bool(d["showAxes"])
183 strokeWidth = float(d["strokeWidth"])
184 strokeColor = tuple(d["strokeColor"])
185 hiddenColor = tuple(d["hiddenColor"])

Callers 3

toSvgMethod · 0.85
exportFunction · 0.85
exportSVGFunction · 0.85

Calls 6

guessUnitOfMeasureFunction · 0.85
getPathsFunction · 0.85
UpdateMethod · 0.80
appendMethod · 0.80
makeCompoundMethod · 0.80
BoundingBoxMethod · 0.45

Tested by

no test coverage detected