
! script name: draft.d/drawthreads
! topic: Sample - draw threads between two points

!A
!A NAME:
!A
!A 	Draw Thread Symbol
!A
!A DESCRIPTION:
!A
!A 	This script draws a thread between two points.
!A
!B INSTRUCTIONS:
!B
!B 	This script will draw a thread symbol between two points.
!B
!B 	The threads are not pickable. 
!B
!B 	The actual shape of the thread is not to scale.
!B
!B 	The outer diameter and the pitch is correct.
!B
!B 	The included angle and inner diameter are distorted.
!B
!B 	Different char symbols are used for different TPI ranges
!B 	to give a better cosmetic appearance.
!B
!B 	This script will draw a whole number of threads starting from
!B 	the first point. Fractional threads will not be drawn.
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: draw threads ")

DIM Text$[256]
DIM Answer$[256]
DIM Destination$[256]
DEG

DeActivateUndo
Dim_type= WsTextLine
Dia=NamedVarVal("hole diameter",WsPointVars,0.0)
Stat=SetRadiusEquals(Diar/2)

Tpi= 8

Thread_loop:!
Stat=SetRadiusEquals(Dia/2)
Dia=InputRadius("THREAD DIAMETER",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave

Stat= SetEqualsValue(Tpi)
Stat=SetInputFormat("n0=","")
Tpi=GetValue("THREADS PER INCH",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Tpi< 1 THEN  Thread_loop

Stat=SetInputFormat("n4=","")
Ps=XyzInput("START",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
Stat= SetLastPoint(Ps)

Stat=SetInputFormat("n4=","")
Pe=XyzInput("END",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
Stat= SetLastPoint(Pe)

Fontr= GetDefault(WsTextFont)
Widthr= GetDefault(WsTextWidth)
Heightr= GetDefault(WsTextHeight)
Angler= GetDefault(WsTextAngle)

L1=LineTwoPoints(Ps,Pe,WsTRIMMED)
Len1= LineLength(L1)
W1= 1/Tpi
H1= Dia
Angle= LineAngle(L1)

Stat=SetDefaults(WsTextHeight,H1)
Stat=SetDefaults(WsTextWidth,W1)
Stat=SetDefaults(WsTextFont,4)
Stat=SetDefaults(WsTextAngle,Angle)

N1= Len1*TPI
SELECT Tpi
CASE 1 TO 5
	Text$= RPT$("a",N1)
CASE 6,7 
	Text$= RPT$("b",N1)
CASE 8 TO 11
	Text$= RPT$("c",N1)
CASE 12 TO 15
	Text$= RPT$("d",N1)
CASE 16 TO 19
	Text$= RPT$("e",N1)
CASE 20 TO 23
	Text$= RPT$("f",N1)
CASE 24 TO 27
	Text$= RPT$("g",N1)
CASE 28 TO 35
	Text$= RPT$("h",N1)
CASE 36 TO 100
	Text$= RPT$("i",N1)
END SELECT
E1= TextArrow(Dim_type,Ps,Ps,Text$)

Stat=SetDefaults(WsTextHeight,Heightr)
Stat=SetDefaults(WsTextWidth,Widthr)
Stat=SetDefaults(WsTextFont,Fontr)
Stat=SetDefaults(WsTextAngle,Angler)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(L1)

GOTO Thread_loop

Leave:!
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(L1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
