
! script name: draft.d/drawflutes
! topic: Sample - draw drill flutes between two points

!A
!A NAME:
!A
!A 	Draw Flutes Symbol
!A
!A DESCRIPTION:
!A
!A 	This script draws  flutes between two points.
!A
!B INSTRUCTIONS:
!B
!B	The flutes drawn are cosmetic only. Only the diameter is 
!B	drawn to scale.		
!B
!C NOTE:
!C
!C 	This is an unsupported sample script.
!C

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

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)

Helix_angle= 60

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

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)
Angle= LineAngle(L1)
H1= Dia
H2= 2*Dia*TAN(Helix_angle)
N1= INT(Len1/H2+ 0.5)
N1= MAX(N1,1)
W1= Len1/N1


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

Text$= RPT$("n",N1)
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 Flute_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
