cqparts_fasteners.solidtypes.threads package

Submodules

cqparts_fasteners.solidtypes.threads.ball_screw module

class cqparts_fasteners.solidtypes.threads.ball_screw.BallScrewThread(*args, **kwargs)

Bases: cqparts_fasteners.solidtypes.threads.base.Thread

ParametricObject constructor parameters:

Parameters:
  • ball_radius (float) – ball’s radius
  • diameter (float) – thread’s diameter
  • inner (bool) – if True, thread is to be cut from a solid to form an inner thread
  • lefthand (bool) – if True, thread is spun in the opposite direction
  • length (float) – thread’s length
  • min_vertices (int or list(int)) – minimum vertices used cross-section’s wire
  • pilothole_radius (float) – explicitly set pilothole radius, overrides pilothole_ratio
  • pilothole_ratio (float) – sets thread’s pilot hole using inner and outer thread radii: \(radius = inner + ratio \times (outer-inner)\)
  • pitch (float) – thread’s pitch
  • start_count (int) – number of thread starts

Search Criteria:

This object can be found with find() and search() using the following search criteria.

Key Value
module cqparts_fasteners.solidtypes.threads.base
name ball_screw
../_images/ball_screw.png
build_profile()
../_images/ball_screw.profile.png
get_radii()

cqparts_fasteners.solidtypes.threads.base module

class cqparts_fasteners.solidtypes.threads.base.MinVerticiesParam(default=None, doc=None)

Bases: cqparts.params.parameter.Parameter

type(value)
class cqparts_fasteners.solidtypes.threads.base.Thread(*args, **kwargs)

Bases: cqparts.part.Part

ParametricObject constructor parameters:

Parameters:
  • diameter (float) – thread’s diameter
  • inner (bool) – if True, thread is to be cut from a solid to form an inner thread
  • lefthand (bool) – if True, thread is spun in the opposite direction
  • length (float) – thread’s length
  • min_vertices (int or list(int)) – minimum vertices used cross-section’s wire
  • pilothole_radius (float) – explicitly set pilothole radius, overrides pilothole_ratio
  • pilothole_ratio (float) – sets thread’s pilot hole using inner and outer thread radii: \(radius = inner + ratio \times (outer-inner)\)
  • pitch (float) – thread’s pitch
  • start_count (int) – number of thread starts
build_profile()

Build the thread’s profile in a cadquery.Workplace as a wire on the \(XZ\) plane.

It will be used as an input to profile_to_cross_section

Note

This function must be overridden by the inheriting class in order to construct a thread.

Without overriding, this function rases a NotImplementedError exception.

example implementation:

import cadquery
from cqparts.solidtypes.threads.base import Thread

class MyThread(Thread):
    def build_profile(self):
        points = [
            (2, 0), (3, 0.5), (3, 1), (2, 1.5), (2, 2)
        ]
        profile = cadquery.Workplane("XZ") \
            .moveTo(*points[0]).polyline(points[1:])
        return profile.wire()  # .wire() is mandatory
Returns:thread profile as a wire on the XZ plane
Return type:cadquery.Workplane

Warning

Wire must be built on the \(XZ\) plane (as shown in the example). If it is not, the thread may not be generated correctly.

get_radii()

Get the inner and outer radii of the thread.

Returns:(<inner radius>, <outer radius>)
Return type:tuple

Note

Ideally this method is overridden in inheriting classes to mathematically determine the radii.

Default action is to generate the profile, then use the bounding box to determine min & max radii. However this method is prone to small numeric error.

make()
make_pilothole_cutter()

Make a solid to subtract from an interfacing solid to bore a pilot-hole.

make_simple()

Return a cylinder with the thread’s average radius & length.

\(radius = (inner_radius + outer_radius) / 2\)

profile

Buffered result of build_profile()

cqparts_fasteners.solidtypes.threads.base.helical_path(pitch, length, radius, angle=0, lefthand=False)
cqparts_fasteners.solidtypes.threads.base.profile_to_cross_section(profile, lefthand=False, start_count=1, min_vertices=20)

Converts a thread profile to it’s equivalent cross-section.

Profile:

The thread profile contains a single wire along the XZ plane (note: wire will be projected onto the XZ plane; Y-coords will be ignored). The profile is expected to be of 1 thread rotation, so it’s height (along the Z-axis) is the thread’s “pitch”. If start_count > 1, then the profile will effectively be duplicated. The resulting cross-section is designed to be swept along a helical path with a pitch of the thread’s “lead” (which is {the height of the given profile} * start_count)

Method:

Each edge of the profile is converted to a bezier spline, aproximating its polar plot equivalent.

Resolution: (via min_vertices parameter)

Increasing the number of vertices used to define the bezier will increase the resulting thread’s accuracy, but cost more to render.

min_vertices may also be expressed as a list to set the number of vertices to set for each wire. where: len(min_vertices) == number of edges in profile

Example

import cadquery
from cqparts_fasteners.solidtypes.threads.base import profile_to_cross_section
from Helpers import show  

profile = cadquery.Workplane("XZ") \
    .moveTo(1, 0) \
    .lineTo(2, 1).lineTo(1, 2) \
    .wire()
cross_section = profile_to_cross_section(profile)

show(profile)  
show(cross_section)  

Will result in:

../_images/solidtypes.threads.base.profile_to_cross_section.01.png
Parameters:
  • profile (cadquery.Workplane) – workplane containing wire of thread profile.
  • lefthand (bool) – if True, cross-section is made backwards.
  • start_count (int) – profile is duplicated this many times.
  • min_vertices (int or tuple) – int or tuple of the desired resolution.
Returns:

workplane with a face ready to be swept into a thread.

Return type:

cadquery.Workplane

Raises:
  • TypeError – if a problem is found with the given parameters.
  • ValueError – if min_vertices is a list with elements not equal to the numbmer of wire edges.

cqparts_fasteners.solidtypes.threads.iso68 module

class cqparts_fasteners.solidtypes.threads.iso68.ISO68Thread(*args, **kwargs)

Bases: cqparts_fasteners.solidtypes.threads.base.Thread

ParametricObject constructor parameters:

Parameters:
  • diameter (float) – thread’s diameter
  • inner (bool) – if True, thread is to be cut from a solid to form an inner thread
  • lefthand (bool) – if True, thread is spun in the opposite direction
  • length (float) – thread’s length
  • min_vertices (int or list(int)) – minimum vertices used cross-section’s wire
  • pilothole_radius (float) – explicitly set pilothole radius, overrides pilothole_ratio
  • pilothole_ratio (float) – sets thread’s pilot hole using inner and outer thread radii: \(radius = inner + ratio \times (outer-inner)\)
  • pitch (float) – thread’s pitch
  • rounding_ratio (float) – [no description]
  • start_count (int) – number of thread starts

Search Criteria:

This object can be found with find() and search() using the following search criteria.

Key Value
module cqparts_fasteners.solidtypes.threads.base
name iso68
../_images/iso68.png
build_profile()

Build a thread profile in specified by ISO 68

../_images/iso68.profile.png
get_radii()

cqparts_fasteners.solidtypes.threads.triangular module

class cqparts_fasteners.solidtypes.threads.triangular.TriangularThread(*args, **kwargs)

Bases: cqparts_fasteners.solidtypes.threads.base.Thread

ParametricObject constructor parameters:

Parameters:
  • angle (float) – pressure angle of thread
  • diameter (float) – thread’s diameter
  • diameter_core (float) – diamter of core
  • inner (bool) – if True, thread is to be cut from a solid to form an inner thread
  • lefthand (bool) – if True, thread is spun in the opposite direction
  • length (float) – thread’s length
  • min_vertices (int or list(int)) – minimum vertices used cross-section’s wire
  • pilothole_radius (float) – explicitly set pilothole radius, overrides pilothole_ratio
  • pilothole_ratio (float) – sets thread’s pilot hole using inner and outer thread radii: \(radius = inner + ratio \times (outer-inner)\)
  • pitch (float) – thread’s pitch
  • start_count (int) – number of thread starts

Search Criteria:

This object can be found with find() and search() using the following search criteria.

Key Value
module cqparts_fasteners.solidtypes.threads.base
name triangular
../_images/triangular.png
build_profile()
../_images/triangular.profile.png
get_radii()
initialize_parameters()

Module contents

class cqparts_fasteners.solidtypes.threads.Thread(*args, **kwargs)

Bases: cqparts.part.Part

ParametricObject constructor parameters:

Parameters:
  • diameter (float) – thread’s diameter
  • inner (bool) – if True, thread is to be cut from a solid to form an inner thread
  • lefthand (bool) – if True, thread is spun in the opposite direction
  • length (float) – thread’s length
  • min_vertices (int or list(int)) – minimum vertices used cross-section’s wire
  • pilothole_radius (float) – explicitly set pilothole radius, overrides pilothole_ratio
  • pilothole_ratio (float) – sets thread’s pilot hole using inner and outer thread radii: \(radius = inner + ratio \times (outer-inner)\)
  • pitch (float) – thread’s pitch
  • start_count (int) – number of thread starts
build_profile()

Build the thread’s profile in a cadquery.Workplace as a wire on the \(XZ\) plane.

It will be used as an input to profile_to_cross_section

Note

This function must be overridden by the inheriting class in order to construct a thread.

Without overriding, this function rases a NotImplementedError exception.

example implementation:

import cadquery
from cqparts.solidtypes.threads.base import Thread

class MyThread(Thread):
    def build_profile(self):
        points = [
            (2, 0), (3, 0.5), (3, 1), (2, 1.5), (2, 2)
        ]
        profile = cadquery.Workplane("XZ") \
            .moveTo(*points[0]).polyline(points[1:])
        return profile.wire()  # .wire() is mandatory
Returns:thread profile as a wire on the XZ plane
Return type:cadquery.Workplane

Warning

Wire must be built on the \(XZ\) plane (as shown in the example). If it is not, the thread may not be generated correctly.

get_radii()

Get the inner and outer radii of the thread.

Returns:(<inner radius>, <outer radius>)
Return type:tuple

Note

Ideally this method is overridden in inheriting classes to mathematically determine the radii.

Default action is to generate the profile, then use the bounding box to determine min & max radii. However this method is prone to small numeric error.

make()
make_pilothole_cutter()

Make a solid to subtract from an interfacing solid to bore a pilot-hole.

make_simple()

Return a cylinder with the thread’s average radius & length.

\(radius = (inner_radius + outer_radius) / 2\)

profile

Buffered result of build_profile()

cqparts_fasteners.solidtypes.threads.register(*args, **kwargs)
cqparts_fasteners.solidtypes.threads.find(*args, **kwargs)
cqparts_fasteners.solidtypes.threads.search(*args, **kwargs)