octoprint.slicing
In this module the slicing support of OctoPrint is encapsulated.
- class octoprint.slicing.SlicingProfile(slicer, name, data, display_name=None, description=None, default=False)
- A wrapper for slicing profiles, both meta data and actual profile data. - Parameters:
- slicer (str) – Identifier of the slicer this profile belongs to. 
- name (str) – Identifier of this slicing profile. 
- data (object) – Profile data, actual structure depends on individual slicer implementation. 
- display_name (str) – Displayable name for this slicing profile. 
- description (str) – Description of this slicing profile. 
- default (bool) – Whether this is the default slicing profile for the slicer. 
 
 
- class octoprint.slicing.TemporaryProfile(save_profile, profile, overrides=None)
- A wrapper for a temporary slicing profile to be used for a slicing job, based on a - SlicingProfilewith optional- overridesapplied through the supplied- save_profilemethod.- Usage example: - temporary = TemporaryProfile(my_slicer.save_slicer_profile, my_default_profile, overrides=my_overrides) with (temporary) as profile_path: my_slicer.do_slice(..., profile_path=profile_path, ...) - Parameters:
- save_profile (callable) – Method to use for saving the temporary profile, also responsible for applying the supplied - overrides. This will be called according to the method signature of- save_slicer_profile().
- profile (SlicingProfile) – The profile from which to derive the temporary profile. 
- overrides (dict) – Optional overrides to apply to the - profilefor creation of the temporary profile.
 
 
- class octoprint.slicing.SlicingManager(profile_path, printer_profile_manager)
- The - SlicingManageris responsible for managing available slicers and slicing profiles.- Parameters:
- profile_path (str) – Absolute path to the base folder where all slicing profiles are stored. 
- printer_profile_manager (PrinterProfileManager) – - PrinterProfileManagerinstance to use for accessing available printer profiles, most importantly the currently selected one.
 
 - all_profiles(slicer, require_configured=False)
- Retrieves all profiles for slicer - slicer.- If - require_configuredis set to True (default is False), only will return the profiles if the- sliceris already configured, otherwise a- SlicerNotConfiguredexception will be raised.- Parameters:
- slicer (str) – Identifier of the slicer for which to retrieve all slicer profiles 
- require_configured (boolean) – Whether to require the slicer - slicerto be already configured (True) or not (False, default). If False and the slicer is not yet configured, a- SlicerNotConfiguredexception will be raised.
 
- Returns:
- A dict of all - SlicingProfileinstances available for the slicer- slicer, mapped by the identifier.
- Return type:
- Raises:
- UnknownSlicer – The slicer - sliceris unknown.
- SlicerNotConfigured – The slicer - sliceris not configured and- require_configuredwas True.
 
 
 - cancel_slicing(slicer_name, source_path, dest_path)
- Cancels the slicing job on slicer - slicer_namefrom- source_pathto- dest_path.- Parameters:
- Raises:
- UnknownSlicer – The slicer specified via - slicer_nameis unknown.
 
 - property configured_slicers
- Returns: (list of str) Identifiers of all available configured slicers. 
 - property default_slicer
- Retrieves the default slicer. - Returns:
- (str) The identifier of the default slicer or Noneif the default slicer is not registered in the
- system. 
 
- (str) The identifier of the default slicer or 
 
 - delete_profile(slicer, name)
- Deletes the profile - namefor the specified- slicer.- If the profile does not exist, nothing will happen. - Parameters:
- Raises:
- UnknownSlicer – The slicer - sliceris unknown.
- CouldNotDeleteProfile – There was an error while deleting the profile. 
 
 
 - get_profile_path(slicer, name, must_exist=False)
- Retrieves the path to the profile named - namefor slicer- slicer.- If - must_existis set to True (defaults to False) a- UnknownProfileexception will be raised if the profile doesn’t exist yet.- Parameters:
- Returns:
- The absolute path to the profile identified by - namefor slicer- slicer.
- Return type:
- Raises:
- UnknownSlicer – The slicer - sliceris unknown.
- UnknownProfile – The profile named - namedoesn’t exist and- must_existwas True.
 
 
 - get_slicer(slicer, require_configured=True)
- Retrieves the slicer named - slicer. If- require_configuredis set to True (the default) an exception will be raised if the slicer is not yet configured.- Parameters:
- slicer (str) – Identifier of the slicer to return 
- require_configured (boolean) – Whether to raise an exception if the slicer has not been configured yet (True, the default), or also return an unconfigured slicer (False). 
 
- Raises:
- UnknownSlicer – The - sliceris unknown.
- SlicerNotConfigured – The - sliceris not yet configured and- require_configuredwas set to True.
 
 
 - get_slicer_profile_path(slicer)
- Retrieves the path where the profiles for slicer - slicerare stored.- Parameters:
- slicer (str) – Identifier of the slicer for which to retrieve the path. 
- Returns:
- The absolute path to the folder where the slicer’s profiles are stored. 
- Return type:
- Raises:
- UnknownSlicer – The slicer - sliceris unknown.
 
 - initialize()
- Initializes the slicing manager by loading and initializing all available - SlicerPluginimplementations.
 - load_profile(slicer, name, require_configured=True)
- Loads the slicing profile for - slicerwith the given profile- nameand returns it. If it can’t be loaded due to an- IOError- Nonewill be returned instead.- If - require_configuredis True (the default) a- SlicerNotConfiguredexception will be raised if the indicated- slicerhas not yet been configured.- Returns:
- The requested slicing profile or None if it could not be loaded. 
- Return type:
- Raises:
- UnknownSlicer – The slicer specified via - sliceris unknown.
- SlicerNotConfigured – The slicer specified via - slicerhas not yet been configured and- require_configuredwas True.
- UnknownProfile – The profile for slicer - slicernamed- namedoes not exist.
 
 
 - profiles_last_modified(slicer)
- Retrieves the last modification date of - slicer’s profiles.- Parameters:
- slicer (str) – the slicer for which to retrieve the last modification date 
- Returns:
- (float) the time stamp of the last modification of the slicer’s profiles 
 
 - property registered_slicers
- Returns: (list of str) Identifiers of all available slicers. 
 - reload_slicers()
- Retrieves all registered - SlicerPluginimplementations and registers them as available slicers.
 - save_profile(slicer, name, profile, overrides=None, allow_overwrite=True, display_name=None, description=None)
- Saves the slicer profile - profilefor slicer- slicerunder name- name.- profilemay be either a- SlicingProfileor a- dict.- If it’s a - SlicingProfile, its- slicer`,- nameand - if provided -- display_nameand- descriptionattributes will be overwritten with the supplied values.- If it’s a - dict, a new- SlicingProfileinstance will be created with the supplied meta data and the profile data as the- dataattribute.- Note - If the profile is the first profile to be saved for the slicer, it will automatically be marked as default. - Parameters:
- slicer (str) – Identifier of the slicer for which to save the - profile.
- name (str) – Identifier under which to save the - profile.
- profile (SlicingProfile or dict) – The - SlicingProfileor a- dictcontaining the profile data of the profile the save.
- overrides (dict) – Overrides to apply to the - profilebefore saving it.
- allow_overwrite (boolean) – If True (default) if a profile for the same - slicerof the same- namealready exists, it will be overwritten. Otherwise an exception will be thrown.
- display_name (str) – The name to display to the user for the profile. 
- description (str) – A description of the profile. 
 
- Returns:
- The saved profile (including the applied overrides). 
- Return type:
- Raises:
- ValueError – The supplied - profileis neither a- SlicingProfilenor a- dict.
- UnknownSlicer – The slicer - sliceris unknown.
- ProfileAlreadyExists – A profile with name - namealready exists for- slicerand- allow_overwriteis False.
 
 
 - set_default_profile(slicer, name, require_configured=False, require_exists=True)
- Sets the given profile as default profile for the slicer. - Parameters:
- slicer (str) – Identifier of the slicer for which to set the default profile. 
- name (str) – Identifier of the profile to set as default. 
- require_configured (bool) – Whether the slicer needs to be configured for the action to succeed. Defaults to false. Will raise a SlicerNotConfigured error if true and the slicer has not been configured yet. 
- require_exists (bool) – Whether the profile is required to exist in order to be set as default. Defaults to true. Will raise a UnknownProfile error if true and the profile is unknown. 
 
- Raises:
- UnknownSlicer – The slicer - sliceris unknown
- SlicerNotConfigured – The slicer - slicerhas not yet been configured and- require_configuredwas true.
- UnknownProfile – The profile - namewas unknown for slicer- slicerand- require_existswas true.
 
 
 - slice(slicer_name, source_path, dest_path, profile_name, callback, callback_args=None, callback_kwargs=None, overrides=None, on_progress=None, on_progress_args=None, on_progress_kwargs=None, printer_profile_id=None, position=None)
- Slices - source_pathto- dest_pathusing slicer- slicer_nameand slicing profile- profile_name. Since slicing happens asynchronously,- callbackwill be called when slicing has finished (either successfully or not), with- callback_argsand- callback_kwargssupplied.- If - callback_argsis left out, an empty argument list will be assumed for the callback. If- callback_kwargsis left out, likewise an empty keyword argument list will be assumed for the callback. Note that in any case the callback must support being called with the following optional keyword arguments:- _analysis
- If the slicer returned analysis data of the created machine code as part of its slicing result, this keyword argument will contain that data. 
- _error
- If there was an error while slicing this keyword argument will contain the error message as returned from the slicer. 
- _cancelled
- If the slicing job was cancelled this keyword argument will be set to True. 
 - Additionally callees may specify - overridesfor the specified slicing profile, e.g. a different extrusion temperature than defined in the profile or a different layer height.- With - on_progress,- on_progress_argsand- on_progress_kwargs, callees may specify a callback plus arguments and keyword arguments to call upon progress reports from the slicing job. The progress callback will be called with a keyword argument- _progresscontaining the current slicing progress as a value between 0 and 1 plus all additionally specified args and kwargs.- If a different printer profile than the currently selected one is to be used for slicing, its id can be provided via the keyword argument - printer_profile_id.- If the - source_pathis to be a sliced at a different position than the print bed center, this- positioncan be supplied as a dictionary defining the- xand- ycoordinate in print bed coordinates of the model’s center.- Parameters:
- slicer_name (str) – The identifier of the slicer to use for slicing. 
- source_path (str) – The absolute path to the source file to slice. 
- dest_path (str) – The absolute path to the destination file to slice to. 
- profile_name (str) – The name of the slicing profile to use. 
- callback (callable) – A callback to call after slicing has finished. 
- callback_args (list or tuple) – Arguments of the callback to call after slicing has finished. Defaults to an empty list. 
- callback_kwargs (dict) – Keyword arguments for the callback to call after slicing has finished, will be extended by - _analysis,- _erroror- _cancelledas described above! Defaults to an empty dictionary.
- overrides (dict) – Overrides for the printer profile to apply. 
- on_progress (callable) – Callback to call upon slicing progress. 
- on_progress_args (list or tuple) – Arguments of the progress callback. Defaults to an empty list. 
- on_progress_kwargs (dict) – Keyword arguments of the progress callback, will be extended by - _progressas described above! Defaults to an empty dictionary.
- printer_profile_id (str) – Identifier of the printer profile for which to slice, if another than the one currently selected is to be used. 
- position (dict) – Dictionary containing the - xand- ycoordinate in the print bed’s coordinate system of the sliced model’s center. If not provided the model will be positioned at the print bed’s center. Example:- dict(x=10,y=20).
 
- Raises:
- UnknownSlicer – The slicer specified via - slicer_nameis unknown.
- SlicerNotConfigured – The slice specified via - slicer_nameis not configured yet.
 
 
 - property slicing_enabled
- Returns: (boolean) True if there is at least one configured slicer available, False otherwise. 
 
octoprint.slicing.exceptions
Slicing related exceptions.
- class octoprint.slicing.exceptions.SlicingException
- Base exception of all slicing related exceptions. 
- class octoprint.slicing.exceptions.SlicingCancelled
- Bases: - SlicingException- Raised if a slicing job was cancelled. 
- class octoprint.slicing.exceptions.SlicerException(slicer, *args, **kwargs)
- Bases: - SlicingException- Base exception of all slicer related exceptions. - slicer
- Identifier of the slicer for which the exception was raised. 
 
- class octoprint.slicing.exceptions.UnknownSlicer(slicer, *args, **kwargs)
- Bases: - SlicerException- Raised if a slicer is unknown. 
- class octoprint.slicing.exceptions.SlicerNotConfigured(slicer, *args, **kwargs)
- Bases: - SlicerException- Raised if a slicer is not yet configured but must be configured to proceed. 
- class octoprint.slicing.exceptions.ProfileException(slicer, profile, *args, **kwargs)
- Base exception of all slicing profile related exceptions. - slicer
- Identifier of the slicer to which the profile belongs. 
 - profile
- Identifier of the profile for which the exception was raised. 
 
- class octoprint.slicing.exceptions.UnknownProfile(slicer, profile, *args, **kwargs)
- Bases: - ProfileException- Raised if a slicing profile does not exist but must exist to proceed. 
- class octoprint.slicing.exceptions.ProfileAlreadyExists(slicer, profile, *args, **kwargs)
- Bases: - ProfileException- Raised if a slicing profile already exists and must not be overwritten.