
! script name: vpksolids.d/vpkscrewshape
! solids: creates a body the shape of a screw
!A
!A NAME:
!A
!A 	Variable Pitch Screw Flight Shape:  VARIATIONAL
!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]
DIM Body$[256]
DIM Name$[256]
DIM Dia_var$[256]
DIM SPitch_var$[256]
DIM EPitch_var$[256]
DIM Length_var$[256]
DIM Depth_var$[256]
DIM Astart_var$[256]
DIM Swidth_var$[256]
DIM Ewidth_var$[256]
DIM Lead_angle_var$[256]
DIM Trail_angle_var$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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= 10.0

Stat= GLPlotOn
Start:!


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
No_dia_var= LastVariableInput(Dia_var$)

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

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

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

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

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

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
No_ewidth_var= LastVariableInput(Ewidth_var$)

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

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

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Screw_taper)
Screw_taper=GetValue("OD TAPER",Answer$)
IF ExitScript(Destination$) THEN Leave
No_taper_ang= LastVariableInput(Taper_angle_var$)
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
No_astart_var= LastVariableInput(Astart_var$)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SOLID: Screw Flight Shape")
V1= FreeParameter("Hand",Hand)
IF No_dia_var THEN
        V2= FreeParameter("OD Diameter",Screw_diameter)
ELSE
        V2= FreeParameter("OD Diameter",Dia_var$)
END IF
IF No_length_var THEN
        V3= FreeParameter("Length",Screw_length)
ELSE
        V3= FreeParameter("Length",Length_var$)
END IF
IF No_spitch_var THEN
        V4= FreeParameter("Starting Pitch",Start_pitch)
ELSE
        V4= FreeParameter("Starting Pitch",SPitch_var$)
END IF
IF No_epitch_var THEN
        V5= FreeParameter("Ending Pitch",End_pitch)
ELSE
        V5= FreeParameter("Ending Pitch",EPitch_var$)
END IF
IF No_depth_var THEN
        V6= FreeParameter("Flight Depth",Screw_depth)
ELSE
        V6= FreeParameter("Flight Depth",Depth_var$)
END IF
IF No_swidth_var THEN
        V7= FreeParameter("Start Flight Width",Start_width)
ELSE
        V7= FreeParameter("Start Flight Width",Swidth_var$)
END IF
IF No_ewidth_var THEN
        V8= FreeParameter("End Flight Width",End_width)
ELSE
        V8= FreeParameter("End Flight Width",Ewidth_var$)
END IF
IF No_lead_ang THEN
        V9= FreeParameter("Lead Flank Angle",Lead_flank_ang)
ELSE
        V9= FreeParameter("Lead Flank Angle",Lead_angle_var$)
END IF
IF No_trail_ang THEN
        V10= FreeParameter("Trail Flank Angle",Trail_flank_ang)
ELSE
        V10= FreeParameter("Trail Flank Angle",Trail_angle_var$)
END IF
IF No_taper_ang THEN
        V11= FreeParameter("OD Taper Angle",Screw_taper)
ELSE
        V11= FreeParameter("OD Taper Angle",Taper_angle_var$)
END IF
IF No_astart_var THEN
        V12= FreeParameter("Start angle",Astart)
ELSE
        V12= FreeParameter("Start angle",Astart_var$)
END IF
V13= FreeParameter("Taper type",Taper_type)
V14= FreeParameter("Angular increment",Astep)
V15= FreeParameter("Start length",Zstart)
Workr= CurrentWorkplane
Stat=SetWorkplane
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
PlotOff
Pkbody= WPKScrewShape(V1,V2,V4,V5,V3,V6,V7,V8,V9,V10,V12,V11,V15,V14,V13)
Stat=SetWorkplane(Workr)
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

StdWorkplane
PlotOn
PlotAll

IF ValidGeometry(Workr) THEN Stat=SetWorkplane(Workr)
ActivateUndo
Stat= AdvanceUndoNumber("var pitch screw flight")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Start

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