vpype_gscrib.renderer
Converts vector graphics into G-code programs.
This module provides the main tools to generate G-code programs for CNC machines and similar devices. GRenderer is the main class that generates the G-code program from a vpype document.
- class vpype_gscrib.renderer.GContext(builder: GCodeBuilder, config: RenderConfig)
Bases:
objectContext of the G-code generation.
This class encapsulates all the configuration parameters needed for G-code generation, including units, speeds, z-axis positions, and machine-specific settings.
Along with the Gbuilder instance it exposes all public fields from the provided RenderConfig as read-only properties. Values are automatically scaled according to the unit conventions below:
Times: scaled from seconds to time units
Speeds: scaled from pixels to length units (mm/min or in/min)
Lengths: scaled from length units to pixels (by GCodeBuilder)
Example
>>> ctx = GContext(builder, config) >>> print(config.work_speed) # Speed in px/min >>> print(ctx.work_speed) # Speed in units/min
- Parameters:
builder (GCodeBuilder) – G-code builder instance
config (RenderConfig) – Configuration object
- format_config_values()
Return a formatted dictionary of configuration values
- property g: GCodeBuilder
The G-code builder instance
- property height_map: BaseHeightMap
Height map instance for this context
- class vpype_gscrib.renderer.GRenderer(builder: GCodeBuilder, configs: List[RenderConfig])
Bases:
DocumentRendererConverts vector graphics to G-Code machine instructions.
This class implements the DocumentRenderer interface by delegating specific machine operations to specialized components:
Head: Controls machine head movements (travel, plunge, retract)
Tool: Manages tool operations (tool activation/deactivation)
Coolant: Handles coolant system control (turn on/off)
Rack: Manages tool changes and rack operations
Bed: Handles bed operations (heat/cool down)
Each component is created through its respective factory based on the configuration modes, allowing different strategies to be swapped without changing the renderer’s core logic. This allows for:
Easy addition of new machine head types
Support for different tool systems (laser, spindle, etc.)
Flexible coolant control strategies
Various tool rack configurations
The renderer coordinates these components to process the document hierarchy: Document → Layers → Paths → Segments, generating appropriate G-code commands through the GCodeBuilder instance.
- Parameters:
builder (GCodeBuilder) – G-code builder instance
configs (List[RenderConfig]) – Configuration parameters
- _g
G-code command builder instance
- Type:
GCodeBuilder
- _config
Rendering configuration parameters
- Type:
- _coolant
Coolant system controller
- Type:
- begin_document(document: Document)
This method is invoked once per document before any of the document layers are processed.
Initializes the G-code generation environment by:
Setting up the coordinate system
Configuring absolute positioning
Setting the appropriate unit system
Establishing the XY plane
Applying initial transformations for document orientation
- Parameters:
document (Document) – Document being processed
- begin_layer(layer: LineCollection)
Each layer is composed of one or more paths. This method is invoked once per layer before any paths are processed.
Prepares the machine for processing a new layer by:
Moving to service position for tool changes
Performing necessary tool changes
Positioning at the layer start point
Activating the tool and coolant systems
- Parameters:
layer (LineCollection) – Layer being processed
- begin_path(path: array)
Each path is composed of one or more segments. This method is invoked once per path before any of its segments are processed.
Prepares for machining operations by:
Retracting the tool head
Moving to the path start position
Plunging to working depth
Activating tool power
- Parameters:
path (array) – Path being processed
- end_document(document: Document)
This method is invoked once per document after all layers on the document have been processed.
Finalizes G-code generation by:
Moving to final park position
Adding program end commands
Performing cleanup operations
- Parameters:
document (Document) – Document being processed
- end_layer(layer: LineCollection)
This method is invoked once per layer after all paths on the layer have been processed.
Performs layer cleanup operations:
Retracting to safe height
Deactivating the tool
Turning off coolant systems
- Parameters:
layer (LineCollection) – Layer being processed
- end_path(path: array)
This method is invoked once per path after all segments of the path have been processed.
Performs path completion operations:
Turning off tool power
Retracting the tool head to safe height
- Parameters:
path (array) – Path being processed
- process_error(e: Exception)
Invoked if an error occurs during the processing.
Handles error conditions by:
Generating emergency stop commands
Performing safe shutdown procedures
Adding error information to the G-code output
- Parameters:
e (Exception) – The exception that occurred