
! script name: vpksolids.d/vpkrampedstart
! solids: creates a ramped start to a simple screw shape.
!A
!A NAME:
!A
!A 	Ramped Simple Screw Start:   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script creates ramped start to a simple screw.
!A
!B INSTRUCTIONS:
!B		Left or Right HAND SCREW: Is the screw left or right hand.
!B
!B		SCREW DIAMETER  Connect: Diameter of od of the screw. Connect
!B			will link diameter with previous section. 
!B
!B		START PITCH   Connect: Give the starting pitch. Connect will 
!B			link pitch to end of previous section.
!B
!B		END PITCH   Constant: Give the starting pitch. Constant will 
!B			make pitch variationally constant.
!B
!B		END CHANNEL DEPTH   Constant: End depth of channel.
!B
!B		START FLIGHT WIDTH   Connect: Starting width of flight.
!B
!B		END FLIGHT WIDTH   Constant: Ending width of flight.
!B
!B NOTES:
!B
!B
!# see also - htdocs/help.d/parasolids.htm

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

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM A$[256]
DIM B$[256]
DIM Name$[256]
DIM CName$[256]
DIM Point$[256]
DIM Pname$[256]
DIM Prop_name$[256]
DIM Dia_var$[256]
DIM SLead_rad_var$[256]
DIM STrail_rad_var$[256]
DIM ELead_rad_var$[256]
DIM ETrail_rad_var$[256]
DIM Spitch_var$[256]
DIM Epitch_var$[256]
DIM Length_var$[256]
DIM Swidth_var$[256]
DIM Ewidth_var$[256]
DIM Sdepth_var$[256]
DIM Edepth_var$[256]
DIM Sangle_var$[256]
DIM Section_type$[256]
DIM Question$(20)[80]
DIM Reply$(20)[80]

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


ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
	Shank_length=250
	Screw_diameter=114
        Start_pitch= 114
        End_pitch= 114
	Screw_length= 250
	Start_depth= .125
	End_depth= 20
	Start_width= 12
	End_width= 12
	SLeading_radius= 4
	ELeading_radius= 4
	STrailing_radius=6
	ETrailing_radius=6
ELSE
	Shank_length=10
	Screw_diameter= 4.5
        Start_pitch= 4.5
        End_pitch= 4.5
	Screw_length= 10
	Start_depth= 0.005
	End_depth= .87
	Start_width= 0.45
	End_width= 0.45
	SLeading_radius= 0.25
	ELeading_radius= 0.25
	STrailing_radius=0.375
	ETrailing_radius=0.375
END IF
astep= 10.0
Nflights=1
Use_input_box=1

Start:!
Stat= GLPlotOn

Cloop:!
Section_type$="Feed"
Nflights=1
Front_cutoff= 1

IF Use_input_box THEN Make_questions

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

V1= FindNamedVar("Screw_Hand",WsVariationVars)
IF ValidGeometry(V1) THEN
   Hand= VariableValue(V1)
ELSE
   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
END IF

Ask_diameter:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Screw_diameter)
Screw_diameter=GetValue("SCREW DIAMETER",Answer$)
IF ExitScript(Destination$) THEN Leave
No_dia_var= LastVariableInput(Dia_var$)

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

End_pitch= Start_pitch
Stat=SetInputFormat("n4a1=",",C,")
Stat=SetEqualsValue(End_pitch)
End_pitch=GetValue("END PITCH   Constant pitch",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "C" THEN
        End_pitch=0
        No_epitch_var=1
ELSE
	No_epitch_var= LastVariableInput(Epitch_var$)
END IF


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

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(End_depth)
End_depth=GetValue("END CHANNEL DEPTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_edepth_var= LastVariableInput(Edepth_var$)


Ask_start_width:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Start_width)
Start_width=GetValue("START FLIGHT WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_swidth_var= LastVariableInput(Swidth_var$)

End_width= Start_width
Stat=SetInputFormat("n4a1=",",C,")
Stat=SetEqualsValue(End_width)
End_width=GetValue("END FLIGHT WIDTH    Constant width",Answer$)
IF ExitScript(Destination$) THEN Leave
No_ewidth_var= LastVariableInput(Ewidth_var$)
IF Answer$= "C" THEN
        End_width=0
        No_ewidth_var=1
ELSE
	No_ewidth_var= LastVariableInput(Ewidth_var$)
END IF


Ask_slead_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(SLeading_radius)
SLeading_radius=GetValue("START LEADING RADIUS",Answer$)
IF ExitScript(Destination$) THEN Leave
No_slead_rad_var= LastVariableInput(SLead_rad_var$)

Ask_elead_radius:!
ELeading_radius= Sleading_radius

Stat=SetInputFormat("n4a1=",",C,")
Stat=SetEqualsValue(ELeading_radius)
ELeading_radius=GetValue("END LEADING RADIUS  Const ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "C" THEN
        ELeading_radius= 0
         No_elead_rad_var=1
ELSE
        No_elead_rad_var= LastVariableInput(ELead_rad_var$)
END IF


Ask_strail_radius:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(STrailing_radius)
STrailing_radius=GetValue("START TRAILING RADIUS",Answer$)
IF ExitScript(Destination$) THEN Leave
No_strail_rad_var= LastVariableInput(STrail_rad_var$)

Ask_etrail_radius:!
ETrailing_radius= Strailing_radius

Stat=SetInputFormat("n4a1=",",C,")
Stat=SetEqualsValue(ETrailing_radius)
ETrailing_radius=GetValue("END TRAILING RADIUS  Const ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "C" THEN
        ETrailing_radius= 0
         No_etrail_rad_var=1
ELSE
        No_etrail_rad_var= LastVariableInput(ETrail_rad_var$)
END IF


Ask_start_angle:!
Start_angle= 0.0

GOTO Make_record


Make_questions:!
FOR I=1 TO 20
	Question$(I)=""
	Reply$(I)=""
NEXT I

Curr_section= 1

Question$(1)= "SHANK LENGTH: "
Reply$(1)= VAL$(Shank_length)

Question$(2)= "Left or Right HAND SCREW:  "
Reply$(2)= RPT$("L",Hand= WsLeft)&RPT$("R", Hand<>WsLeft)

Question$(3)= "SCREW DIAMETER:  "
Reply$(3)= VAL$(Screw_diameter)

Question$(4)= "START PITCH:  "
Reply$(4)= VAL$(Start_pitch)

Question$(5)= "END PITCH:  "
Reply$(5)= VAL$(Start_pitch)

Question$(6)= "SCREW SECTION LENGTH:  "
Reply$(6)= VAL$(Screw_length)

Question$(7)= "END CHANNEL DEPTH:  "
Reply$(7)= VAL$(End_depth)

Question$(8)= "START FLIGHT WIDTH:  "
Reply$(8)= VAL$(Start_width)

Question$(9)= "END FLIGHT WIDTH:  "
Reply$(9)= "Const"

Question$(10)= "START LEADING RADIUS:  "
Reply$(10)= VAL$(SLeading_radius)

Question$(11)= "END LEADING RADIUS:  "
Reply$(11)= VAL$(ELeading_radius)

Question$(12)= "START TRAILING RADIUS:  "
Reply$(12)= VAL$(STrailing_radius)

Question$(13)= "END TRAILING RADIUS:  "
Reply$(13)= VAL$(ETrailing_radius)

Question$(14)= "BACK CUTOFF:  "
Reply$(14)= "0"

Input_box:!
Stat=SetInputFormat("n8","")
Stat= DisplayMessage(" ")
Stat=ChangeLabelStr("MultiLineShell","Reference Entity Prompts")
Input_stat=MultiInput(Question$(*),Reply$(*),0)
IF (ExitScript(Destination$)) THEN Leave
IF Input_stat=27 THEN Leave
Stat= DisplayMessage(" ")

Analyze_answers:!
A$= Reply$(1)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Shank_length)
IF Stat=1 THEN Input_box
IF Shank_length< 0.001 THEN Input_box
No_slength_var=1

A$= Reply$(2)
Answer$= TRIM$(A$)
IF Answer$="L" OR Answer$="l" THEN 
	Hand= WsLeft
ELSE
	Hand= WsRight
END IF

A$= Reply$(3)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Screw_diameter)
IF Stat=1 THEN Input_box
IF Screw_diameter< 0.001 THEN Input_box
No_dia_var=1

A$= Reply$(4)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Start_pitch)
IF Stat=1 THEN Input_box
IF Start_pitch< 0.001 THEN Input_box
No_spitch_var=1

A$= Reply$(5)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Const")>0) THEN
        End_pitch=0
        No_epitch_var=1
ELSE
	Stat= EvaluateAnswer(Answer$,End_pitch)
	IF Stat=1 THEN Input_box
	IF End_pitch< 0.001 THEN Input_box
        No_epitch_var=1
END IF

A$= Reply$(6)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Screw_length)
IF Stat=1 THEN Input_box
IF Screw_length< 0.001 THEN Input_box
No_length_var=1

A$= Reply$(7)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,End_depth)
IF Stat=1 THEN Input_box
IF End_depth< 0.001 THEN Input_box
No_edepth_var=1

A$= Reply$(8)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Start_width)
IF Stat=1 THEN Input_box
IF Start_width< 0.001 THEN Input_box
No_swidth_var=1

A$= Reply$(9)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Const")>0) THEN
        End_width=0
        No_ewidth_var=1
ELSE
	Stat= EvaluateAnswer(Answer$,End_width)
	IF Stat=1 THEN Input_box
	IF End_width< 0.001 THEN Input_box
        No_ewidth_var=1
END IF

A$= Reply$(10)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Connect")>0) THEN
	V1= FindNamedVar("Curr_lead_radius",WsVariationVars)
        SLeading_radius= VariableValue(V1)
        IF SLeading_radius>0 THEN
                SLead_rad_var$= "Curr_lead_radius"
                No_slead_rad_var=0
        ELSE
                GOTO Input_box
        END IF
ELSE
	Stat= EvaluateAnswer(Answer$,SLeading_radius)
	IF Stat=1 THEN Input_box
        No_slead_rad_var=1
END IF

A$= Reply$(11)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Const")>0) THEN
        ELeading_radius= 0
        No_elead_rad_var=1
ELSE
	Stat= EvaluateAnswer(Answer$,ELeading_radius)
	IF Stat=1 THEN Input_box
        No_elead_rad_var=1
END IF


A$= Reply$(12)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Connect")>0) THEN
        V1= FindNamedVar("Curr_trail_radius",WsVariationVars)
        STrailing_radius= VariableValue(V1)
        IF STrailing_radius>0 THEN
                STrail_rad_var$= "Curr_trail_radius"
                No_strail_rad_var=0
        ELSE
                GOTO Input_box
        END IF
ELSE
	Stat= EvaluateAnswer(Answer$,STrailing_radius)
	IF Stat=1 THEN Input_box
        No_strail_rad_var=1
END IF

A$= Reply$(13)
Answer$= TRIM$(A$)
IF Answer$= "C" OR Answer$="c" OR (POS(Answer$,"Const")>0) THEN
        ETrailing_radius= 0
        No_etrail_rad_var=1
ELSE
	Stat= EvaluateAnswer(Answer$,ETrailing_radius)
	IF Stat=1 THEN Input_box
        No_etrail_rad_var=1
END IF


A$= Reply$(14)
Answer$= TRIM$(A$)
Stat= EvaluateAnswer(Answer$,Back_cutoff)
IF Stat=1 THEN Input_box

Stat=SetInputFormat("n4","")
PlotAll


Make_record:!
WPKClearErrorFlag
Stat= GenerateVarName("Body",Cname$)
Stat= GenerateVarName(WsGroupEnt,Name$)
Stat= GenerateVarName(WsPointEnt,Pname$)
Stat= GenerateVarName(WsPointEnt,Prop_name$)
RecordFunctionOn
Stat= RecordDescr("SCREW: Ramped Start")
Stat= DisplayMessage("Current Section #1")
WPKEndSession
Stat= PrintToVarRecord("WPKEndSession")
V0= FreeParameter("Shank Length",Shank_length)
V1= FreeParameter("Hand",Hand)
IF No_dia_var THEN
        V2= FreeParameter("Screw Diameter",Screw_diameter)
ELSE
        V2= FreeParameter("Screw Diameter",Dia_var$)
END IF
IF No_spitch_var THEN
        V3= FreeParameter("Start pitch",Start_pitch)
ELSE
        V3= FreeParameter("Start pitch",Spitch_var$)
END IF
IF No_epitch_var THEN
	IF End_pitch=0 THEN
        	V4= FreeParameter("End pitch",V3)
	ELSE
        	V4= FreeParameter("End pitch",End_pitch)
	END IF
ELSE
        V4= FreeParameter("End pitch",Epitch_var$)
END IF
IF No_length_var THEN
        V5= FreeParameter("Section Length",Screw_length)
ELSE
        V5= FreeParameter("Section Length",Length_var$)
END IF
V6= FreeParameter("Start channel depth",Start_depth)
IF No_edepth_var THEN
	IF End_depth=0 THEN
        	V7= FreeParameter("End channel depth",V6)
	ELSE
        	V7= FreeParameter("End channel depth",End_depth)
	END IF
ELSE
        V7= FreeParameter("End channel depth",Edepth_var$)
END IF
IF No_swidth_var THEN
        V8= FreeParameter("Start flight width",Start_width)
ELSE
        V8= FreeParameter("Start flight width",Swidth_var$)
END IF
IF No_ewidth_var THEN
	IF End_width=0 THEN
        	V9= FreeParameter("End flight width",V8)
	ELSE
        	V9= FreeParameter("End flight width",End_width)
	END IF
ELSE
        V9= FreeParameter("End flight width",Ewidth_var$)
END IF
IF No_slead_rad_var THEN
        V31= FreeParameter("Start leading radius",SLeading_radius)
ELSE
        V31= FreeParameter("Start leading radius",SLead_rad_var$)
END IF
IF No_elead_rad_var THEN
        V32= FreeParameter("End leading radius",ELeading_radius)
ELSE
        V32= FreeParameter("End leading radius",ELead_rad_var$)
END IF
IF No_strail_rad_var THEN
        V33= FreeParameter("Start Trailing radius",STrailing_radius)
ELSE
        V33= FreeParameter("Start Trailing radius",STrail_rad_var$)
END IF
IF No_etrail_rad_var THEN
        V34= FreeParameter("End Trailing radius",ETrailing_radius)
ELSE
        V34= FreeParameter("End Trailing radius",ETrail_rad_var$)
END IF
V10= FreeParameter("Start angle",0.0)
Workr= CurrentWorkplane
Stat= SetWorkplane
Pc= PointXYZ(0,0,0)
Ps= PointXYZ(V0,0,0)
ShankCylinder=WPKCylinder(Pc,Ps,VariableValue(V2)/2,V0)
Stat= WPKNameBody(ShankCylinder,Cname$)
Stat= WPKSetBodyParent(ShankCylinder)
Stat= DeleteEntity(Pc)
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
V11= FreeParameter("Left Wall angle",Left_wall_angle)
V12= FreeParameter("Right Wall angle",Right_wall_angle)
V13= FreeParameter("Zstart ",ZPointValue(Ps))
V14= FreeParameter("Angular step", Astep)
V15= FreeParameter("Flight od taper", 0.0)
V16= FreeParameter("Flight taper type", 1)
V17= FreeParameter("Front Cutoff", 1)
V18= FreeParameter("Back Cutoff", Back_cutoff)
V20= FreeParameter("Bottom type", 1)
V21= FreeParameter("Make solid", 0)
Prop_data= CreateUserData(20010,"Screw",CHR$(10))
Stat= PutUserString(Prop_data,"Class name:","Extrusion Screw")
Stat= PutUserValue(Prop_data,"Class id number:",20010)
Stat= PutUserString(Prop_data,"Name:","Simple Screw")
IF Hand= WsRight THEN
	Stat= PutUserString(Prop_data,"Hand:","Right")
ELSE
	Stat= PutUserString(Prop_data,"Hand:","Left")
END IF
Stat= PutUserValue(Prop_data,"Section number:",1)
Stat= PutUserString(Prop_data,"Section type:",Section_type$)
Stat= PutUserValue(Prop_data,"Number of flights:",1)
Stat= PutUserValue(Prop_data,"Screw diameter:",V2)
Stat= PutUserValue(Prop_data,"Section length:",V5)
Stat= PutUserValue(Prop_data,"Start pitch:",V3)
Stat= PutUserValue(Prop_data,"End pitch:",V4)
Stat= PutUserValue(Prop_data,"Start flight width:",V8)
Stat= PutUserValue(Prop_data,"End flight width:",V9)
Stat= PutUserValue(Prop_data,"Start channel depth:",V6)
Stat= PutUserValue(Prop_data,"End channel depth:",V7)
Stat= PutUserValue(Prop_data,"Start leading radius:",V31)
Stat= PutUserValue(Prop_data,"End leading radius:",V32)
Stat= PutUserValue(Prop_data,"Start trailing radius:",V33)
Stat= PutUserValue(Prop_data,"End trailing radius:",V34)
Stat= PutUserValue(Prop_data,"Leading flank angle:",V11)
Stat= PutUserValue(Prop_data,"Trailing flank angle:",V12)
Stat= PutUserValue(Prop_data,"Flight od taper:",V15)
Stat= PutUserValue(Prop_data,"Flight od taper type:",V16)
Stat= PutUserValue(Prop_data,"Front cutoff type:",V17)
Stat= PutUserValue(Prop_data,"Back cutoff type:",V18)
Stat= PutUserValue(Prop_data,"Angular step:",V14)
Stat= PutUserValue(Prop_data,"Bottom type:",V20)
Stat= PutUserValue(Prop_data,"Make solid:",V21)
Stat= NameEntity(Prop_data,Prop_name$)
Bodygroup= WPKSimpleScrew(Prop_data,V13,V10)
Stat= WPKNameBodyGroup(Bodygroup,Name$)
Stat= WPKSetBodyParent(Bodygroup,1)
Pkassembly= WPKCreateAssembly(Bodygroup)
Stat= WPKNameEntity(Pkassembly,"ScrewSection1")
Stat= WPKSetBodyParent(Pkassembly)
Stat= DeleteEntity(Bodygroup)
G1= CreateGroup("  ")
Stat= AddToGroup(G1,ShankCylinder)
Stat= AddToGroup(G1,PkAssembly)
PkScrewAssembly= WPKCreateAssembly(G1)
Stat= WPKNameEntity(PkScrewAssembly,"ScrewAssembly")
Stat= DeleteEntity(G1)
Stat= SetWorkplane
Pe= PtIncrXyz(Ps,V5,0,0)
Stat= NameEntity(Pe,Pname$)
V22=NumericVariable("Curr_Section",WsVariationVars,1)
V22=NumericVariable("Screw_Hand",WsVariationVars,V1)
V22=NumericVariable("Curr_Flight_Dia",WsVariationVars,V2)
V23=NumericVariable("Curr_Flight_Pitch",WsVariationVars,V4)
V23=NumericVariable("Curr_Flight_Depth",WsVariationVars,V7)
V24=NumericVariable("Curr_Flight_Width",WsVariationVars,V9)
V25= FreeParameter("Flight_End_Angle", VarPitchAngle(V1,V3,V4,V5,V10))
V26=NumericVariable("Curr_Flight_Angle",WsVariationVars,V25)
V27=NumericVariable("Curr_Start_Length",WsVariationVars,XPointValue(Pe))
V28=NumericVariable("Curr_Lead_Radius",WsVariationVars,V32)
V29=NumericVariable("Curr_Trail_Radius",WsVariationVars,V34)
Stat=SetWorkplane(Workr)
Stat= DeleteEntityList(Ps)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("simple screw")
Stat= AddItemToUndo(WsUBCreateMode,Pname$)
Stat= AddItemToUndo(WsUBCreateMode,Prop_name$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

ResizeAll


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




