cam.utils#

BlenderCAM ‘utils.py’ © 2012 Vilem Novak

Main functionality of BlenderCAM. The functions here are called with operators defined in ‘ops.py’

Attributes#

Classes#

Functions#

opencamlib_version()

Return the version of the OpenCamLib library.

positionObject(operation)

Position an object based on specified operation parameters.

getBoundsWorldspace(obs[, use_modifiers])

Get the bounding box of a list of objects in world space.

getSplineBounds(ob, curve)

Get the bounding box of a spline object.

getOperationSources(o)

Get operation sources based on the geometry source type.

getBounds(o)

Calculate the bounding box for a given object.

getBoundsMultiple(operations)

Gets bounds of multiple operations for simulations or rest milling.

samplePathLow(o, ch1, ch2, dosample)

Generate a sample path between two channels.

sampleChunks(o, pathSamples, layers)

Sample chunks of paths based on the provided parameters.

sampleChunksNAxis(o, pathSamples, layers)

Sample chunks along a specified axis based on provided paths and layers.

extendChunks5axis(chunks, o)

Extend chunks with 5-axis cutter start and end points.

curveToShapely(cob[, use_modifiers])

Convert a curve object to Shapely polygons.

silhoueteOffset(context, offset[, style, mitrelimit])

Offset the silhouette of a curve or font object in Blender.

polygonBoolean(context, boolean_type)

Perform a boolean operation on selected polygons.

polygonConvexHull(context)

Generate the convex hull of a polygon from the given context.

Helix(r, np, zstart, pend, rev)

Generate a helix of points in 3D space.

comparezlevel(x)

overlaps(bb1, bb2)

Determine if one bounding box is a child of another.

connectChunksLow(chunks, o)

Connects chunks that are close to each other without lifting, sampling

getClosest(o, pos, chunks)

Find the closest chunk to a given position.

sortChunks(chunks, o[, last_pos])

Sort a list of chunks based on a specified strategy.

getVectorRight(lastv, verts)

Get the index of the vector that is most to the right based on angle.

cleanUpDict(ndict)

Remove lonely points from a dictionary.

dictRemove(dict, val)

Remove a key and its associated values from a dictionary.

addLoop(parentloop, start, end)

Add a loop to a parent loop structure.

cutloops(csource, parentloop, loops)

Cut loops from a source code segment.

getOperationSilhouete(operation)

Gets the silhouette for the given operation.

getObjectSilhouete(stype[, objects, use_modifiers])

Get the silhouette of objects based on the specified type.

getAmbient(o)

Calculate and update the ambient geometry based on the provided object.

getObjectOutline(radius, o, Offset)

Get the outline of a geometric object based on specified parameters.

addOrientationObject(o)

Set up orientation for a milling object.

removeOrientationObject(o)

Remove an orientation object from the current Blender scene.

addTranspMat(ob, mname, color, alpha)

Add a transparent material to a given object.

addMachineAreaObject()

Add a machine area object to the current Blender scene.

addMaterialAreaObject()

Add a material area object to the current Blender scene.

getContainer()

Get or create a container object for camera objects.

unique(L)

Return a list of unhashable elements in L, but without duplicates.

checkEqual(lst)

prepareIndexed(o)

Prepare and index objects in the given collection.

cleanupIndexed(operation)

Clean up indexed operations by updating object orientations and paths.

rotTo2axes(e, axescombination)

Converts an Orientation Object Rotation to Rotation Defined by 2

reload_paths(o)

Reload the camera path data from a pickle file.

updateMachine(self, context)

Update the machine with the given context.

updateMaterial(self, context)

Update the material in the given context.

updateOperation(self, context)

Update the visibility and selection state of camera operations in the

isValid(o, context)

Check the validity of a geometry source.

operationValid(self, context)

Validate the current camera operation in the given context.

isChainValid(chain, context)

Check the validity of a chain of operations within a given context.

updateOperationValid(self, context)

updateChipload(self, context)

Update the chipload based on feedrate, spindle RPM, and cutter

updateOffsetImage(self, context)

Refresh the Offset Image Tag for re-rendering.

updateZbufferImage(self, context)

Update the Z-buffer and offset image tags for recalculation.

updateStrategy(o, context)

Update the strategy of the given object.

updateCutout(o, context)

updateExact(o, context)

Update the state of an object for exact operations.

updateOpencamlib(o, context)

Update the OpenCAMLib settings for a given operation.

updateBridges(o, context)

Update the status of bridges.

updateRotation(o, context)

Update the rotation of a specified object in Blender.

updateRest(o, context)

Update the state of the object.

getStrategyList(scene, context)

Get a list of available strategies for operations.

update_material(self, context)

update_operation(self, context)

Update the camera operation based on the current context.

update_exact_mode(self, context)

Update the exact mode of the active camera operation.

update_opencamlib(self, context)

Update the OpenCamLib with the current active operation.

update_zbuffer_image(self, context)

Update the Z-buffer image based on the active camera operation.

check_operations_on_load(context)

Checks for any broken computations on load and resets them.

Add_Pocket(self, maxdepth, sname, new_cutter_diameter)

Add a pocket operation for the medial axis and profile cut.

Module Contents#

SHAPELY = True[source]#
opencamlib_version()[source]#

Return the version of the OpenCamLib library.

This function attempts to import the OpenCamLib library and returns its version. If the library is not available, it will return None. The function first tries to import the library using the name ‘ocl’, and if that fails, it attempts to import it using ‘opencamlib’ as an alias. If both imports fail, it returns None.

Returns:

The version of OpenCamLib if available, None otherwise.

Return type:

str or None

positionObject(operation)[source]#

Position an object based on specified operation parameters.

This function adjusts the location of a Blender object according to the provided operation settings. It calculates the bounding box of the object in world space and modifies its position based on the material’s center settings and specified z-positioning (BELOW, ABOVE, or CENTERED). The function also applies transformations to the object if it is not of type ‘CURVE’.

Parameters:

operation (OperationType) – An object containing parameters for positioning, including object_name, use_modifiers, and material settings.

getBoundsWorldspace(obs, use_modifiers=False)[source]#

Get the bounding box of a list of objects in world space.

This function calculates the minimum and maximum coordinates that encompass all the specified objects in the 3D world space. It iterates through each object, taking into account their transformations and modifiers if specified. The function supports different object types, including meshes and fonts, and handles the conversion of font objects to mesh format for accurate bounding box calculations.

Parameters:
  • obs (list) – A list of Blender objects to calculate bounds for.

  • use_modifiers (bool) – If True, apply modifiers to the objects before calculating bounds. Defaults to False.

Returns:

A tuple containing the minimum and maximum coordinates

in the format (minx, miny, minz, maxx, maxy, maxz).

Return type:

tuple

Raises:

CamException – If an object type does not support CAM operations.

getSplineBounds(ob, curve)[source]#

Get the bounding box of a spline object.

This function calculates the minimum and maximum coordinates (x, y, z) of the given spline object by iterating through its bezier points and regular points. It transforms the local coordinates to world coordinates using the object’s transformation matrix. The resulting bounds can be used for various purposes, such as collision detection or rendering.

Parameters:
  • ob (Object) – The object containing the spline whose bounds are to be calculated.

  • curve (Curve) – The curve object that contains the bezier points and regular points.

Returns:

A tuple containing the minimum and maximum coordinates in the format (minx, miny, minz, maxx, maxy, maxz).

Return type:

tuple

getOperationSources(o)[source]#

Get operation sources based on the geometry source type.

This function retrieves and sets the operation sources for a given object based on its geometry source type. It handles three types of geometry sources: ‘OBJECT’, ‘COLLECTION’, and ‘IMAGE’. For ‘OBJECT’, it selects the specified object and applies rotations if enabled. For ‘COLLECTION’, it retrieves all objects within the specified collection. For ‘IMAGE’, it sets a specific optimization flag. Additionally, it determines whether the objects are curves or meshes based on the geometry source.

Parameters:

o (Object) – An object containing properties such as geometry_source, object_name, collection_name, rotation_A, rotation_B, enable_A, enable_B, old_rotation_A, old_rotation_B, A_along_x, and optimisation.

Returns:

This function does not return a value but modifies the

properties of the input object.

Return type:

None

getBounds(o)[source]#

Calculate the bounding box for a given object.

This function determines the minimum and maximum coordinates of an object’s bounding box based on its geometry source. It handles different geometry types such as OBJECT, COLLECTION, and CURVE. The function also considers material properties and image cropping if applicable. The bounding box is adjusted according to the object’s material settings and the optimization parameters defined in the object.

Parameters:

o (object) – An object containing geometry and material properties, as well as optimization settings.

Returns:

This function modifies the input object in place and does not return a

value.

Return type:

None

getBoundsMultiple(operations)[source]#

Gets bounds of multiple operations for simulations or rest milling.

This function iterates through a list of operations to determine the minimum and maximum bounds in three-dimensional space (x, y, z). It initializes the bounds to extreme values and updates them based on the bounds of each operation. The function is primarily intended for use in simulations or rest milling processes, although it is noted that the implementation may not be optimal.

Parameters:

operations (list) – A list of operation objects, each containing ‘min’ and ‘max’ attributes with ‘x’, ‘y’, and ‘z’ coordinates.

Returns:

A tuple containing the minimum and maximum bounds in the

order (minx, miny, minz, maxx, maxy, maxz).

Return type:

tuple

samplePathLow(o, ch1, ch2, dosample)[source]#

Generate a sample path between two channels.

This function computes a series of points that form a path between two given channels. It calculates the direction vector from the end of the first channel to the start of the second channel and generates points along this vector up to a specified distance. If sampling is enabled, it modifies the z-coordinate of the generated points based on the cutter shape or image sampling, ensuring that the path accounts for any obstacles or features in the environment.

Parameters:
  • o – An object containing optimization parameters and properties related to the path generation.

  • ch1 – The first channel object, which provides a point for the starting location of the path.

  • ch2 – The second channel object, which provides a point for the ending location of the path.

  • dosample (bool) – A flag indicating whether to perform sampling along the generated path.

Returns:

An object representing the generated path points.

Return type:

camPathChunk

async sampleChunks(o, pathSamples, layers)[source]#

Sample chunks of paths based on the provided parameters.

This function processes the given path samples and layers to generate chunks of points that represent the sampled paths. It takes into account various optimization settings and strategies to determine how the points are sampled and organized into layers. The function handles different scenarios based on the object’s properties and the specified layers, ensuring that the resulting chunks are correctly structured for further processing.

Parameters:
  • o (object) – An object containing various properties and settings related to the sampling process.

  • pathSamples (list) – A list of path samples to be processed.

  • layers (list) – A list of layers defining the z-coordinate ranges for sampling.

Returns:

A list of sampled chunks, each containing points that represent

the sampled paths.

Return type:

list

async sampleChunksNAxis(o, pathSamples, layers)[source]#

Sample chunks along a specified axis based on provided paths and layers.

This function processes a set of path samples and organizes them into chunks according to specified layers. It prepares the collision world if necessary, updates the cutter’s rotation based on the path samples, and handles the sampling of points along the paths. The function also manages the relationships between the sampled points and their respective layers, ensuring that the correct points are added to each chunk. The resulting chunks can be used for further processing in a 3D environment.

Parameters:
  • o (object) – An object containing properties such as min/max coordinates, cutter shape, and other relevant parameters.

  • pathSamples (list) – A list of path samples, each containing start points, end points, and rotations.

  • layers (list) – A list of layer definitions that specify the boundaries for sampling.

Returns:

A list of sampled chunks organized by layers.

Return type:

list

extendChunks5axis(chunks, o)[source]#

Extend chunks with 5-axis cutter start and end points.

This function modifies the provided chunks by appending calculated start and end points for a cutter based on the specified orientation and movement parameters. It determines the starting position of the cutter based on the machine’s settings and the object’s movement constraints. The function iterates through each point in the chunks and updates their start and end points accordingly.

Parameters:
  • chunks (list) – A list of chunk objects that will be modified.

  • o (object) – An object containing movement and orientation data.

curveToShapely(cob, use_modifiers=False)[source]#

Convert a curve object to Shapely polygons.

This function takes a curve object and converts it into a list of Shapely polygons. It first breaks the curve into chunks and then transforms those chunks into Shapely-compatible polygon representations. The use_modifiers parameter allows for additional processing of the curve before conversion, depending on the specific requirements of the application.

Parameters:
  • cob – The curve object to be converted.

  • use_modifiers (bool) – A flag indicating whether to apply modifiers during the conversion process. Defaults to False.

Returns:

A list of Shapely polygons created from the curve object.

Return type:

list

silhoueteOffset(context, offset, style=1, mitrelimit=1.0)[source]#

Offset the silhouette of a curve or font object in Blender.

This function takes an active curve or font object in Blender and creates an offset silhouette based on the specified parameters. It first retrieves the silhouette of the object and then applies a buffer operation to create the offset shape. The resulting shape is then converted back into a curve object in the Blender scene.

Parameters:
  • context (bpy.context) – The current Blender context.

  • offset (float) – The distance to offset the silhouette.

  • style (int?) – The join style for the offset. Defaults to 1.

  • mitrelimit (float?) – The mitre limit for the offset. Defaults to 1.0.

Returns:

A dictionary indicating the operation is finished.

Return type:

dict

polygonBoolean(context, boolean_type)[source]#

Perform a boolean operation on selected polygons.

This function takes the active object and applies a specified boolean operation (UNION, DIFFERENCE, or INTERSECT) with respect to other selected objects in the Blender context. It first converts the polygons of the active object and the selected objects into a Shapely MultiPolygon. Depending on the boolean type specified, it performs the corresponding boolean operation and then converts the result back into a Blender curve.

Parameters:
  • context (bpy.context) – The Blender context containing scene and object data.

  • boolean_type (str) – The type of boolean operation to perform. Must be one of ‘UNION’, ‘DIFFERENCE’, or ‘INTERSECT’.

Returns:

A dictionary indicating the operation result, typically {‘FINISHED’}.

Return type:

dict

polygonConvexHull(context)[source]#

Generate the convex hull of a polygon from the given context.

This function duplicates the current object, joins it, and converts it into a 3D mesh. It then extracts the X and Y coordinates of the vertices to create a MultiPoint data structure using Shapely. Finally, it computes the convex hull of these points and converts the result back into a curve named ‘ConvexHull’. Temporary objects created during this process are deleted to maintain a clean workspace.

Parameters:

context – The context in which the operation is performed, typically related to Blender’s current state.

Returns:

A dictionary indicating the operation’s completion status.

Return type:

dict

Helix(r, np, zstart, pend, rev)[source]#

Generate a helix of points in 3D space.

This function calculates a series of points that form a helix based on the specified parameters. It starts from a given radius and z-coordinate, and generates points by rotating around the z-axis while moving linearly along the z-axis. The number of points generated is determined by the number of turns (revolutions) and the number of points per revolution.

Parameters:
  • r (float) – The radius of the helix.

  • np (int) – The number of points per revolution.

  • zstart (float) – The starting z-coordinate for the helix.

  • pend (tuple) – A tuple containing the x, y, and z coordinates of the endpoint.

  • rev (int) – The number of revolutions to complete.

Returns:

A list of tuples representing the coordinates of the points in the

helix.

Return type:

list

comparezlevel(x)[source]#
overlaps(bb1, bb2)[source]#

Determine if one bounding box is a child of another.

This function checks if the first bounding box (bb1) is completely contained within the second bounding box (bb2). It does this by comparing the coordinates of both bounding boxes to see if all corners of bb1 are within the bounds of bb2.

Parameters:
  • bb1 (tuple) – A tuple representing the coordinates of the first bounding box in the format (x_min, y_min, x_max, y_max).

  • bb2 (tuple) – A tuple representing the coordinates of the second bounding box in the format (x_min, y_min, x_max, y_max).

Returns:

True if bb1 is a child of bb2, otherwise False.

Return type:

bool

async connectChunksLow(chunks, o)[source]#

Connects chunks that are close to each other without lifting, sampling them ‘low’.

This function processes a list of chunks and connects those that are within a specified distance based on the provided options. It takes into account various strategies for connecting the chunks, including ‘CARVE’, ‘PENCIL’, and ‘MEDIAL_AXIS’, and adjusts the merging distance accordingly. The function also handles specific movement settings, such as whether to stay low or to merge distances, and may resample chunks if certain optimization conditions are met.

Parameters:
  • chunks (list) – A list of chunk objects to be connected.

  • o (object) – An options object containing movement and strategy parameters.

Returns:

A list of connected chunk objects.

Return type:

list

getClosest(o, pos, chunks)[source]#

Find the closest chunk to a given position.

This function iterates through a list of chunks and determines which chunk is closest to the specified position. It checks if each chunk’s children are sorted before calculating the distance. The chunk with the minimum distance to the given position is returned.

Parameters:
  • o – An object representing the origin point.

  • pos – A position to which the closest chunk is calculated.

  • chunks (list) – A list of chunk objects to evaluate.

Returns:

The closest chunk object to the specified position, or None if no valid

chunk is found.

Return type:

Chunk

async sortChunks(chunks, o, last_pos=None)[source]#

Sort a list of chunks based on a specified strategy.

This function sorts a list of chunks according to the provided options and the current position. It utilizes a recursive approach to find the closest chunk to the current position and adapts its distance if it has not been sorted before. The function also handles progress updates asynchronously and adjusts the recursion limit to accommodate deep recursion scenarios.

Parameters:
  • chunks (list) – A list of chunk objects to be sorted.

  • o (object) – An options object that contains sorting strategy and other parameters.

  • last_pos (tuple?) – The last known position as a tuple of coordinates. Defaults to None, which initializes the position to (0, 0, 0).

Returns:

A sorted list of chunk objects.

Return type:

list

getVectorRight(lastv, verts)[source]#

Get the index of the vector that is most to the right based on angle.

This function calculates the angle between a reference vector (formed by the last two vectors in lastv) and each vector in the verts list. It identifies the vector that has the smallest angle with respect to the reference vector, indicating that it is the most rightward vector in relation to the specified direction.

Parameters:
  • lastv (list) – A list containing two vectors, where each vector is represented as a tuple or list of coordinates.

  • verts (list) – A list of vectors represented as tuples or lists of coordinates.

Returns:

The index of the vector in verts that is most to the right

based on the calculated angle.

Return type:

int

cleanUpDict(ndict)[source]#

Remove lonely points from a dictionary.

This function iterates over the keys of the provided dictionary and removes any entries that contain one or fewer associated values. It continues to check for and remove “lonely” points until no more can be found. The process is repeated until all such entries are eliminated from the dictionary.

Parameters:

ndict (dict) – A dictionary where keys are associated with lists of values.

Returns:

This function modifies the input dictionary in place and does not return

a value.

Return type:

None

dictRemove(dict, val)[source]#

Remove a key and its associated values from a dictionary.

This function takes a dictionary and a key (val) as input. It iterates through the list of values associated with the given key and removes the key from each of those values’ lists. Finally, it removes the key itself from the dictionary.

Parameters:
  • dict (dict) – A dictionary where the key is associated with a list of values.

  • val – The key to be removed from the dictionary and from the lists of its associated values.

addLoop(parentloop, start, end)[source]#

Add a loop to a parent loop structure.

This function recursively checks if the specified start and end values can be added as a new loop to the parent loop. If an existing loop encompasses the new loop, it will call itself on that loop. If no such loop exists, it appends the new loop defined by the start and end values to the parent loop’s list of loops.

Parameters:
  • parentloop (list) – A list representing the parent loop, where the third element is a list of child loops.

  • start (int) – The starting value of the new loop to be added.

  • end (int) – The ending value of the new loop to be added.

Returns:

This function modifies the parentloop in place and does not

return a value.

Return type:

None

cutloops(csource, parentloop, loops)[source]#

Cut loops from a source code segment.

This function takes a source code segment and a parent loop defined by its start and end indices, along with a list of nested loops. It creates a copy of the source code segment and removes the specified nested loops from it. The modified segment is then appended to the provided list of loops. The function also recursively processes any nested loops found within the parent loop.

Parameters:
  • csource (str) – The source code from which loops will be cut.

  • parentloop (tuple) – A tuple containing the start index, end index, and a list of nested loops. The list of nested loops should contain tuples with start and end indices for each loop.

  • loops (list) – A list that will be populated with the modified source code segments after removing the specified loops.

Returns:

This function modifies the loops list in place and does not return a

value.

Return type:

None

getOperationSilhouete(operation)[source]#

Gets the silhouette for the given operation.

This function determines the silhouette of an operation using image thresholding techniques. It handles different geometry sources, such as objects or images, and applies specific methods based on the type of geometry. If the geometry source is ‘OBJECT’ or ‘COLLECTION’, it checks whether to process curves or not. The function also considers the number of faces in mesh objects to decide on the appropriate method for silhouette extraction.

Parameters:

operation (Operation) – An object containing the necessary data

Returns:

The computed silhouette for the operation.

Return type:

Silhouette

getObjectSilhouete(stype, objects=None, use_modifiers=False)[source]#

Get the silhouette of objects based on the specified type.

This function computes the silhouette of a given set of objects in Blender based on the specified type. It can handle both curves and mesh objects, converting curves to polygon format and calculating the silhouette for mesh objects. The function also considers the use of modifiers if specified. The silhouette is generated by processing the geometry of the objects and returning a Shapely representation of the silhouette.

Parameters:
  • stype (str) – The type of silhouette to generate (‘CURVES’ or ‘OBJECTS’).

  • objects (list?) – A list of Blender objects to process. Defaults to None.

  • use_modifiers (bool?) – Whether to apply modifiers to the objects. Defaults to False.

Returns:

The computed silhouette as a Shapely MultiPolygon.

Return type:

shapely.geometry.MultiPolygon

getAmbient(o)[source]#

Calculate and update the ambient geometry based on the provided object.

This function computes the ambient shape for a given object based on its properties, such as cutter restrictions and ambient behavior. It determines the appropriate radius and creates the ambient geometry either from the silhouette or as a polygon defined by the object’s minimum and maximum coordinates. If a limit curve is specified, it will also intersect the ambient shape with the limit polygon.

Parameters:

o (object) – An object containing properties that define the ambient behavior, cutter restrictions, and limit curve.

Returns:

The function updates the ambient property of the object in place.

Return type:

None

getObjectOutline(radius, o, Offset)[source]#

Get the outline of a geometric object based on specified parameters.

This function generates an outline for a given geometric object by applying a buffer operation to its polygons. The buffer radius can be adjusted based on the radius parameter, and the operation can be offset based on the Offset flag. The function also considers whether the polygons should be merged or not, depending on the properties of the object o.

Parameters:
  • radius (float) – The radius for the buffer operation.

  • o (object) – An object containing properties that influence the outline generation.

  • Offset (bool) – A flag indicating whether to apply a positive or negative offset.

Returns:

The resulting outline of the geometric object as a MultiPolygon.

Return type:

MultiPolygon

addOrientationObject(o)[source]#

Set up orientation for a milling object.

This function creates an orientation object in the Blender scene for 4-axis and 5-axis milling operations. It checks if an orientation object with the specified name already exists, and if not, it adds a new empty object of type ‘ARROWS’. The function then configures the rotation locks and initial rotation angles based on the specified machine axes and rotary axis.

Parameters:

o (object) – An object containing properties such as name,

removeOrientationObject(o)[source]#

Remove an orientation object from the current Blender scene.

This function constructs the name of the orientation object based on the name of the provided object and attempts to find and delete it from the Blender scene. If the orientation object exists, it will be removed using the delob function.

Parameters:

o (Object) – The object whose orientation object is to be removed.

addTranspMat(ob, mname, color, alpha)[source]#

Add a transparent material to a given object.

This function checks if a material with the specified name already exists in the Blender data. If it does, it retrieves that material; if not, it creates a new material with the given name and enables the use of nodes. The function then assigns the material to the specified object, ensuring that it is applied correctly whether the object already has materials or not.

Parameters:
  • ob (bpy.types.Object) – The Blender object to which the material will be assigned.

  • mname (str) – The name of the material to be added or retrieved.

  • color (tuple) – The RGBA color value for the material (not used in this function).

  • alpha (float) – The transparency value for the material (not used in this function).

addMachineAreaObject()[source]#

Add a machine area object to the current Blender scene.

This function checks if a machine object named ‘CAM_machine’ already exists in the current scene. If it does not exist, it creates a new cube mesh object, applies transformations, and modifies its geometry to represent a machine area. The function ensures that the scene’s unit settings are set to metric before creating the object and restores the original unit settings afterward. It also configures the display properties of the object for better visibility in the scene. The function operates within Blender’s context and utilizes various Blender operations to create and modify the mesh. It also handles the selection state of the active object.

addMaterialAreaObject()[source]#

Add a material area object to the current Blender scene.

This function checks if a material area object named ‘CAM_material’ already exists in the current scene. If it does, it retrieves that object; if not, it creates a new cube mesh object to serve as the material area. The dimensions and location of the object are set based on the current camera operation’s bounds. The function also applies transformations to ensure the object’s location and dimensions are correctly set. The created or retrieved object is configured to be non- renderable and non-selectable in the viewport, while still being selectable for operations. This is useful for visualizing the working area of the camera without affecting the render output. Raises: None

getContainer()[source]#

Get or create a container object for camera objects.

This function checks if a container object named ‘CAM_OBJECTS’ exists in the current Blender scene. If it does not exist, the function creates a new empty object of type ‘PLAIN_AXES’, names it ‘CAM_OBJECTS’, and sets its location to the origin (0, 0, 0). The newly created container is also hidden. If the container already exists, it simply retrieves and returns that object.

Returns:

The container object for camera objects, either newly created or

existing.

Return type:

bpy.types.Object

class Point(x, y, z)[source]#
unique(L)[source]#

Return a list of unhashable elements in L, but without duplicates.

This function processes a list of lists, specifically designed to handle unhashable elements. It sorts the input list and removes duplicates by comparing the elements based on their coordinates. The function counts the number of duplicate vertices and the number of collinear points along the Z-axis.

Parameters:

L (list) – A list of lists, where each inner list represents a point

Returns:

A tuple containing two integers:
  • The first integer represents the count of duplicate vertices.

  • The second integer represents the count of Z-collinear points.

Return type:

tuple

checkEqual(lst)[source]#
prepareIndexed(o)[source]#

Prepare and index objects in the given collection.

This function stores the world matrices and parent relationships of the objects in the provided collection. It then clears the parent relationships while maintaining their transformations, sets the orientation of the objects based on a specified orientation object, and finally re-establishes the parent-child relationships with the orientation object. The function also resets the location and rotation of the orientation object to the origin.

Parameters:

o (ObjectCollection) – A collection of objects to be prepared and indexed.

cleanupIndexed(operation)[source]#

Clean up indexed operations by updating object orientations and paths.

This function takes an operation object and updates the orientation of a specified object in the scene based on the provided orientation matrix. It also sets the location and rotation of a camera path object to match the updated orientation. Additionally, it reassigns parent-child relationships for the objects involved in the operation and updates their world matrices.

Parameters:

operation (OperationType) – An object containing the necessary data

rotTo2axes(e, axescombination)[source]#

Converts an Orientation Object Rotation to Rotation Defined by 2 Rotational Axes on the Machine.

This function takes an orientation object and a specified axes combination, and computes the angles of rotation around two axes based on the provided orientation. It supports different axes combinations for indexed machining. The function utilizes vector mathematics to determine the angles of rotation and returns them as a tuple.

Parameters:
  • e (OrientationObject) – The orientation object representing the rotation.

  • axescombination (str) – A string indicating the axes combination (‘CA’ or ‘CB’).

Returns:

A tuple containing two angles (float) representing the rotation around the specified axes.

Return type:

tuple

reload_paths(o)[source]#

Reload the camera path data from a pickle file.

This function retrieves the camera path data associated with the given object o. It constructs a new mesh from the path vertices and updates the object’s properties with the loaded data. If a previous path mesh exists, it is removed to avoid memory leaks. The function also handles the creation of a new mesh object if one does not already exist in the current scene.

Parameters:

o (Object) – The object for which the camera path is being

USE_PROFILER = False[source]#
was_hidden_dict[source]#
_IS_LOADING_DEFAULTS = False[source]#
updateMachine(self, context)[source]#

Update the machine with the given context.

This function is responsible for updating the machine state based on the provided context. It prints a message indicating that the update process has started. If the global variable _IS_LOADING_DEFAULTS is not set to True, it proceeds to add a machine area object.

Parameters:

context – The context in which the machine update is being performed.

updateMaterial(self, context)[source]#

Update the material in the given context.

This method is responsible for updating the material based on the provided context. It performs necessary operations to ensure that the material is updated correctly. Currently, it prints a message indicating the update process and calls the addMaterialAreaObject function to handle additional material area object updates.

Parameters:

context – The context in which the material update is performed.

updateOperation(self, context)[source]#

Update the visibility and selection state of camera operations in the scene.

This method manages the visibility of objects associated with camera operations based on the current active operation. If the ‘hide_all_others’ flag is set to true, it hides all other objects except for the currently active one. If the flag is false, it restores the visibility of previously hidden objects. The method also attempts to highlight the currently active object in the 3D view and make it the active object in the scene.

Parameters:

context (bpy.types.Context) – The context containing the current scene and

isValid(o, context)[source]#

Check the validity of a geometry source.

This function verifies if the provided geometry source is valid based on its type. It checks for three types of geometry sources: ‘OBJECT’, ‘COLLECTION’, and ‘IMAGE’. For ‘OBJECT’, it ensures that the object name ends with ‘_cut_bridges’ or exists in the Blender data objects. For ‘COLLECTION’, it checks if the collection name exists and contains objects. For ‘IMAGE’, it verifies if the source image name exists in the Blender data images.

Parameters:
  • o (object) – An object containing geometry source information, including attributes like geometry_source, object_name, collection_name, and source_image_name.

  • context – The context in which the validation is performed (not used in this function).

Returns:

True if the geometry source is valid, False otherwise.

Return type:

bool

operationValid(self, context)[source]#

Validate the current camera operation in the given context.

This method checks if the active camera operation is valid based on the current scene context. It updates the operation’s validity status and provides warnings if the source object is invalid. Additionally, it configures specific settings related to image geometry sources.

Parameters:

context (Context) – The context containing the scene and camera operations.

isChainValid(chain, context)[source]#

Check the validity of a chain of operations within a given context.

This function verifies if all operations in the provided chain are valid according to the current scene context. It first checks if the chain contains any operations. If it does, it iterates through each operation in the chain and checks if it exists in the scene’s camera operations. If an operation is not found or is deemed invalid, the function returns a tuple indicating the failure and provides an appropriate error message. If all operations are valid, it returns a success indication.

Parameters:
  • chain (Chain) – The chain of operations to validate.

  • context (Context) – The context containing the scene and camera operations.

Returns:

A tuple containing a boolean indicating validity and an error message

(if any). The first element is True if valid, otherwise False. The second element is an error message string.

Return type:

tuple

updateOperationValid(self, context)[source]#
updateChipload(self, context)[source]#

Update the chipload based on feedrate, spindle RPM, and cutter parameters.

This function calculates the chipload using the formula: chipload = feedrate / (spindle_rpm * cutter_flutes). It also attempts to account for chip thinning when cutting at less than 50% cutter engagement with cylindrical end mills by combining two formulas. The first formula provides the nominal chipload based on standard recommendations, while the second formula adjusts for the cutter diameter and distance between paths. The current implementation may not yield consistent results, and there are concerns regarding the correctness of the units used in the calculations. Further review and refinement of this function may be necessary to improve accuracy and reliability.

Parameters:

context – The context in which the update is performed (not used in this implementation).

Returns:

This function does not return a value; it updates the chipload in place.

Return type:

None

updateOffsetImage(self, context)[source]#

Refresh the Offset Image Tag for re-rendering.

This method updates the chip load and marks the offset image tag for re- rendering. It sets the changed attribute to True and indicates that the offset image tag needs to be updated.

Parameters:

context – The context in which the update is performed.

updateZbufferImage(self, context)[source]#

Update the Z-buffer and offset image tags for recalculation.

This method modifies the internal state to indicate that the Z-buffer image and offset image tags need to be updated during the calculation process. It sets the changed attribute to True and marks the relevant tags for updating. Additionally, it calls the getOperationSources function to ensure that the necessary operation sources are retrieved.

Parameters:

context – The context in which the update is being performed.

updateStrategy(o, context)[source]#

Update the strategy of the given object.

This function modifies the state of the object o by setting its changed attribute to True and printing a message indicating that the strategy is being updated. Depending on the value of machine_axes and strategy4axis, it either adds or removes an orientation object associated with o. Finally, it calls the updateExact function to perform further updates based on the provided context.

Parameters:
  • o (object) – The object whose strategy is to be updated.

  • context (object) – The context in which the update is performed.

updateCutout(o, context)[source]#
updateExact(o, context)[source]#

Update the state of an object for exact operations.

This function modifies the properties of the given object o to indicate that an update is required. It sets various flags related to the object’s state and checks the optimization settings. If the optimization is set to use exact mode, it further checks the strategy and inverse properties to determine if exact mode can be used. If not, it disables the use of OpenCamLib.

Parameters:
  • o (object) – The object to be updated, which contains properties related

  • context (object) – The context in which the update is being performed.

Returns:

This function does not return a value.

Return type:

None

updateOpencamlib(o, context)[source]#

Update the OpenCAMLib settings for a given operation.

This function modifies the properties of the provided operation object based on its current strategy and optimization settings. If the operation’s strategy is either ‘POCKET’ or ‘MEDIAL_AXIS’, and if OpenCAMLib is being used for optimization, it disables the use of both exact optimization and OpenCAMLib, indicating that the current operation cannot utilize OpenCAMLib.

Parameters:
  • o (object) – The operation object containing optimization and strategy settings.

  • context (object) – The context in which the operation is being updated.

Returns:

This function does not return any value.

Return type:

None

updateBridges(o, context)[source]#

Update the status of bridges.

This function marks the bridge object as changed, indicating that an update has occurred. It prints a message to the console for logging purposes. The function takes in an object and a context, but the context is not utilized within the function.

Parameters:
  • o (object) – The bridge object that needs to be updated.

  • context (object) – Additional context for the update, not used in this function.

updateRotation(o, context)[source]#

Update the rotation of a specified object in Blender.

This function modifies the rotation of a Blender object based on the properties of the provided object ‘o’. It checks which rotations are enabled and applies the corresponding rotation values to the active object in the scene. The rotation can be aligned either along the X or Y axis, depending on the configuration of ‘o’.

Parameters:
  • o (object) – An object containing rotation settings and flags.

  • context (object) – The context in which the operation is performed.

updateRest(o, context)[source]#

Update the state of the object.

This function modifies the given object by setting its ‘changed’ attribute to True. It also prints a message indicating that the update operation has been performed.

Parameters:
  • o (object) – The object to be updated.

  • context (object) – The context in which the update is being performed.

getStrategyList(scene, context)[source]#

Get a list of available strategies for operations.

This function retrieves a predefined list of operation strategies that can be used in the context of a 3D scene. Each strategy is represented as a tuple containing an identifier, a user-friendly name, and a description of the operation. The list includes various operations such as cutouts, pockets, drilling, and more. If experimental features are enabled in the preferences, additional experimental strategies may be included in the returned list.

Parameters:
  • scene – The current scene context.

  • context – The current context in which the operation is being performed.

Returns:

A list of tuples, each containing the strategy identifier,

name, and description.

Return type:

list

update_material(self, context)[source]#
update_operation(self, context)[source]#

Update the camera operation based on the current context.

This function retrieves the active camera operation from the Blender context and updates it using the updateRest function. It accesses the active operation from the scene’s camera operations and passes the current context to the updating function.

Parameters:

context – The context in which the operation is being updated.

update_exact_mode(self, context)[source]#

Update the exact mode of the active camera operation.

This function retrieves the currently active camera operation from the Blender context and updates its exact mode using the updateExact function. It accesses the active operation through the cam_operations list in the current scene and passes the active operation along with the current context to the updateExact function.

Parameters:

context – The context in which the update is performed.

update_opencamlib(self, context)[source]#

Update the OpenCamLib with the current active operation.

This function retrieves the currently active camera operation from the Blender context and updates the OpenCamLib accordingly. It accesses the active operation from the scene’s camera operations and passes it along with the current context to the update function.

Parameters:

context – The context in which the operation is being performed, typically provided by Blender’s internal API.

update_zbuffer_image(self, context)[source]#

Update the Z-buffer image based on the active camera operation.

This function retrieves the currently active camera operation from the Blender context and updates the Z-buffer image accordingly. It accesses the scene’s camera operations and invokes the updateZbufferImage function with the active operation and context.

Parameters:

context (bpy.context) – The current Blender context.

check_operations_on_load(context)[source]#

Checks for any broken computations on load and resets them.

This function verifies the presence of necessary Blender add-ons and installs any that are missing. It also resets any ongoing computations in camera operations and sets the interface level to the previously used level when loading a new file. If the add-on has been updated, it copies the necessary presets from the source to the target directory. Additionally, it checks for updates to the camera plugin and updates operation presets if required.

Parameters:

context – The context in which the function is executed, typically containing information about the current Blender environment.

Add_Pocket(self, maxdepth, sname, new_cutter_diameter)[source]#

Add a pocket operation for the medial axis and profile cut.

This function first deselects all objects in the scene and then checks for any existing medial pocket objects, deleting them if found. It verifies whether a medial pocket operation already exists in the camera operations. If it does not exist, it creates a new pocket operation with the specified parameters. The function also modifies the selected object’s silhouette offset based on the new cutter diameter.

Parameters:
  • maxdepth (float) – The maximum depth of the pocket to be created.

  • sname (str) – The name of the object to which the pocket will be added.

  • new_cutter_diameter (float) – The diameter of the new cutter to be used.