! script name: pksolids.d/pktorus
! solids: construct a torus in the current workplane.

!A
!A NAME:
!A
!A 	Solid Torus
!A
!A DESCRIPTION:
!A
!A 	This script will construct a torus. 
!A
!B INSTRUCTIONS:
!B
!B 	MAJOR RADIUS: Give the major or axial radius of the torus.
!B
!B 	MINOR RADIUS: Give the minor or radial radius of the torus.
!B
!B 	LOCATION POINT: Enter the location of the center of the torus.
!B
!B 	AXIS DIRECTION POINT: Enter a point giving the direction of the
!B 		axis of the torus.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: torus")

DIM Destination$[256]
DIM Answer$[256]


ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        R1= 25
        R2= 25
ELSE
        R1= 1
        R2= 1
END IF

Stat= GLPlotOn
Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(R1)
R1=InputRadius("MAJOR RADIUS")
IF ExitScript(Destination$) THEN Leave

Stat=SetRadiusEquals(R2)
R2=InputRadius("MINOR RADIUS")
IF ExitScript(Destination$) THEN Leave

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

Stat=SetInputFormat("n4","")
Pe=XyzInput("AXIS DIRECTION POINT ",WsXyzInput)
IF ExitScript(Destination$) THEN Leave

WPKClearErrorFlag
C1=WPKTorus(Ps,Pe,R1,R2)

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)

ActivateUndo
Stat= AdvanceUndoNumber("solid torus")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Cloop

Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
