I've been needing this for a while, and some of you may find it useful.

It's designed for single-point threading, bottom-up to clear chips better, and to facilitate climb milling, which gives a little smoother thread form. It has a centering plunge to the desired threading depth followed by a tangent lead-in to the desired threadform depth.

It threads to one pitch above the stock surface, then moves to clearance.

If you have multiple holes, it will connect all of them with one toolpath, moving between them at clearance.

All the parameters are hard-coded right now, except for the hole diameter itself. In this sort-of 'demo' version, I'm not dealing with the threadform depth, either.

I just want some input as to bugs, suggestions, etc. Thanks to David's reminding me about the 'reality' of drawing entities, I finished quickly.

Lloyd

(ps... should have waited... it only took about five minutes to add the form depth

=================

Updated version B-threading with bottom-up finish V0.2

' Bottom-up threading V0.2

'

' For a single-point tool, with clearance moves and

' a tangent lead-in to the thread wall.

'

' By Lloyd E. Sponenburgh 3/29/2015

' If you use this, please give credits to me, and leave in the

' credit to Andy.

' AGAIN, with credits to Andy Payne for Boingy.

' This routine designs a straight spiral of a given threads per inch,

' a given depth, a given stock surface, a given threading-tool diameter,

' and a given desired thread form depth, within a hole of a specified diameter.

'

'

' Given:

' The primitive ID of the hole (circle). Actually, in this case, the hole will

' be gotten from the screen selection.

'

' The stock surface Z, and clearance height Z.

' The threading tool diameter to its tip.

' The desired form depth. (NO protection against exceeding the depth of the

' tool's forming tip!!!)

' The desired threads per inch.

'

' The routine is intended to be used with an ENGRAVE MOp.

'

' It will first find the center of the hole, and describe a straight vertical

' line at that center point from clearance to the desired threading depth.

' It will continue that polyline in a curved tangent to the form depth.

' It will describe a straight spiral upwards with a clockwise THREAD, but

' that means, of course, the toolpath will be spiralling CCW.

' It will continue to one thread pitch above surface, or to clearance, whichever

' is less above the surface.

' If the end-point of the threading path is lower than clearance, then it will

' continue in a straight vertical line to clearance. (in fact, it will do so

' in either case, but the last segment will be zero-length if the tool

' was already at the clearance height when it stopped the thread)

'

' If there are multiple circles to thread, ONE polyline connecting all of

' them at the clearance height will be made.

'

' A modified BOINGY MakeHelix is used as a subroutine to generate the straight

' spiral path. Instead of creating a new poly, it will add points to our

' "working" polyline, p.

'

'

dim TP_radius as single ' toolpath target radius for center of cutter

dim tool_diameter as single ' diameter to tip of threading tool

dim tool_radius as single ' we're assuming a single-point tool

dim form_depth as single ' depth into the wall of the threading point

dim pass_form_depth as single ' depth increment per pass, less some for finish

dim finish_depth as single ' finishing pass depth

dim roughing_passes as integer ' total number of roughing passes

dim finishing_passes as integer ' ditto finishing

dim steps as integer ' total arc segments from bottom to top

'dim i as integer

dim th as double ' theta angle per step

dim p as new polyline ' name of our polyline

dim x,y,z as single ' cartesian coordinates

dim cp as point3F ' center-point of selected circle

dim Diameter as Double ' diameter in CB units of selected circle

dim target_depth,clearance_height,stock_surface as single

dim thread_pitch as single

dim thread_top as single

dim lead_in_diameter ' radius of the lead-in tangent

dim one_eighty_bulge as single =1 ' +=ccw, -=CW (+-0.4142135237309503 for 90 degrees)

dim steps_per_circuit as single ' number of divisions of each loop

' arbitrary according to needs

dim e as Circle

dim any_selected as integer=0

dim pass_number as integer ' loop counter for roughing/finish passes

' this setup makes straight-line segments for the helix.

' Inches is used in this example, but the algorithm is "unit-less".

sub main

roughing_passes=4 ' four rough

finishing_passes=2

thread_pitch=0.050 ' 20tpi for this fixed-pitch example

tool_diameter=.968 ' for testing -- this is pretty accurate

form_depth=0.044 ' for 20tpi, pretty exact would be 0.043301

tool_radius=tool_diameter/2

steps_per_circuit=180

stock_surface=0 ' OOPS! bug in starting-depth calculations!

' doesn't account for stock surface!

clearance_height=0.25

target_depth=-1.25 ' depth we'll go with this threading

finish_depth=0.002

pass_form_depth=(form_depth-finish_depth)/roughing_passes

' find the circle and get its specs

for each ent as Entity in view.SelectedEntities

if ent.PrimitiveType()<>"Circle" then

exit for

end if

any_selected=1 ' we had at least one circle!

e=ent

cp=e.Center()

x=cp.x

y=cp.y

Diameter=e.Diameter ' get the hole's diameter

TP_radius=(Diameter/2)-tool_radius ' zero cutting depth

for pass_number=1 to roughing_passes+finishing_passes

if pass_number<=roughing_passes then

TP_radius+=pass_form_depth ' increase depth of cut by pass depth

else

TP_radius=((Diameter/2)-tool_radius)+form_depth ' make it EXACT

end if

' see where the thread should stop

thread_top=stock_surface+thread_pitch

if thread_top>clearance_height then

thread_top=clearance_height ' adjust to clearance if Higher than clearance

end if

if pass_number>roughing_passes then

' make a bottom_up pass (in climb)

' Start at clearance, and work down.

x=cp.x

y=cp.y

z=clearance_height

p.add(x,y,z)

' now plunge to depth

z=target_depth

p.add(x,y,z)

' now calculate a half-turn circular curve that will go from this

' center-point to tangent of the targeted thread form depth

'

' Since we're spiraling up counter-clockwise, the lead-in must curve

' CCW from the center.

lead_in_diameter=TP_radius

p.add(x,y,z,one_eighty_bulge) ' establish a move from the center to the start

' and the curvature of the line to the next point

x=x+lead_in_diameter ' move 'right'to wall of hole

p.add(x,y,z) ' set second point of curve

MakeThread()

' now add a leadout directly to clearance

z=clearance_height

p.add(x,y,z)

else

' make a top-down pass

' Start at clearance, and work down.

lead_in_diameter=TP_radius

x=x+lead_in_diameter ' move 'right'to wall of hole

z=clearance_height ' but at clearance

p.add(x,y,z)

z=thread_pitch ' then down one 'pitch' above surface

p.add(x,y,z)

MakeThread()

' Since we're spiraling down clockwise, the lead-out must curve

' CW from the center.

p.add(x,y,z,(-1*one_eighty_bulge)) ' establish a move from the center to the start

' and the curvature of the line to the next point

' Move via that curve to the center again

x=cp.x

y=cp.y

p.add(x,y,z)

' now add a final leadout directly to clearance

z=clearance_height

p.add(x,y,z)

end if

next pass_number

next

' finally, add the polyline to the document

if any_selected>0 then

doc.add(p)

end if

end sub

function MakeThread

dim start as single = 0 ' in radians

dim steps as single ' number of total steps we'll go

dim turns as single ' number of circuits to make

dim th as single = start

dim dt as single

dim dz as single

turns=((math.abs(target_depth)+thread_top)/thread_pitch)

steps=turns*steps_per_circuit

if pass_number>roughing_passes then

dz = (thread_top-target_depth)/steps

dt = (2*pi)/steps_per_circuit

else

dz = -1*(thread_top-target_depth)/steps

dt = (-2*pi)/steps_per_circuit

end if

'// Play da loop

for i as short = 0 to steps

z = z + dz

th = th + dt

x = cp.x+(TP_radius * math.cos(th))

y = cp.y+(TP_radius * math.sin(th))

p.Add(x,y,z)

next i

end function