Compilers#
- class pyvcad_compilers.CompilerBase#
Abstract base class of every compiler in pyvcad_compilers.
A compiler stores a design root and its settings when constructed, and does all of its work in compile(), which prepares the root itself. The base class provides progress and status callbacks, cancellation, culling switches and export statistics. Instantiate a concrete compiler such as MaterialInkjetCompiler or VdbCompiler.
- cancel(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) None#
Asks a running compile() to stop. compile() then raises RuntimeError(‘Cancelled’).
Safe to call from another thread.
- compile(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) None#
Compiles the design and writes the output.
Prepares the root, samples it and writes the compiler’s output. Releases the GIL while it runs.
- Raises:
RuntimeError – On invalid input, missing required attributes, or after cancel().
- culling_enabled(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) bool#
Returns True unless set_culling_enabled(False) was called.
- culling_stats(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) pyvcad.pyvcad.CullingStats#
Returns the culling counts (a pyvcad.CullingStats) from the most recent compile.
Inactive, with a fallback_reason, when the design’s distance is approximate, culling is switched off, or the compiler does not cull.
- report_stats(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) None#
Prints export statistics for the most recent successful compile.
- Raises:
RuntimeError – If no compile() has finished.
- set_culling_enabled(self: pyvcad_compilers.pyvcad_compilers.CompilerBase, enabled: bool) None#
Switches skipping of voxels proven empty on or off (on by default).
Culling never changes the output; turning it off is for A/B tests and debugging. The environment variable OPENVCAD_DISABLE_CULLING=1 also turns it off.
- Parameters:
enabled (bool) – False to sample every voxel.
- set_progress_callback(self: pyvcad_compilers.pyvcad_compilers.CompilerBase, arg0: collections.abc.Callable[[float], None]) None#
Sets the progress callback function.
The callback receives the progress fraction in [0, 1]. Calls are rate-limited to roughly every 1% or 100 ms, but a report of 1.0 is always forwarded. Most compilers report 1.0 at the end of a successful compile; a cancelled or failed compile stops early. Use compile() returning, not a 1.0 report, as the completion signal.
- Parameters:
progress_callback (function) – Called with one float argument, the progress.
- set_status_callback(self: pyvcad_compilers.pyvcad_compilers.CompilerBase, arg0: collections.abc.Callable[[str], None]) None#
Sets the compiler stage-status callback.
- Parameters:
status_callback (function) – Receives a human-readable compiler stage message.
- supported_attributes(self: pyvcad_compilers.pyvcad_compilers.CompilerBase) list[str]#
Returns the attribute names this compiler works with.
The meaning depends on the compiler. MaterialInkjetCompiler, ColorInkjetCompiler, MyersonCompiler and SimulationCompiler (its direct_attributes) require the root to carry every listed attribute; compile() raises RuntimeError otherwise. VatCompiler and MultiMaterialVatCompiler list the attribute they sample. The slicer project compilers list every attribute they understand; a design may carry any subset. VdbCompiler and GCVFCompiler return an empty list.
- Returns:
Attribute names, possibly empty.
- Return type:
list[str]
Inkjet and PolyJet#
- class pyvcad_compilers.MaterialInkjetCompiler#
Compiles VOLUME_FRACTIONS into material-coded PolyJet slice images.
Each inside voxel is assigned one material and drawn in that material’s MaterialDefs color. Each layer is written as an RGBA PNG named <file_prefix><z>.png in output_directory; empty leading and trailing layers are removed and the rest renumbered from 0.
- __init__(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_directory: str, file_prefix: str, material_defs: pyvcad.pyvcad.MaterialDefs, liquid_keep_out_distance: SupportsFloat | SupportsIndex = 0.0, export_mode: pyvcad_compilers.pyvcad_compilers.MaterialInkjetExportMode = <MaterialInkjetExportMode.STOCHASTIC: 0>) None#
Constructor. Creates a MaterialInkjetCompiler object.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The voxel size in mm (can be anisotropic).
output_directory (str) – The output directory. Created if missing.
file_prefix (str) – File name prefix. Slice z is written as <file_prefix><z>.png.
material_defs (MaterialDefs) – Material definitions that give each material ID its color.
liquid_keep_out_distance (float, optional) – Distance in mm from the surface within which the keep-out materials (see set_liquid_keep_out_materials) are removed. 0.0 (the default) disables it.
export_mode (MaterialInkjetExportMode, optional) – The material assignment mode. Defaults to STOCHASTIC.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.MaterialInkjetCompiler(root, pv.Vec3(0.0423, 0.0847, 0.027), 'slices', 'layer_', ... pv.default_materials) >>> compiler.compile()
- liquid_keep_out_materials(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler) list[str]#
Returns the keep-out material names set by set_liquid_keep_out_materials(). An empty list means the default liquid material is kept out.
- material_voxel_counts(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler) dict[int, int]#
Returns a dict mapping material IDs to the number of voxels each received in the last compile().
- resolution(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler) tuple[int, int, int]#
Returns the slice resolution of the last compile() as (x_resolution, y_resolution, z_resolution).
z_resolution counts the layers kept after empty layers are trimmed.
- set_fallback_material_id(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler, material_id: SupportsInt | SupportsIndex) None#
Set the fallback material ID for voxels where VOLUME_FRACTIONS is undefined. Only applies when strict mode is off. The default fallback is material ID 0 (void).
- Parameters:
material_id (int) – The fallback material ID.
- set_liquid_keep_out_materials(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler, material_names: collections.abc.Sequence[str]) None#
Set the materials removed within liquid_keep_out_distance of the surface.
Only applies when liquid_keep_out_distance > 0. With an empty list (the default), the material named ‘liquid’ (or ‘M.Cleanser’) is kept out. Every name must exist in the MaterialDefs or compile() raises RuntimeError.
- Parameters:
material_names (list[str]) – Names of the materials to keep out.
Example
>>> compiler.set_liquid_keep_out_materials(['M.Cleanser', 'support'])
- set_strict_mode(self: pyvcad_compilers.pyvcad_compilers.MaterialInkjetCompiler, strict: bool) None#
Enable or disable strict mode.
When strict mode is on, the compiler raises RuntimeError if any inside voxel is missing the VOLUME_FRACTIONS attribute. When off (the default), the fallback material is used for undefined regions.
- Parameters:
strict (bool) – True to enable strict mode.
- class pyvcad_compilers.MaterialInkjetExportMode#
Selects how volume fractions are quantized into discrete material voxels.
Members:
STOCHASTIC : Independently sample each voxel from its local volume fractions.
DITHERED_3D : Deterministically diffuse quantization error across the 3D voxel grid.
- DITHERED_3D = <MaterialInkjetExportMode.DITHERED_3D: 1>#
- STOCHASTIC = <MaterialInkjetExportMode.STOCHASTIC: 0>#
- MaterialInkjetExportMode.name -> str
- property value#
- class pyvcad_compilers.ColorInkjetCompiler#
Compiles COLOR_RGBA into full-color PolyJet slice images.
Each inside voxel’s sRGBA color goes through a ColorPipeline and is assigned one ink (cyan, magenta, yellow, black, white or clear). Each layer is written as an RGBA PNG named <file_prefix><z>.png in output_directory; empty leading and trailing layers are removed and the rest renumbered from 0.
- __init__(self: pyvcad_compilers.pyvcad_compilers.ColorInkjetCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_directory: str, file_prefix: str, icc_profile: str = 'default', export_mode: pyvcad_compilers.pyvcad_compilers.ColorInkjetExportMode = <ColorInkjetExportMode.STOCHASTIC: 0>, color_pipeline_options: pyvcad_compilers.pyvcad_compilers.ColorPipelineOptions = <pyvcad_compilers.pyvcad_compilers.ColorPipelineOptions object at 0x10470a5f0>) None#
Constructor. Creates a ColorInkjetCompiler object.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The voxel size in mm (can be anisotropic).
output_directory (str) – The output directory. Created if missing.
file_prefix (str) – File name prefix. Slice z is written as <file_prefix><z>.png.
icc_profile (str, optional) – ICC profile name from ColorPipeline.get_icc_profiles(). Defaults to ‘default’.
export_mode (ColorInkjetExportMode, optional) – The color-to-ink assignment mode. Defaults to STOCHASTIC.
color_pipeline_options (ColorPipelineOptions, optional) – Color correction pipeline step options.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.ColorInkjetCompiler(root, pv.Vec3(0.0423, 0.0847, 0.027), 'slices', 'layer_') >>> compiler.compile()
- resolution(self: pyvcad_compilers.pyvcad_compilers.ColorInkjetCompiler) tuple[int, int, int]#
Returns the slice resolution of the last compile() as (x_resolution, y_resolution, z_resolution).
z_resolution counts the layers kept after empty layers are trimmed.
- set_fallback_color(self: pyvcad_compilers.pyvcad_compilers.ColorInkjetCompiler, color: pyvcad.pyvcad.Vec4) None#
Set the fallback sRGBA color for voxels where COLOR_RGBA is undefined. Each component is in [0, 1]. Only applies when strict mode is off. The default fallback is fully transparent (0,0,0,0).
- Parameters:
color (Vec4) – The fallback sRGBA color.
- set_strict_mode(self: pyvcad_compilers.pyvcad_compilers.ColorInkjetCompiler, strict: bool) None#
Enable or disable strict mode.
When strict mode is on, the compiler raises RuntimeError if any inside voxel is missing the COLOR_RGBA attribute. When off (the default), the fallback color is used for undefined regions.
- Parameters:
strict (bool) – True to enable strict mode.
- class pyvcad_compilers.ColorInkjetExportMode#
Selects how colors are turned into discrete ink voxels.
Members:
STOCHASTIC : Independently draw each voxel’s ink from its local ink probabilities.
DITHERED_3D : Deterministically diffuse ink quantization error across the 3D voxel grid.
- DITHERED_3D = <ColorInkjetExportMode.DITHERED_3D: 1>#
- STOCHASTIC = <ColorInkjetExportMode.STOCHASTIC: 0>#
- ColorInkjetExportMode.name -> str
- property value#
- class pyvcad_compilers.GCVFCompiler#
Compiles a design into a legacy Stratasys GCVF archive for the J750.
Slices the design with MaterialInkjetCompiler (VOLUME_FRACTIONS) or ColorInkjetCompiler (COLOR_RGBA), then packages the PNG stack, a z-buffer image, an STL mesh, bounding-box metadata and ConfigFile.xml into one .gcvf zip archive.
- __init__(self: pyvcad_compilers.pyvcad_compilers.GCVFCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_file_path: str, material_defs: pyvcad.pyvcad.MaterialDefs = None, channel_material_map: collections.abc.Mapping[str, str]={}, liquid_keep_out_distance: SupportsFloat | SupportsIndex = 0.0, mesh_voxel_size_override: SupportsFloat | SupportsIndex = 0.0, icc_profile: str = 'default', color_export_mode: pyvcad_compilers.pyvcad_compilers.ColorInkjetExportMode = <ColorInkjetExportMode.STOCHASTIC: 0>, color_pipeline_options: pyvcad_compilers.pyvcad_compilers.ColorPipelineOptions = <pyvcad_compilers.pyvcad_compilers.ColorPipelineOptions object at 0x10470adf0>) None#
Constructor. Creates a GCVFCompiler object.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The slice voxel size in mm. ConfigFile.xml’s XDpi, YDpi and SliceThicknessNanoMeter are derived from it (round(25.4 / x), round(25.4 / y), round(z * 1e6)). The J750’s native resolution, (25.4/600, 25.4/300, 0.027) mm, is the usual choice.
output_file_path (str) – The output GCVF archive path.
material_defs (MaterialDefs, optional) – Design material definitions. Required for VOLUME_FRACTIONS designs, whose materials must all be J750 materials; ignored for COLOR_RGBA.
channel_material_map (dict, optional) – Mapping from channel names (‘cyan’, ‘magenta’, ‘yellow’, ‘black’ or ‘key’, ‘white’, ‘clear’) to J750 material names, for COLOR_RGBA designs.
liquid_keep_out_distance (float, optional) – Liquid keep-out distance in mm. Only allowed for VOLUME_FRACTIONS designs.
mesh_voxel_size_override (float, optional) – Uniform voxel size for the STL mesh. 0.0 (the default) uses the largest voxel_size component, but at least 1% of the smallest bounding-box side.
icc_profile (str, optional) – ICC profile name for color mode.
color_export_mode (ColorInkjetExportMode, optional) – Color backend export mode.
color_pipeline_options (ColorPipelineOptions, optional) – Color backend pipeline step options.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.GCVFCompiler(root, pv.Vec3(25.4 / 600, 25.4 / 300, 0.027), 'part.gcvf', ... material_defs=pv.j750_materials)
- resolution(self: pyvcad_compilers.pyvcad_compilers.GCVFCompiler) tuple[int, int, int]#
Returns the slice resolution of the last compile() as (x_resolution, y_resolution, z_resolution).
- set_backend(self: pyvcad_compilers.pyvcad_compilers.GCVFCompiler, backend: pyvcad_compilers.pyvcad_compilers.GCVFBackend) None#
Chooses the slice backend instead of inferring it from the design.
Needed when a design has both VOLUME_FRACTIONS and COLOR_RGBA. The attribute the chosen backend reads must be present or compile() raises RuntimeError.
- Parameters:
backend (GCVFBackend) – AUTOMATIC (default), MATERIAL, or COLOR.
Example
>>> compiler.set_backend(pvc.GCVFBackend.COLOR)
- set_liquid_keep_out_materials(self: pyvcad_compilers.pyvcad_compilers.GCVFCompiler, material_names: collections.abc.Sequence[str]) None#
Set the design materials removed within liquid_keep_out_distance of the surface.
Only applies to volume_fractions designs with liquid_keep_out_distance > 0. With an empty list (the default), the material named ‘liquid’ (or ‘M.Cleanser’) is kept out.
- Parameters:
material_names (list[str]) – Names of the materials to keep out.
- class pyvcad_compilers.GCVFBackend#
Selects which slice backend a GCVF export uses.
Members:
AUTOMATIC : Pick from the design’s attributes; fails if it has both VOLUME_FRACTIONS and COLOR_RGBA.
MATERIAL : Resolve VOLUME_FRACTIONS as J750 materials.
COLOR : Resolve COLOR_RGBA through the color pipeline.
- AUTOMATIC = <GCVFBackend.AUTOMATIC: 0>#
- COLOR = <GCVFBackend.COLOR: 2>#
- MATERIAL = <GCVFBackend.MATERIAL: 1>#
- GCVFBackend.name -> str
- property value#
- class pyvcad_compilers.MyersonCompiler#
Writes per-material 1-bit BMP stacks for the legacy Myerson workflow.
Reads VOLUME_FRACTIONS and writes one folder per material found in the design, with one bitmap per layer on a fixed 880-pixel-wide canvas. Each inside voxel gets one material by stochastic sampling; a void pick leaves the voxel empty.
- __init__(self: pyvcad_compilers.pyvcad_compilers.MyersonCompiler, layer_height: SupportsFloat | SupportsIndex, x_dpi: SupportsInt | SupportsIndex, y_dpi: SupportsInt | SupportsIndex, taper_angle_deg: SupportsFloat | SupportsIndex, extra_width: SupportsFloat | SupportsIndex, output_path: str, root: pyvcad.pyvcad.Node, material_defs: pyvcad.pyvcad.MaterialDefs) None#
Constructor. Creates a MyersonCompiler object.
- Parameters:
layer_height (float) – The layer height in mm.
x_dpi (int) – The X resolution in dots per inch.
y_dpi (int) – The Y resolution in dots per inch.
taper_angle_deg (float) – The taper angle in degrees.
extra_width (float) – Additional per-side Y padding in mm.
output_path (str) – The output directory that will contain per-material folders.
root (Node) – The root node of the tree. compile() prepares it.
material_defs (MaterialDefs) – Material definitions used to name the output folders.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.MyersonCompiler(0.032, 600, 600, 0.0, 0.0, "out", root, pv.default_materials)
- resolution(self: pyvcad_compilers.pyvcad_compilers.MyersonCompiler) tuple[int, int, int]#
Returns the exported bitmap resolution as (width, height, layer_count).
- Parameters:
None.
Example
>>> compiler.resolution()
- set_fallback_material_id(self: pyvcad_compilers.pyvcad_compilers.MyersonCompiler, material_id: SupportsInt | SupportsIndex) None#
Set the fallback material ID used when VOLUME_FRACTIONS is undefined.
Only applies when strict mode is off. The fallback must be one of the materials in the design’s VOLUME_FRACTIONS attributes; otherwise compile() raises RuntimeError as soon as an inside voxel lacks VOLUME_FRACTIONS. The default, 0 (void), is never exported, so with the default every inside voxel needs VOLUME_FRACTIONS.
- Parameters:
material_id (int) – The fallback material ID.
Example
>>> compiler.set_fallback_material_id(pv.default_materials.id('red'))
- set_strict_mode(self: pyvcad_compilers.pyvcad_compilers.MyersonCompiler, strict: bool) None#
Enable or disable strict mode.
- Parameters:
strict (bool) – True to raise when inside voxels are missing VOLUME_FRACTIONS.
Example
>>> compiler.set_strict_mode(True)
Vat photopolymerization#
- class pyvcad_compilers.VatCompiler#
Compiles the INTENSITY attribute into grayscale BMP slices for vat photopolymerization.
INTENSITY in [0, 1] maps to 8-bit gray. Each layer is written as <file_prefix><z>.bmp in output_directory; empty leading and trailing layers are removed and the rest renumbered from 0. The image covers either the design’s bounding box or, with printer_volume, the printer’s XY build area with the design centered.
- __init__(*args, **kwargs)#
Overloaded function.
__init__(self: pyvcad_compilers.pyvcad_compilers.VatCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_directory: str, file_prefix: str) -> None
Constructor. Creates a VatCompiler that samples the model bounding box.
- Parameters:
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.VatCompiler(root, pv.Vec3(0.05, 0.05, 0.05), 'slices', 'layer_') >>> compiler.compile()
__init__(self: pyvcad_compilers.pyvcad_compilers.VatCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, printer_volume: pyvcad.pyvcad.Vec3, output_directory: str, file_prefix: str) -> None
Constructor. Creates a VatCompiler that uses a fixed printer-volume XY domain.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The voxel size in mm.
printer_volume (Vec3) – The printer build volume in mm. compile() raises RuntimeError if the design’s bounding box is larger.
output_directory (str) – The output directory. Created if missing.
file_prefix (str) – File name prefix. Slice z is written as <file_prefix><z>.bmp.
- resolution(self: pyvcad_compilers.pyvcad_compilers.VatCompiler) tuple[int, int, int]#
Returns the compiled resolution as (x_resolution, y_resolution, z_layer_count).
z_layer_count counts the layers kept after empty layers are trimmed.
- set_fallback_intensity(self: pyvcad_compilers.pyvcad_compilers.VatCompiler, intensity: SupportsFloat | SupportsIndex) None#
Set the fallback intensity for voxels where INTENSITY is undefined.
The value is clamped into [0, 1]. Only applies when strict mode is off. The default fallback intensity is 1.0.
- Parameters:
intensity (float) – The fallback exposure intensity.
- set_strict_mode(self: pyvcad_compilers.pyvcad_compilers.VatCompiler, strict: bool) None#
Enable or disable strict mode.
When strict mode is on, the compiler raises RuntimeError if any inside voxel is missing the INTENSITY attribute. When off (the default), missing values use the fallback intensity.
- Parameters:
strict (bool) – True to enable strict mode.
- class pyvcad_compilers.MultiMaterialVatCompiler#
Compile volume fractions into synchronized grayscale PNG stacks for dual- or quad-vat printers.
Each inside sample draws one material from its volume fractions with a seeded random draw. Void (material ID 0) takes part in the draw, so a draw that lands on void, or all-zero fractions, leaves the pixel black in every vat. Otherwise the drawn material’s vat gets the pixel, exposed by the optional ‘<material_name>_intensity’ scalar attribute (default 1.0), and the other vats get black. Every non-void material with a positive fraction must be assigned to a vat, or compile() raises RuntimeError. Images use a fixed 1280 x 800 canvas spanning 55.01 x 34.38 mm, with the design centered in XY.
- __init__(self: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatCompiler, root: pyvcad.pyvcad.Node, output_path: str, material_defs: pyvcad.pyvcad.MaterialDefs, vat_material_names: collections.abc.Sequence[str], layer_thickness: typing.SupportsFloat | typing.SupportsIndex = 0.05, system: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatSystem = <MultiMaterialVatSystem.DUAL: 2>, output_mode: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatOutputMode = <MultiMaterialVatOutputMode.DIRECTORY: 0>, random_seed: typing.SupportsInt | typing.SupportsIndex = 0) None#
Constructor. Creates a MultiMaterialVatCompiler object.
- Parameters:
root (Node) – The design root with VOLUME_FRACTIONS. compile() prepares it.
output_path (str) – Directory path and ZIP filename stem.
material_defs (MaterialDefs) – Material definitions for the design.
vat_material_names (list[str]) – Ordered materials mapped to vats A-D.
layer_thickness (float, optional) – Layer height in mm. Defaults to 0.05.
system (MultiMaterialVatSystem, optional) – DUAL or QUAD. Defaults to DUAL.
output_mode (MultiMaterialVatOutputMode, optional) – Directory, ZIP, or both.
random_seed (int, optional) – Reproducible stochastic assignment seed. Defaults to 0.
- Raises:
RuntimeError – If layer_thickness is below 0.01 mm, or vat_material_names is empty, longer than the system’s vat count, repeats a name, names void, or names an undefined material.
- archive_path(self: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatCompiler) str#
Returns the ZIP path: output_path with any .zip extension removed, then .zip appended.
- printer_volume(self: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatCompiler) pyvcad.pyvcad.Vec3#
Returns the fixed 55.01 x 34.38 x 150 mm build volume.
- resolution(self: pyvcad_compilers.pyvcad_compilers.MultiMaterialVatCompiler) tuple[int, int, int]#
Returns (1280, 800, layer_count). layer_count is 0 before compile().
- class pyvcad_compilers.MultiMaterialVatSystem#
Selects the target number of resin vats.
Members:
DUAL : Two vats, A and B.
QUAD : Four vats, A through D.
- DUAL = <MultiMaterialVatSystem.DUAL: 2>#
- QUAD = <MultiMaterialVatSystem.QUAD: 4>#
- MultiMaterialVatSystem.name -> str
- property value#
- class pyvcad_compilers.MultiMaterialVatOutputMode#
Selects which sliced-image outputs are kept.
Members:
DIRECTORY : Keep the vat_a … vat_d folders of PNG layers.
ZIP : Write only the ZIP archive; the folders are removed afterwards.
DIRECTORY_AND_ZIP : Keep the folders and also write the ZIP archive.
- DIRECTORY = <MultiMaterialVatOutputMode.DIRECTORY: 0>#
- DIRECTORY_AND_ZIP = <MultiMaterialVatOutputMode.DIRECTORY_AND_ZIP: 2>#
- ZIP = <MultiMaterialVatOutputMode.ZIP: 1>#
- MultiMaterialVatOutputMode.name -> str
- property value#
Slicer projects#
- class pyvcad_compilers.SlicerProjectCompiler#
Abstract base class for slicer project compilers. Instantiate PrusaSlicerProjectCompiler or FullSpectrumSlicerProjectCompiler.
- class pyvcad_compilers.PrusaSlicerProjectCompiler#
Compiles slicer attributes into a PrusaSlicer-compatible .3mf project.
Three workflows, picked from the design’s attributes: settings meshes (per-region PrusaSlicer settings such as infill_density), virtual extrusion (temperature with a flow_rate companion, written as toolchange G-code), and ColorMix (COLOR_RGB or VOLUME_FRACTIONS as mixed-filament regions). ColorMix cannot be combined with the other two.
- __init__(self: pyvcad_compilers.pyvcad_compilers.PrusaSlicerProjectCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_file_path: str, num_regions: SupportsInt | SupportsIndex = 10, printer_profile_path: str = '', filament_profile_path: str = '', enable_color_mix: bool = False, color_mix_filaments: object = None, total_physical_extruders: SupportsInt | SupportsIndex = 5, color_mix_recipe_preset: str = 'expanded', max_palette_size: SupportsInt | SupportsIndex = 32, min_component_percent: SupportsInt | SupportsIndex = 15, max_recipe_components: SupportsInt | SupportsIndex = 3, direct_physical_delta_e: SupportsFloat | SupportsIndex = 1.0, region_overlap_mm: SupportsFloat | SupportsIndex = 0.2, volume_fraction_materials: dict = {}, material_defs_path: str = '', close_unresolved_band_gaps: bool = True, volume_fraction_palette_mode: str = 'uniform') None#
Constructor. Creates a PrusaSlicer project compiler.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The sampling voxel size in mm.
output_file_path (str) – The output file path for the .3mf project.
num_regions (int) – The number of sub-ranges per attribute dimension. Defaults to 10.
printer_profile_path (str) – Path to PrusaSlicer printer profile (.ini). Required when virtual extrusion attributes are present; for ColorMix, either profile adds a project config. Defaults to “”.
filament_profile_path (str) – Path to PrusaSlicer filament profile (.ini). Required when virtual extrusion attributes are present. Defaults to “”.
enable_color_mix (bool) – Enable Prusa ColorMix export explicitly. COLOR_RGB or VOLUME_FRACTIONS also select ColorMix automatically.
color_mix_filaments (list[dict], optional) – Physical filaments, each a dict with color_hex and optional slot (defaults to its position, from 1) and nozzle_diameter_mm (currently unused). None uses the default CMYKW set, limited to total_physical_extruders. For VOLUME_FRACTIONS designs, slots in volume_fraction_materials that are missing here are added with the material’s color.
total_physical_extruders (int) – Total physical extruder slots in PrusaSlicer. Virtual ColorMix extruder IDs start after this count.
color_mix_recipe_preset (str) – Printable recipe set for COLOR_RGB ColorMix export. Use “expanded” or “conservative”.
max_palette_size (int) – Maximum generated ColorMix palette size.
min_component_percent (int) – Minimum component weight for mixed recipes.
max_recipe_components (int) – Maximum physical filaments per Prusa ColorMix recipe, up to 3.
direct_physical_delta_e (float) – Legacy compatibility setting; Prusa COLOR_RGB ColorMix selects physical and virtual recipes from one candidate set.
region_overlap_mm (float) – Small spatial overlap between generated ColorMix regions.
volume_fraction_materials (dict[str, int]) – Material name to physical slot (from 1). Required when the design has VOLUME_FRACTIONS and no COLOR_RGB; compile() raises RuntimeError if it is empty then. Ignored otherwise.
material_defs_path (str) – Optional MaterialDefs JSON path. Empty uses bundled configs/default.json.
close_unresolved_band_gaps (bool) – Closes the sub-voxel slot left where a segmented attribute jumps by more than one region between neighbouring voxels (e.g. a discontinuous attribute, or a gradient too steep for the voxel size). Off leaves the legacy behaviour.
volume_fraction_palette_mode (str) – How VOLUME_FRACTIONS palette recipes are chosen. “uniform” (default) cuts the fraction range into max_palette_size equal bins, so every region spans the same fraction width. “adaptive” median-cuts the sampled fraction histogram, spending recipes where the samples are but only splitting in halves, so bin widths are uneven unless max_palette_size is a power of two. Uniform needs one free axis, so exports with three or more materials always use adaptive.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.PrusaSlicerProjectCompiler(root, pv.Vec3(0.5, 0.5, 0.5), 'part.3mf', ... volume_fraction_materials={'red': 1, 'blue': 2}) >>> compiler.compile()
- class pyvcad_compilers.FullSpectrumSlicerProjectCompiler#
Compiles COLOR_RGB or VOLUME_FRACTIONS into an Orca FullSpectrum .3mf project.
Builds a palette of physical and virtual mixed-filament recipes, meshes one region per recipe, and writes the Bambu/Orca component-based 3MF dialect with a resolved Orca project config. COLOR_RGB wins when a design has both attributes. Settings-mesh and virtual-extrusion attributes are not supported.
- __init__(self: pyvcad_compilers.pyvcad_compilers.FullSpectrumSlicerProjectCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_file_path: str, filaments: object = None, max_palette_size: SupportsInt | SupportsIndex = 32, min_component_percent: SupportsInt | SupportsIndex = 15, max_recipe_components: SupportsInt | SupportsIndex = 3, direct_physical_delta_e: SupportsFloat | SupportsIndex = 1.0, region_overlap_mm: SupportsFloat | SupportsIndex = 0.2, base_project_settings_path: str = '', orca_machine_profile_path: str = '', orca_process_profile_path: str = '', orca_default_filament_profile_path: str = '', orca_profile_search_paths: collections.abc.Sequence[str] = [], volume_fraction_materials: dict = {}, material_defs_path: str = '', color_mix_recipe_preset: str = 'expanded', volume_fraction_palette_mode: str = 'uniform') None#
Constructor. Creates an Orca FullSpectrum project compiler.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The sampling voxel size in mm.
output_file_path (str) – The output file path for the .3mf project.
filaments (list[dict], optional) – 2 to 9 physical filaments with slots 1, 2, … in order. Each dict has color_hex (‘#RRGGBB’) and optional slot (defaults to its position, from 1), filament_settings_id, filament_id, filament_profile_path and nozzle_diameter_mm (default 0.4). None uses a default CMYKW set for COLOR_RGB designs. For VOLUME_FRACTIONS designs, slots in volume_fraction_materials that are missing here are added with the material’s color, so filaments can be left out when the mapping covers slots 1..N.
max_palette_size (int) – Maximum generated color palette size or volume-fraction region count.
min_component_percent (int) – Minimum component weight for mixed recipes.
max_recipe_components (int) – Maximum physical filaments per mixed recipe, capped at 3.
direct_physical_delta_e (float) – Legacy compatibility setting; COLOR_RGB FullSpectrum selects physical and virtual recipes from one candidate set.
region_overlap_mm (float) – Small spatial overlap between generated regions.
base_project_settings_path (str) – Optional Orca project settings JSON to overlay before FullSpectrum keys.
orca_machine_profile_path (str) – Orca machine profile path or name. Empty uses the bundled ‘Prusa XL 5T 0.4 nozzle’ profile.
orca_process_profile_path (str) – Orca process profile path or name. Empty uses the bundled ‘0.20mm Speed @Prusa XL 5T 0.4’ profile.
orca_default_filament_profile_path (str) – Orca filament profile path or name for filaments without their own filament_profile_path. Empty uses the bundled PLA profile.
orca_profile_search_paths (list[str]) – Additional directories searched for Orca JSON profiles, after the bundled ones.
volume_fraction_materials (dict[str, int]) – Material name to physical slot (from 1). Required when the design has VOLUME_FRACTIONS and no COLOR_RGB; compile() raises RuntimeError if it is empty then. VOLUME_FRACTIONS export is palette-based, like COLOR_RGB export.
material_defs_path (str) – Optional MaterialDefs JSON path. Empty uses bundled configs/default.json.
color_mix_recipe_preset (str) – Printable recipe set for COLOR_RGB FullSpectrum export. Use “expanded” or “conservative”.
volume_fraction_palette_mode (str) – How VOLUME_FRACTIONS palette recipes are chosen. “uniform” (default) cuts the fraction range into max_palette_size equal bins, so every region spans the same fraction width. “adaptive” median-cuts the sampled fraction histogram, spending recipes where the samples are but only splitting in halves, so bin widths are uneven unless max_palette_size is a power of two. Uniform needs one free axis, so exports with three or more materials always use adaptive.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.FullSpectrumSlicerProjectCompiler(root, pv.Vec3(0.5, 0.5, 0.5), 'part.3mf', ... volume_fraction_materials={'red': 1, 'blue': 2}) >>> compiler.compile()
Volumetric data#
- class pyvcad_compilers.VdbCompiler#
Exports a design to one OpenVDB file.
The file always has a FloatGrid level set named ‘surface’. It can also hold a BoolGrid named ‘occupancy’ and one grid per exported scalar, vec3 or vec4 attribute. VOLUME_FRACTIONS is never exported, and attributes of other types are skipped.
- __init__(self: pyvcad_compilers.pyvcad_compilers.VdbCompiler, root: pyvcad.pyvcad.Node, voxel_size: pyvcad.pyvcad.Vec3, output_file_path: str, attributes_to_export: object = [], include_occupancy: bool = False) None#
Constructor. Creates a VdbCompiler that writes one OpenVDB file.
- Parameters:
root (Node) – The root node of the tree. compile() prepares it.
voxel_size (Vec3) – The voxel size in mm.
output_file_path (str) – The VDB file path to write. Missing parent folders are created.
attributes_to_export (list[str] | None, optional) – Attribute names to export. [] (the default) exports every attribute on the root except VOLUME_FRACTIONS; None exports none.
include_occupancy (bool, optional) – True to include a BoolGrid named ‘occupancy’. Defaults to False.
- Raises (from compile()):
- RuntimeError: If an exported attribute has no sample inside or on the surface, or mixes
scalar, vec3 and vec4 values.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> compiler = pvc.VdbCompiler(root, pv.Vec3(0.5, 0.5, 0.5), 'part.vdb', attributes_to_export=None) >>> compiler.compile()
Simulation#
The simulation compiler meshes a design and exports it to a solver. See the Simulation Compiler guide.
- class pyvcad_compilers.SimulationCompiler#
Meshes a design (hex or tet), samples attributes at element centroids and writes one backend: a GENERIC in-memory SimulationModel, Abaqus .inp, FEniCSx .xdmf/.h5 or LS-DYNA .k.
- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationCompiler, root: pyvcad.pyvcad.Node, settings: pyvcad_compilers.pyvcad_compilers.SimulationCompilerSettings) None#
Constructor.
- Parameters:
root (Node) – The root node of the design. compile() prepares it.
settings (SimulationCompilerSettings) – Mesh, backend and attribute settings. Copied, so later changes to the object have no effect.
Example
>>> import pyvcad as pv >>> import pyvcad_compilers as pvc >>> settings = pvc.SimulationCompilerSettings() >>> settings.backend = pvc.SimulationBackend.GENERIC >>> settings.hex_settings.voxel_size = pv.Vec3(0.5, 0.5, 0.5) >>> compiler = pvc.SimulationCompiler(root, settings) >>> compiler.compile() >>> model = compiler.model()
- element_count(self: pyvcad_compilers.pyvcad_compilers.SimulationCompiler) int#
Number of mesh elements from the last compile() (before any backend-specific filtering, such as LSDYNA_K dropping void elements).
- model(self: pyvcad_compilers.pyvcad_compilers.SimulationCompiler) pyvcad_compilers.pyvcad_compilers.SimulationModel#
The prepared SimulationModel. Only available after compiling with the GENERIC backend.
- Raises:
RuntimeError – If the last compile() used another backend or none has run.
- node_count(self: pyvcad_compilers.pyvcad_compilers.SimulationCompiler) int#
Number of mesh nodes from the last compile() (before any backend-specific filtering).
- written_files(self: pyvcad_compilers.pyvcad_compilers.SimulationCompiler) list[str]#
Paths written by the last compile(); empty for GENERIC.
- class pyvcad_compilers.SimulationCompilerSettings#
Settings of the SimulationCompiler.
- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationCompilerSettings) None#
Creates settings for an ABAQUS_INP hex mesh with the defaults listed on each field.
- property backend#
GENERIC, ABAQUS_INP (default), FENICSX_XDMF or LSDYNA_K.
- Type:
- property direct_attributes#
scalar attributes sampled per element into SimulationModel.scalar_fields. Only modulus, poissons_ratio and density are supported. The root must carry each one, and compile() raises RuntimeError if an element centroid has no value.
- Type:
list[str]
- property file_prefix#
output file name without extension (default ‘simulation’); ignored by GENERIC.
- Type:
str
- property hex_settings#
used when mesh_kind is HEX.
- property lsdyna_settings#
options used only by the LSDYNA_K backend.
- Type:
- property material_defs#
material table used to name volume-fraction materials. The LSDYNA_K backend also reads optional ‘density’, ‘modulus’ and ‘poissons_ratio’ entries from it.
- Type:
- property mesh_kind#
HEX (default) or TET.
- Type:
- property output_directory#
folder for file backends, created if missing; ignored by GENERIC.
- Type:
str
- property random_seed#
seed for deterministic tet meshing and the stochastic material_id draw (default 0).
- Type:
int
- property tet_adaptive_settings#
used when mesh_kind is TET and use_adaptive_tet_sizing is True.
- property tet_fixed_settings#
used when mesh_kind is TET and use_adaptive_tet_sizing is False.
- property use_adaptive_tet_sizing#
use the adaptive tet sizing settings (default False).
- Type:
bool
- class pyvcad_compilers.SimulationLsDynaSettings#
Options for the LSDYNA_K backend.
The .k deck is geometry only: nodes, solid elements, and one
*PART,*SECTION_SOLID, placeholder*MAT_ELASTICand*SET_PART_LISTper material, plus a part set with every part. It has no loads, boundary conditions, contact or control cards. Units: mm, tonne, s, N, MPa. Checked with LS-DYNA R16.1 (SMP, double precision): exported decks read and initialise without errors and run a short explicit test.- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationLsDynaSettings) None#
Creates default LS-DYNA settings.
- property default_density#
placeholder density in tonne/mm^3 (default 1e-9) for materials without a ‘density’ entry in material_defs.
- Type:
float
- property default_modulus#
placeholder Young’s modulus in MPa (default 100) for materials without a ‘modulus’ entry in material_defs.
- Type:
float
- property default_poissons_ratio#
placeholder Poisson’s ratio (default 0.3) for materials without a ‘poissons_ratio’ entry in material_defs.
- Type:
float
- property element_id_offset#
added to every element ID (element index + 1 + offset).
- Type:
int
- property hex_element_formulation#
*SECTION_SOLIDELFORM for hex meshes (default 1, constant-stress solid; 2 is the fully integrated solid). Tetrahedron formulations (4, 10, 13, 60) and 20-node or higher-order formulations raise an error.- Type:
int
- property include_void_elements#
they are dropped, together with nodes that only they use.
- Type:
bool
- Type:
keep elements whose sampled material is void (material ID 0). Default False
- property long_format#
force long format (
*KEYWORD LONG=Y, 20-column fields). Chosen automatically when a node or element ID exceeds 99,999,999.- Type:
bool
- property mixed_material_tet_element_formulation#
its nodal pressure averaging creates spurious energy (
*SECTION_SOLIDremark 12). Set it to 13 to keep 13.- Type:
int
- Type:
ELFORM used instead of 13 for tet decks whose parts have different bulk moduli and share nodes (default 10). LS-DYNA does not allow ELFORM 13 there
- property node_id_offset#
added to every node ID (node index + 1 + offset).
- Type:
int
- property part_id_offset#
added to every part, section, material and part-set ID.
- Type:
int
- property tet_element_formulation#
*SECTION_SOLIDELFORM for tet meshes (default 13, 1-point nodal-pressure tetrahedron; 10 is the plain 1-point tetrahedron). Tets are written as degenerate 8-node solids (N5..N8 = N4). When this is 13 and parts with different bulk moduli share nodes, mixed_material_tet_element_formulation is used instead. 10-node formulations (16, 17) raise an error.- Type:
int
- property title#
*TITLEtext (at most 80 characters are written).- Type:
str
- class pyvcad_compilers.SimulationHexMeshSettings#
Hexahedral mesh settings for SimulationCompilerSettings.hex_settings.
- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationHexMeshSettings) None#
Creates settings with a 1 mm voxel size.
- class pyvcad_compilers.SimulationTetFixedMeshSettings#
Tetrahedral mesh settings with one target cell size (CGAL Mesh_3 criteria, in mm).
- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationTetFixedMeshSettings) None#
Creates settings with the defaults listed on each field.
- property cell_radius_edge_ratio#
largest circumradius to shortest edge ratio of a tetrahedron (default 3).
- Type:
int
- property cell_size#
largest tetrahedron circumradius in mm (default 0.1).
- Type:
float
- property facet_angle#
smallest surface-triangle angle in degrees (default 30).
- Type:
float
- property facet_distance#
largest distance in mm between a surface triangle and the true surface (default 0.01).
- Type:
float
- property facet_size#
largest surface-triangle size in mm (default 0.1).
- Type:
float
- class pyvcad_compilers.SimulationTetAdaptiveMeshSettings#
Tetrahedral mesh settings whose cell size follows an expression (CGAL Mesh_3 criteria, in mm).
- __init__(self: pyvcad_compilers.pyvcad_compilers.SimulationTetAdaptiveMeshSettings) None#
Creates settings with the defaults listed on each field.
- property cell_radius_edge_ratio#
largest circumradius to shortest edge ratio of a tetrahedron (default 3).
- Type:
int
- property cell_size_lower#
smallest cell size in mm, min_cell in the expression (default 0.1).
- Type:
float
- property cell_size_upper#
largest cell size in mm, max_cell in the expression (default 1.0).
- Type:
float
- property facet_angle#
smallest surface-triangle angle in degrees (default 30).
- Type:
float
- property facet_distance#
largest distance in mm between a surface triangle and the true surface (default 0.01).
- Type:
float
- property facet_size#
largest surface-triangle size in mm (default 0.1).
- Type:
float
- property variable_cell_size_expression#
cell-size expression of min_cell, max_cell and h, the length of the tree’s gradient (default ‘min_cell + h * (max_cell - min_cell)’).
- Type:
str
- class pyvcad_compilers.SimulationModel#
Mesh and per-element data built by SimulationCompiler with the GENERIC backend.
Read-only. Get it from SimulationCompiler.model() after compile().
- property cell_type#
HEX8 or TET4.
- Type:
- property connectivity#
flat node indices, nodes_per_cell per element.
- Type:
list[int]
- property material_ids#
one material ID per element, drawn from its volume fractions with random_seed. Empty when the design has no VOLUME_FRACTIONS.
- Type:
list[int]
- property material_names#
names of the materials with a positive fraction somewhere, from material_defs, or ‘material_<id>’ when not found.
- Type:
dict[int, str]
- property nodes_per_cell#
8 for HEX8, 4 for TET4.
- Type:
int
- property scalar_fields#
per-element values of each direct attribute.
- Type:
dict[str, list[float]]
- property volume_fraction_fields#
per-element volume fraction of each material.
- Type:
dict[int, list[float]]
- class pyvcad_compilers.SimulationBackend#
Output transport of the SimulationCompiler.
Members:
GENERIC : No files. After compile(), SimulationCompiler.model() returns the prepared SimulationModel.
ABAQUS_INP : Abaqus input file <file_prefix>.inp.
FENICSX_XDMF : FEniCSx/DOLFINx mesh bundle <file_prefix>.xdmf + <file_prefix>.h5.
LSDYNA_K : LS-DYNA keyword deck <file_prefix>.k (geometry only, placeholder materials; checked with LS-DYNA R16.1). Options are in SimulationCompilerSettings.lsdyna_settings.
- ABAQUS_INP = <SimulationBackend.ABAQUS_INP: 1>#
- FENICSX_XDMF = <SimulationBackend.FENICSX_XDMF: 2>#
- GENERIC = <SimulationBackend.GENERIC: 0>#
- LSDYNA_K = <SimulationBackend.LSDYNA_K: 3>#
- SimulationBackend.name -> str
- property value#