MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / plot

Function plot

src/ifcquery/ifcquery/plot.py:148–284  ·  view source on GitHub ↗

Plot IFC model as SVG (via ifcopenshell.draw) or PNG/base64 (via CairoSVG). Args: model: In-memory IFC model. output_format: 'svg' | 'png' | 'base64' - 'svg' -> returns SVG bytes - 'png' -> returns PNG bytes - 'base64'-> returns dict:

(
    model: ifcopenshell.file,
    *,
    output_format: str = "png",
    selector: str | None = None,
    element_ids: list[int] | None = None,
    view: str = "floorplan",
    # SVG / page sizing (draw works in mm coordinates)
    width_mm: float = 297.0,
    height_mm: float = 420.0,
    scale: float = 1.0 / 100.0,
    merge_projection: bool = True,
    # PNG sizing (only for output_format png/base64)
    png_width: int = 1024,
    png_height: int = 1024,
)

Source from the content-addressed store, hash-verified

146
147
148def plot(
149 model: ifcopenshell.file,
150 *,
151 output_format: str = "png",
152 selector: str | None = None,
153 element_ids: list[int] | None = None,
154 view: str = "floorplan",
155 # SVG / page sizing (draw works in mm coordinates)
156 width_mm: float = 297.0,
157 height_mm: float = 420.0,
158 scale: float = 1.0 / 100.0,
159 merge_projection: bool = True,
160 # PNG sizing (only for output_format png/base64)
161 png_width: int = 1024,
162 png_height: int = 1024,
163) -> bytes | dict[str, Any]:
164 """
165 Plot IFC model as SVG (via ifcopenshell.draw) or PNG/base64 (via CairoSVG).
166
167 Args:
168 model: In-memory IFC model.
169 output_format: 'svg' | 'png' | 'base64'
170 - 'svg' -> returns SVG bytes
171 - 'png' -> returns PNG bytes
172 - 'base64'-> returns dict: {mime, png_b64, width, height, view}
173 selector: ifcopenshell selector query to restrict plotted elements.
174 element_ids: STEP ids to highlight; non-highlighted geometry is faded.
175 view: One of VIEWS ('floorplan', 'elevation', 'section', 'auto').
176 width_mm, height_mm: Page size in mm.
177 scale: Model-to-paper scale (0.01 means 1:100).
178 merge_projection: Passed through to ifcopenshell.draw.main.
179 png_width, png_height: Raster size in pixels for png/base64 outputs.
180
181 Raises:
182 ImportError: if ifcopenshell.draw or CairoSVG is not available (as required).
183 ValueError: invalid args or selector matches nothing.
184 """
185 if output_format not in OUTPUT_FORMATS:
186 raise ValueError(f"output_format must be one of {OUTPUT_FORMATS}, got {output_format!r}")
187 if view not in VIEWS:
188 raise ValueError(f"view must be one of {VIEWS}, got {view!r}")
189 if not _HAS_DRAW:
190 raise ImportError("ifcopenshell.draw is not available in this environment.")
191
192 # Configure draw settings
193 settings = ifcopenshell.draw.draw_settings(
194 auto_floorplan=(view in ("floorplan", "auto")),
195 auto_elevation=(view in ("elevation", "auto")),
196 auto_section=(view in ("section", "auto")),
197 width=width_mm,
198 height=height_mm,
199 scale=scale,
200 css="",
201 )
202
203 # Optional highlight CSS overlay
204 if element_ids:
205 settings.css = _highlight_css_from_ids(model, element_ids)

Calls 10

_highlight_css_from_idsFunction · 0.85
_make_filtered_iteratorFunction · 0.85
svg_splitFunction · 0.85
_diagnose_empty_drawingFunction · 0.85
newMethod · 0.80
openMethod · 0.80
draw_settingsMethod · 0.45
filter_elementsMethod · 0.45
saveMethod · 0.45
decodeMethod · 0.45