
! script name: v3dwrap.d/makeodspiralcut
! var_topic: cuts a spiral around a cylinder

!A
!A NAME:
!A
!A 	Make OD Rotary Spiral Cut	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a spiral rotary cut between two positions. Designed
!A	for output on a Mill-Turn machine.
!A
!B INSTRUCTIONS:
!B
!B 	CUT ALONG Wall or Centerline:
!B
!B 		W - Wall cutting positions the cutter along
!B 		    the side of the contour as if it is a wall.
!B 		C - Centerline cutting will place the center
!B 		    of the tool along the wrapped contour.
!B
!B 		The angular orientation of the cutter is determined by the
!B 		normal vector to the cylinder.
!B
!B 	TOLERANCE: Enter the tolerance for the wrapping operation.
!B
!B 	RADIUS OF CYLINDER: Enter the radius
!B 		of cylinder to be wrapped around.
!B
!B 	STARTING ANGLE: Starting angular
!B 		coordinate of the wrapped entity.
!B
!B 	Z CUTTER DISPLACEMENT: Enter the Z displacement of
!B 		cutter relative to the Z or the wrapping cylinder.
!B
!B
!C NOTES:
!C
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: make spiral rotary cut ")

DIM Destination$[256]
DIM Answer$[256]
DIM Datastr$[4000]
DIM Tool_name$[256]
DIM Tool_type$[256]
DIM Surface_dir$[256]
DIM Tool_name$[256]
DIM Tool_image$[256]
DIM Toolid$[256]
DIM Finish_var$[256]
DIM Radius_var$[256]
DIM Astart_var$[256]
DIM Angle_var$[256]
DIM Zstart_var$[256]
DIM Zend_var$[256]
DIM Xdist_var$[256]
DIM Name$[256]

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


ActivateUndo
Tol=NamedVarVal("3D Cutting Tol",Ws3DSystemVars,0.005)
Start:!
Stat=SetInputFormat("a1=",",W,C,")
Stat=SetEqualsValue(0,"W")
Stat=GetValue("CUT ALONG Wall or Centerline",Answer$)
IF ExitScript(Destination$) THEN Leave

Centerline_cut=(Answer$="C")
Pen_color=CurrentPen

Cutter_type=NamedVarVal("cutter type",WsSystemVars,Cutter_type)
Stat=ToolSelectBox("TOOLS","selected tool",WsAllMills)
IF Stat THEN 
  Stat= MessageFileBox("/usr/weber/database/messages/notoolsloaded","ATTENTION")
  GOTO Leave
END IF
Tool_ques:!
Stat=SetInputFormat("a99","")
Stat=GetValue("CUTTER PATH TOOL",Tool_name$)
IF ExitScript(Destination$) THEN Leave
IF Tool_name$= "CANCEL" THEN Leave
Tool=FindUserData(Tool_name$,WsToolData)
Stat=GetUserString(Tool,"Tool type:",Toolid$)
IF NOT POS(Toolid$, "MILL") THEN Tool_ques
LowerSelectBox


Past_dia:!
IF NOT Centerline_cut THEN
	Finishr=NamedVarVal("finish allowance",WsSystemVars,0.0)
	Stat=SetInputFormat("n4=","")
	Stat=SetEqualsValue(Finishr)
	Finish_allow=GetValue("FINISH ALLOWANCE",Answer$)
	IF ExitScript(Destination$) THEN Leave
	Finishr=Finish_allow
	No_finish_var= LastVariableInput(Finish_var$)
	Vfinish=CreateVariable("finish allowance",WsSystemVars,Finishr)
ELSE
	No_finish_var= 1
	Finish_allow=0
END IF

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

Ask_radius:Stat=SetInputFormat("n4=","")
Radius=InputRadius("RADIUS OF CYLINDER")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Ask_radius
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF

Start_angle:!
Astart=InputAngle("STARTING ANGLE")
IF ExitScript(Destination$) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Angle)
Angle=GetValue("ANGULAR EXTENT")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xstart)
Zstart=GetValue("Z START")
IF ExitScript(Destination$) THEN Leave
No_zstart_var= LastVariableInput(Zstart_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Zend)
Zend=GetValue("Z END")
IF ExitScript(Destination$) THEN Leave
No_zend_var= LastVariableInput(Zend_var$)


Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xdist)
Xdist=GetValue("X CUTTER DISPLACEMENT")
IF ExitScript(Destination$) THEN Leave
No_xdist_var= LastVariableInput(xdist_var$)

Ploop:!

Stat=SetPickMask(WsPickAll)

Direction=WsForward
Side=0
IF NOT Centerline_cut THEN
	Side=1
	Direction= WsForward
	Stat=SetInputFormat("a1=",",L,R,")
	Stat=SetEqualsValue(0,"L")
	Stat=GetValue("  Left or Right OF WALL",Answer$)
	IF ExitScript(Destination$) THEN Leave
	IF Answer$= "L" THEN
		Side= 1
	ELSE
		Side= -1
	END IF
END IF
Stat=SetCurrentColor(Pen_color)
Nsign=1


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CUTTERPATH: Od manual rotary")
Stat= SetRecDelLastExec
IF No_finish_var THEN
        V1= FreeParameter("Finish allowance",Finish_allow)
ELSE
        V1= FreeParameter("Finish allowance",Finish_var$)
END IF
IF No_radius_var THEN
	V9= FreeParameter("Radius",Radius)
ELSE
	V9= FreeParameter("Radius",Radius_var$)
END IF
IF No_astart_var THEN
        V2= FreeParameter("Astart",Astart)
ELSE
        V2= FreeParameter("Astart",Astart_var$)
END IF
IF No_angle_var THEN
        V3= FreeParameter("Angular Increment",Angle)
ELSE
        V3= FreeParameter("Angular Increment",Angle_var$)
END IF
IF No_zstart_var THEN
        V4= FreeParameter("Z Start",Zstart)
ELSE
        V4= FreeParameter("Z Start",Zstart_var$)
END IF
IF No_zend_var THEN
        V5= FreeParameter("Z End",Zend)
ELSE
        V5= FreeParameter("Z End",Zend_var$)
END IF
V6= FreeParameter("X Start",Xstart)
V7= FreeParameter("X End",Xend)
Work= CurrentWorkplane
Stat= SetWorkplane
Ps= PointXYZ(V4,0,V6)
Pe= PointXYZ(V5,PI*VariableValue(V9)*VariableValue(V3)/180,V7)
L1= LineTwoPoints(Ps,Pe)
C1= CreateGroup(" ")
Stat= AddToGroup(C1,L1)
P1= PointXYZ(0,0,0)
P2= PointXYZ(0,1,0)
P3= PointXYZ(-1,0,0)
Trans1= ThreePtTrans(P1,P2,P3)
Stat= SetWorkplane(Trans1)
V10= FreeParameter("Taper",Taper)
IF No_xdist_var THEN
        V11= FreeParameter("X Distance",Xdist)
ELSE
        V11= FreeParameter("X Distance",Xdist_var$)
END IF
V12= FreeParameter("Side",Side)
V13= FreeParameter("Tolerance",Tol)
V15= FreeParameter("Normal direction",Nsign)
Tool=FindUserData(Tool_name$,WsToolData)
Mdef1= ToolMillingDef(Tool,WsClimb)
Stat=AssociateTool(Mdef1,Tool)
Stat= MillDefCutInfo(Mdef1,V12,0.0,V1,0.0,1,V13)
Stat= MillDefZInfo(Mdef1,1,V11)
G1=CutWrapCurve(Mdef1,C1,V9,V2,V10,V13,V15)
Stat= AutoNameGroup(G1,Name$)
Stat= DeleteEntityList(Mdef1,P1,P2,P3,Ps,Pe)
Stat= DeleteGroup(C1,WsTrue)
Stat= SetNoPathFlag(G1,WsTrue)
Stat= SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(G1) THEN
        DelLastVarRecord
	Curr_record= 0
ELSE
        Stat= AnimateTool(Tool,G1)
	ActivateUndo
	Stat= AdvanceUndoNumber("manual od rotary")
	Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Start_angle

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

END

