Skip to main content

Plotter3D

Plotter3D is a 3D plotter for creating artwork using G-code. This class should be used with a 3D printer.

Plotter3D extends from the abstract class Plotter.

init

__init__(
self, title: str, x_min: float, x_max: float, y_min: float, y_max: float, z_plotting_height: float, z_navigation_height: float, feed_rate: float, handle_out_of_bounds: Union[Literal['Warning'], Literal['Error']] = 'Warning', output_directory: str = './output', include_comments: bool = True )
-> None

Initializes a new instance of the Plotter3D class.

Args:

  • title (str) : The title of the work of art.
  • x_min (float) : The minimum X-coordinate of the plotter.
  • y_min (float) : The minimum Y-coordinate of the plotter.
  • x_max (float) : The maximum X-coordinate of the plotter.
  • y_max (float) : The maximum Y-coordinate of the plotter.
  • z_plotting_height (float) : The height of the plotting instrument when plotting on the plotting surface.
  • z_navigation_height (float) : The height of the plotting instrument when navigating to a new location.
  • feed_rate (float) : The feed rate, for the plotter.
  • handle_out_of_bounds (Warning | Error, optional): How to handle out-of-bounds points. Warning will print a warning, skip the point, and continue. Error will throw an error and stop. Defaults to Warning.
  • output_directory (str, optional) : The directory where G-code files will be saved. Defaults to ./output.
  • include_comments (bool, optional) : Whether to include comments in the G-Code files. Useful for learning about G-Code and debugging. D efaults to True.

add_layer

add_layer(
self, title: str, color: Optional[str] = None, line_width: float = 2.0, preview_only: bool = False )
-> gcode2dplotterart.layer.Layer3D.Layer3D

Adds a new layer to the plotter.

Args:

  • title (str): The title of the layer.
  • color (Optional[str], optional): The color of the layer. Defaults to None.
  • line_width (float, optional): The line width of the layer. Defaults to 2.0.
  • preview_only (bool, optional): Whether the layer is for preview only. Defaults to False.

Returns:

  • Layer3D: The newly created layer.

get_min_and_max_points

get_min_and_max_points(
self )
-> Dict[Literal['x_min', 'y_min', 'x_max', 'y_max'], float]

Find the min and max plot points of the plotter.

Returns:

  • dict : {x_min (float), y_min (float), x_max (float), y_max (float)} A dictionary containing the min and max plot points of the plotter.

get_plotting_data

get_plotting_data(
self )
-> Dict[str, Dict[str, List[str]]]

Get current plotting data.

Returns:

  • dict: {"layer" : {"setup": [], "plotting": [], "teardown": []}} A dictionary of dictionaries containing instruction phases - setup, plotting, and teardown as an array of G-Code instruction strings per layer. Mostly used for testing purposes.

is_point_in_bounds

is_point_in_bounds(
self, x: float, y: float )
-> bool

Whether the point to be plotted is within the plotter bounds.

Args:

  • x (float) : The x-coordinate of the point to be plotted.
  • y (float) : The y-coordinate of the point to be plotted.

Returns:

  • bool : Whether the point to be plotted is within the plotter bounds.

preview

preview(
self, show_entire_plotting_area: bool = True )
-> None

Generate a preview image of the plotter's layers. Layers will be plotted in the order they've been added to the Plotter. Only looks at instructions during the plotting phase.

Args:

  • show_entire_plotting_area (bool, optional): Whether to show the entire plotting area or just the size of the art to be plotted. Defaults to True.

save

save(
self, clear_output_before_save: bool = True, include_layer_number: bool = True )
-> None

Save all the layers to the output directory defined by the output_directory Plotter param. Each layer will be saved as an individual file with the filename defined by {layer_number}_{layer_title}.gcode.

Args:

  • clear_output_before_save (bool, optional): Whether to remove all files from the artwork output directory (defined as [output_directory]/[title]) before saving. Defaults to True.
  • include_layer_number (bool, optional): Whether to prepend filename with layer_number. Defaults to True.