Module functions
- cadscript.make_box(sizex: Tuple[float, float] | float, sizey: Tuple[float, float] | float, sizez: Tuple[float, float] | float, *, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) Body [source]
Create a box-shaped body with the given dimensions.
- Parameters:
sizex (DimensionDefinitionType) – The size of the box along the x-axis.
sizey (DimensionDefinitionType) – The size of the box along the y-axis.
sizez (DimensionDefinitionType) – The size of the box along the z-axis.
center (CenterDefinitionType, optional) – Whether to center the box at the origin. If False, the box will start from the origin. Can also be “X”, “Y” or “Z” to center in only one direction or “XY”, “XZ”, “YZ” to center in two directions. Defaults to True which centers the box in all directions.
- Returns:
The created box-shaped body.
- Return type:
- cadscript.make_sphere(*, r: float | None = None, radius: float | None = None, d: float | None = None, diameter: float | None = None, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) Body [source]
Create a spherical body with the given radius or diameter.
- Parameters:
r (float, optional) – The radius of the sphere (alternative to ‘radius’, ‘d’ or ‘diameter’).
radius (float, optional) – The radius of the sphere (alternative to ‘r’, ‘d’ or ‘diameter’).
d (float, optional) – The diameter of the sphere (alternative to ‘r’, ‘radius’ or ‘diameter’).
diameter (float, optional) – The diameter of the sphere (alternative to ‘r’, ‘radius’ or ‘d’).
center (CenterDefinitionType, optional) – Whether to center the box at the sphere. If False, the box will start from the origin. Can also be “X”, “Y” or “Z” to center in only one direction or “XY”, “XZ”, “YZ” to center in two directions. Defaults to True which centers the box in all directions.
- Returns:
The created spherical body.
- Return type:
- cadscript.make_cylinder(*, h: float | None = None, height: float | None = None, r: float | None = None, radius: float | None = None, d: float | None = None, diameter: float | None = None, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True, direction: Literal['X', 'Y', 'Z'] | None = 'Z') Body [source]
Create a cylinder with the given height and radius or diameter. The cylinder is aligned along the z-axis, unless specified otherwise using the ‘direction’ parameter.
- Parameters:
h (float, optional) – The height of the cylinder (alternative to ‘height’ parameter).
height (float, optional) – The height of the cylinder (alternative to ‘h’ parameter).
r (float, optional) – The radius of the cylinder (alternative to ‘radius’, ‘d’ or ‘diameter’).
radius (float, optional) – The radius of the cylinder (alternative to ‘r’, ‘d’ or ‘diameter’).
d (float, optional) – The diameter of the cylinder (alternative to ‘r’, ‘radius’ or ‘diameter’).
diameter (float, optional) – The diameter of the cylinder (alternative to ‘r’, ‘radius’ or ‘d’).
center (CenterDefinitionType, optional) – Whether to center the cylinder at the origin. If False, the box will start from the origin. Can also be “X”, “Y” or “Z” to center in only one direction or “XY”, “XZ”, “YZ” to center in two directions. if “base” is specified, the cylinder will be centered at the base, e.g. in XY if direction is “Z”. Defaults to True which centers the box in all directions.
direction (str, optional) – The direction of the cylinder axis. Can be one of “X”, “Y” or “Z”. Defaults to “Z”.
- Returns:
The created body.
- Return type:
- cadscript.make_extrude(plane: ConstructionPlane | str, sketch: Sketch, amount: Tuple[float, float] | float, center: bool = False) Body [source]
Create an extrusion from a sketch.
- Parameters:
plane (Union[ConstructionPlane,str]) – The plane to extrude on. Can be one of the strings “XY”, “YZ”, “ZX”, “XZ”, “YX”, “ZY”.
sketch (Sketch) – The sketch to extrude.
amount (float) – The amount of extrusion. Can also be a tuple of two floats to extrude between two planes with the given offsets.
center (CenterDefinitionType, optional) – Whether to center the extrusion at the plane. If False, the extrusion will start from the plane. If True, the extrusion will be centered at the plane. If amount is a tuple, this parameter is ignored. Defaults to False.
- Returns:
The extruded body.
- Return type:
- Remarks:
The planes are defined as follows. Directions refer to the global directions.
Plane
xDir
yDir
zDir
XY
+x
+y
+z
YZ
+y
+z
+x
ZX
+z
+x
+y
XZ
+x
+z
-y
YX
+y
+x
-z
ZY
+z
+y
-x
Please note that the “XZ” plane has its normal in negative y direction.
To avoid confusion, it is recommended to use the
make_extrude_x()
,make_extrude_y()
ormake_extrude_z()
functions
- cadscript.make_extrude_x(sketch: Sketch, amount: Tuple[float, float] | float, center: bool = False) Body [source]
Create an extrusion from a sketch at the origin in the x direction. The x direction of the sketch will be aligned with the global y direction. The y direction of the sketch will be aligned with the global z direction.
- Parameters:
sketch (Sketch) – The sketch to extrude.
amount (float) – The amount of extrusion in positive x direction (global coordinates). Can also be a tuple of two floats to extrude between two planes with the given offsets.
center (CenterDefinitionType, optional) – Whether to center the extrusion at the orogin. If False, the extrusion will start from the origin. If True, the extrusion will be centered at the origin. If amount is a tuple, this parameter is ignored. Defaults to False.
- Returns:
The extruded body.
- Return type:
- cadscript.make_extrude_y(sketch: Sketch, amount: Tuple[float, float] | float, center: bool = False) Body [source]
Create an extrusion from a sketch at the origin in the y direction. The x direction of the sketch will be aligned with the global x direction. The y direction of the sketch will be aligned with the global z direction.
- Parameters:
sketch (Sketch) – The sketch to extrude.
amount (float) – The amount of extrusion in positive y direction (global coordinates). Can also be a tuple of two floats to extrude between two planes with the given offsets.
center (CenterDefinitionType, optional) – Whether to center the extrusion at the orogin. If False, the extrusion will start from the origin. If True, the extrusion will be centered at the origin. If amount is a tuple, this parameter is ignored. Defaults to False.
- Returns:
The extruded body.
- Return type:
- Remarks:
Please note that this function does not do the same as using
make_extrude()
with “XZ” as the plane parameter. The “XZ” plane has its normal in negative y direction, while this function uses global coordinates and extrudes in positive y direction therefore.
- cadscript.make_extrude_z(sketch: Sketch, amount: Tuple[float, float] | float, center: bool = False) Body [source]
Create an extrusion from a sketch at the origin in the z direction. The x direction of the sketch will be aligned with the global x direction. The y direction of the sketch will be aligned with the global y direction.
- Parameters:
sketch (Sketch) – The sketch to extrude.
amount (float) – The amount of extrusion in positive z direction (global coordinates). Can also be a tuple of two floats to extrude between two planes with the given offsets.
center (CenterDefinitionType, optional) – Whether to center the extrusion at the orogin. If False, the extrusion will start from the origin. If True, the extrusion will be centered at the origin. If amount is a tuple, this parameter is ignored. Defaults to False.
- Returns:
The extruded body.
- Return type:
- cadscript.make_text(text: str, size: float, height: float, *, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True, font: str = 'Arial')[source]
Create a 3D text object.
- Parameters:
text (str) – The text to be created.
size (float) – The size of the text.
height (float) – The height of the text.
center (CenterDefinitionType, optional) – Whether to center the text object at the origin. If False, the text will start from the origin. Can also be “X”, “Y” or “Z” to center in only one direction or “XY”, “XZ”, “YZ” to center in two directions. Defaults to True which centers the text object in all directions.
font (str, optional) – The font of the text. Defaults to “Arial”.
- Returns:
The 3D text object.
- Return type:
- cadscript.make_construction_plane(plane: ConstructionPlane | str, offset: float | None = None)[source]
- cadscript.make_sketch()[source]
Creates a new empty sketch object.
- Returns:
The newly created sketch object.
- Return type:
- cadscript.show(item: Body | Sketch | ConstructionPlane | Assembly)[source]
If inside CQ-Editor, will display the item in the 3D view. Otherwise save a STL or DXF into the system temp directory.
- cadscript.pattern_rect(sizex: Tuple[float, float] | float, sizey: Tuple[float, float] | float, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) List[Tuple[float, float]] [source]
Generate a rectangular pattern.
- Parameters:
- Returns:
A list of tuples representing the vertices of the rectangle in clockwise order.
- Return type:
- cadscript.pattern_grid(count_x: int, count_y: int, *, spacing_x: float | None = None, spacing_y: float | None = None, size_x: Tuple[float, float] | float | None = None, size_y: Tuple[float, float] | float | None = None, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) List[Tuple[float, float]] [source]
Generate a grid pattern of locations based on the given parameters.
- Parameters:
count_x (int) – The number of grid points in the x-direction. If 1 is passed, the result will be a 1D grid, i.e. points along the y-axis.
count_y (int) – The number of grid points in the y-direction. If 1 is passed, the result will be a 1D grid, i.e. points along the x-axis.
spacing_x (float, optional) – The spacing between grid points in the x-direction. If not specified, it will be calculated based on the size_x parameter.
spacing_y (float, optional) – The spacing between grid points in the y-direction. If not specified, it will be calculated based on the size_y parameter.
size_x (DimensionDefinitionType, optional) – The size of the grid in the x-direction. If not specified, it will be calculated based on the spacing_x parameter.
size_y (DimensionDefinitionType, optional) – The size of the grid in the y-direction. If not specified, it will be calculated based on the spacing_y parameter.
center (CenterDefinitionType, optional) – Determines whether the grid is centered. If True, the grid will be centered. If False, the grid will start from the origin. Can also be “X” or “Y” to center in only one direction. Defaults to True.
- Returns:
A list of (x, y) coordinates representing the locations of the grid points.
- Return type:
List[Vector2DType]
- cadscript.pattern_distribute(size_x: Tuple[float, float] | float, size_y: Tuple[float, float] | float, tile_size_x: float, tile_size_y: float, *, count_x: int | None = None, count_y: int | None = None, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True, result_pos: Literal['center', 'origin'] = 'center', min_spacing_x: float = 0.0, min_spacing_y: float = 0.0) List[Tuple[float, float]] [source]
Generate a grid pattern that evenly distributes tiles of fixed size on a rectangle.
- Parameters:
size_x (DimensionDefinitionType) – The width of the rectangle.
size_y (DimensionDefinitionType) – The height of the rectangle.
tile_size_x (float) – The width of the tiles.
tile_size_y (float) – The height of the tiles.
count_x (int, optional) – The number of tiles in the x-direction. If not specified, the maximum number of tiles that fit will be used.
count_y (int, optional) – The number of tiles in the y-direction. If not specified, the maximum number of tiles that fit will be used.
center (CenterDefinitionType, optional) – Determines whether the rectangle is centered around the origin. If True, the rectangle will be centered. Can also be “X” or “Y” to center in only one direction. If False, the rectangle will start from the origin. Defaults to True.
result_pos (Literal["center", "origin"], optional) – Determines the position of the points in the resulting list. If “center”, the points will be denote the center of the tiles. If “origin”, the points will denote the bottom-left corner of the tiles. Defaults to “center”.
min_spacing_x (float, optional) – The minimum spacing between tiles in the x-direction. Defaults to 0. Only used if count_x is not specified.
min_spacing_y (float, optional) – The minimum spacing between tiles in the y-direction. Defaults to 0. Only used if count_y is not specified.
- Returns:
A list of (x, y) coordinates representing the locations of the tiles.
- Return type:
List[Vector2DType]
- Remarks:
If count_x or count_y is not specified, the maximum number of tiles that fit will be used.
if tile_size_x is greater than size_x or tile_size_y is greater than size_y, no tiles will be generated.
If count_x or count_y is 1, the result with be centered in the corresponding direction.
- cadscript.pattern_distribute_stretch(size_x: Tuple[float, float] | float, size_y: Tuple[float, float] | float, *, count_x: int | None = None, count_y: int | None = None, min_tile_size_x: int | None = None, max_tile_size_x: int | None = None, min_tile_size_y: int | None = None, max_tile_size_y: int | None = None, spacing_x: float = 0.0, spacing_y: float = 0.0, center: Literal['X', 'Y', 'Z', 'XY', 'XZ', 'YZ', 'XYZ'] | bool = True) List[Interval2D] [source]
Generate a grid pattern that evenly distributes tiles of variable size on a rectangle.
- Parameters:
size_x (DimensionDefinitionType) – The width of the rectangle.
size_y (DimensionDefinitionType) – The height of the rectangle.
count_x (int, optional) – The number of tiles in the x-direction. If not specified, the values of min_tile_size_x and max_tile_size_x will be used to calculate the number of tiles that fit.
count_y (int, optional) – The number of tiles in the y-direction. If not specified, the values of min_tile_size_y and max_tile_size_y will be used to calculate the number of tiles that fit.
min_tile_size_x (int, optional) – The minimum size of the tiles in the x-direction.
max_tile_size_x (int, optional) – The maximum size of the tiles in the x-direction.
min_tile_size_y (int, optional) – The minimum size of the tiles in the y-direction.
max_tile_size_y (int, optional) – The maximum size of the tiles in the y-direction.
spacing_x (float, optional) – The spacing between tiles in the x-direction. Defaults to 0.
spacing_y (float, optional) – The spacing between tiles in the y-direction. Defaults to 0.
center (CenterDefinitionType, optional) – Determines whether the rectangle is centered around the origin. If True, the rectangle will be centered. Can also be “X” or “Y” to center in only one direction. If False, the rectangle will start from the origin. Defaults to True.
- Returns:
A list of Interval2D objects representing the tiles.
- Return type:
List[Interval2D]
- Remarks:
If count_x or is not specified, the values of min_tile_size_x and max_tile_size_x will be used to calculate the number of tiles that fit.
If min_tile_size_x is given, the algorithm will use as many tiles as possible to fit the size. If min_tile_size_x is greater than the rectangle size, no tiles will be generated.
If max_tile_size_x is given, the algorithm will only use as few tiles as possible to fit the size.
If both min_tile_size_x and max_tile_size_x are given, the algorithm will use as few tiles as possible, but will return no tiles if the size is less than min_tile_size_x.
All the remarks for the x-direction also apply to the y-direction with the corresponding parameters.