
! script name: pksolids.d/pkscrewshape
! solids: creates a body the shape of a screw
!A
!A NAME:
!A
!A 	Variable Pitch Screw Shape: 
!A
!A DESCRIPTION:
!A
!A	This script creates a body the shape of a screw.
!A
!B INSTRUCTIONS:
!B
!B		OD SCREW DIAMETER: Diameter of outside of screw.
!B
!B		START PITCH: Give the starting pitch.
!B
!B		END PITCH: Give the ending pitch.
!B
!B		TOTAL SCREW LENGTH:  Total length of screw.
!B
!B		DEPTH: Depth of thread shape.
!B
!B		TAPER:  Positive angle tapers outward.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: var pitch screw ")

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        Screw_diameter= 68
        Start_pitch= 68
        End_pitch= 68
	Screw_length= 250
	Screw_depth= 25
	Screw_taper= 0
ELSE
        Screw_diameter= 4.5
        Start_pitch= 4.5
        End_pitch= 4.5
	Screw_length= 10
	Screw_depth= 1.0
	Screw_taper= 0
END IF
astep= 5.0

Start:!
Stat= GLPlotOn


Cloop:!

Stat=SetInputFormat("a1=",",L,R,")
Stat=SetEqualsValue(0,"R")
Stat=GetValue("Left or Right HAND SCREW ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "L" THEN
        Hand= WsLeft
ELSE
        Hand= WsRight
END IF

Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(0.5*Screw_diameter)
Screw_diameter=InputRadius("OD DIAMETER",WsDiaInput)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Start_pitch)
Start_pitch=GetValue("START PITCH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(End_pitch)
End_pitch=GetValue("END PITCH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Screw_length)
Screw_length=GetValue("TOTAL LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Screw_depth)
Screw_depth=GetValue("DEPTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Start_width= .1*Start_pitch
Stat=SetEqualsValue(Start_width)
Start_width=GetValue("START FLIGHT WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

IF End_width=0 THEN End_width= Start_width
Stat=SetInputFormat("n4=","")
End_width= .1*Start_pitch
Stat=SetEqualsValue(End_width)
End_width=GetValue("END FLIGHT WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Lead_flank_ang)
Lead_flank_ang=GetValue("LEAD FLANK ANGLE",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Trail_flank_ang)
Trail_flank_ang=GetValue("TRAIL FLANK ANGLE",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Screw_taper)
Screw_taper=GetValue("OD TAPER",Answer$)
IF ExitScript(Destination$) THEN Leave
IF ABS(Screw_taper)> 0.0 THEN
	Stat=SetInputFormat("a1=",",F,C,")
	Stat=SetEqualsValue(0,"F")
	Stat=GetValue(" Flat or Conical TAPER ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	IF Answer$= "F" THEN
       		 Taper_type=0
	ELSE
       		 Taper_type=1
	END IF
END IF

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Start_angle)
Start_angle=GetValue("START ANGLE",Answer$)
IF ExitScript(Destination$) THEN Leave

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


Workr= CurrentWorkplane
StdWorkplane
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
Zstart= ZPointValue(Ps)
Stat= DeleteEntity(Ps)

D1= Screw_diameter
D2= Screw_depth
P1= Start_pitch
P2= End_pitch
Len1= Screw_length
W1= Start_width
W2= End_width
A1= Lead_flank_ang
A2= Trail_flank_ang


WPKClearErrorFlag
PlotOff
E1= WPKScrewShape(Hand,D1,P1,P2,Len1,D2,W1,W2,A1,A2,Start_angle,Screw_taper,Zstart,Astep,Taper_type)


StdWorkplane
PlotOn
PlotAll

IF ValidGeometry(Workr) THEN Stat=SetWorkplane(Workr)

ActivateUndo
Stat= AdvanceUndoNumber("var pitch screw")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Start

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