knit_script.knit_script_std_library.needles module

Functions that are automatically imported in knit-script.

This module provides essential needle-related utility functions that are automatically available in the knit script environment. These functions offer convenient ways to create needle objects and sort needle collections according to carriage pass requirements. The functions are designed to simplify common needle operations and provide intuitive interfaces for needle manipulation in knit script programs.

needle(is_front, index)[source]

Create a needle with the specified bed position and index.

This function provides a convenient way to create Needle objects with the specified bed position and index location. It serves as a factory function for needle creation and is commonly used throughout knit script programs for referencing specific needles on the knitting machine.

Parameters:
  • is_front (bool) – Whether the needle is on the front bed (True) or back bed (False). The front bed is typically the bed closest to the operator.

  • index (int) – The position index of the needle on the specified bed. This represents the physical position of the needle along the bed.

Returns:

A Needle object with the given position and bed configuration, ready for use in knitting operations.

Return type:

Needle

direction_sorted_needles(needles, direction=+, racking=0.0)[source]

Sort a list of needles according to the specified carriage pass direction.

This function orders needles in the sequence they would be encountered during a carriage pass in the given direction, taking into account the machine’s racking configuration. This sorting is essential for proper carriage pass execution, as needles must be processed in the correct order to avoid conflicts and ensure proper yarn handling.

The sorting algorithm considers both the direction of carriage movement and the racking offset between front and back needle beds. This ensures that needles are processed in the physically correct sequence as the carriage moves across the machine.

Parameters:
  • needles (list[Needle]) – The list of needles to sort. Can contain needles from both front and back beds.

  • direction (Carriage_Pass_Direction, optional) – The carriage pass direction to sort by. Determines whether needles are ordered for left-to-right or right-to-left carriage movement.

  • Carriage_Pass_Direction.Rightward. (Defaults to)

  • racking (float, optional) – The racking value of the machine, representing the relative offset between front and back needle beds.

  • 0.0. (This affects the relative positioning of front and back needles during sorting. Defaults to)

Returns:

A new list containing the needles sorted in the order they would be encountered during a carriage pass in the specified direction. The original list is not modified.

Return type:

list[Needle]

Note

The racking parameter is converted to an integer for the underlying sorting algorithm. This represents the standard practice in knitting machine operations where racking is typically specified in whole needle positions.