
! script name: milacron.d/ventcutoutbody
! topic: create vent cutout bodies

!A
!A NAME:
!A
!A	Vent Cutout Bodies
!A
!A DESCRIPTION:
!A
!A	This function creates vent cutout bodies. Use Trim Vent Cutout Body
!A	to modify the bodies. Use Subtract Vent Cutout Bodies to subtract the shape
!A	from the main screw.
!A
!B INSTRUCTIONS:
!B
!B
!C NOTE:
!C
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: ventcutoutbody ")

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

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

Astep= 10.0

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

Stat=SetInputFormat("n0=","")
Stat= SetEqualsValue(Nflights)
Nflights=GetValue("NUMBER OF ROWS")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Dia)
Dia=GetValue("BALL DIAMETER")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Slead)
Slead=GetValue("START LEAD")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Slead)
Elead=GetValue("END LEAD")
IF (ExitScript(Destination$)) THEN Leave

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

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

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Startx)
Startx=GetValue("START X")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Endx)
Endx=GetValue("END X")
IF (ExitScript(Destination$)) THEN Leave

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

Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("BODY: Vent Cutout Bodies ")
Workr= CurrentWorkplane
Stat= SetWorkplane
V0= FreeParameter("Type",1)
V1= FreeParameter("Hand",Hand)
V2= FreeParameter("Number of rows",Nflights)
V3= FreeParameter("Ball diameter",Dia)
V6= FreeParameter("Start lead",Slead)
V7= FreeParameter("End lead",Elead)
V8= FreeParameter("Start depth",Sdepth)
V9= FreeParameter("End depth",Edepth)
V10= FreeParameter("Starting X",Startx)
V11= FreeParameter("Ending X",Endx)
V12= FreeParameter("Start angle",Astart)
V13= FreeParameter("Angular step",Astep)
Prop_grp= GrpOfUserProps(20000,21000)
P1= GroupElement(Prop_grp,1)
P2= GroupElement(Prop_grp,9999)
V20= FreeParameter("Start Diameter",GetUserValue(P1,"Starting outer diameter:"))
V21= FreeParameter("End Diameter",GetUserValue(P2,"Ending outer diameter:"))
V22= FreeParameter("Total length",(GetUserValue(P2,"Xstart:")+GetUserValue(P2,"Section length:")))
V23= FreeParameter("Diameter difference",(VariableValue(V21)-VariableValue(V20)))
V24= FreeParameter("Starting parameter",(VariableValue(V10)/VariableValue(V22)))
V4= FreeParameter("Starting outer diameter",(VariableValue(V20)+VariableValue(V24)*VariableValue(V23)))
V25= FreeParameter("Ending parameter",(VariableValue(V11)/VariableValue(V22)))
V5= FreeParameter("Ending outer diameter",(VariableValue(V20)+VariableValue(V25)*VariableValue(V23)))
Bodygroup=WPKVentGrooveBody(V0,V1,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11,V12,V13)
Stat= WPKNameBodyGroup(Bodygroup,Name$)
Stat= WPKSetBodyParent(Bodygroup,1)
Stat= DeleteEntity(Bodygroup)
Stat= DeleteEntity(Prop_grp)
Stat=SetWorkplane(Workr)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

PlotAll
Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("vent cutout bodies")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Ploop

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