
! script name: wscturn.d/incrleadout
! var_topic: add a incremental linear leadout move to a lathe contour

!A
!A NAME:
!A
!A 	Add Moves: Incremental Lead Out	
!A
!A DESCRIPTION:
!A
!A 	This script adds an incremental leadout move to a lathe contour.
!A	The move is measured from the contour end point.
!A
!B INSTRUCTIONS:
!B
!B 	PICK PATH TO BE CHANGED: Pick an element
!B 		of the lathe path to be changed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: incremental leadout ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Element$[256]
DIM X_var$[256]
DIM Y_var$[256]
DIM Name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

Feed_move= 1

ActivateUndo
Stat=SetXyzInput(WsXyzInput)
Start: !
Stat= SetEqualsValue(0.0,RPT$("F",Feed_move)&RPT$("R",(Feed_move=0)))
Stat=SetInputFormat("a1=",",R,F,")
Stat=GetValue("Rapid or Feed move  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Feed_move= POS(Answer$,"F")

Pick_contour:stat= SetInputFormat("n4","")
Contour= PickGroupEnt("PICK PATH TO CHANGE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)

X_leadout: !
Stat= SetEqualsValue(0.0)
Stat=SetInputFormat("n4=","")
Xmove=GetValue("DIAMETER LEADOUT MOVE ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_x_var= LastVariableInput(X_var$)

Y_leadout: !
Stat= SetEqualsValue(0.0)
Stat=SetInputFormat("n4=","")
Zmove=GetValue("Z LEADOUT MOVE ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_z_var= LastVariableInput(Z_var$)

Stat=GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Incremental leadout")
Ps=ContEndPt(Contour$)
IF No_x_var THEN
	V1= FreeParameter("Diameter leadout move ",Xmove)
ELSE
	V1= FreeParameter("Diameter leadout move ",X_var$)
END IF
IF No_z_var THEN
	V2= FreeParameter("Z leadout move ",Zmove)
ELSE
	V2= FreeParameter("Z leadout move ",Z_var$)
END IF
Pe= PtIncrXyz(Ps,V2,VariableValue(V1)/2,0.0)
L1=LineTwoPoints(Ps,Pe)

ActivateUndo
Stat= AdvanceUndoNumber("incremental leadout")
Stat= AddGroupToUndo(WsUBModifyMode,Contour$,1,WsTrue)

Stat=AddToContour(Contour$,L1)
Stat=NameEntity(L1,Name$)
IF NOT Feed_move THEN
	Stat= SetRapidFlag(L1,1)
	Stat= SetLineType(L1,8)
END IF
Stat=DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

Leave:!
Stat=SetPickReturn(WsGeometryEnd)
Stat=DeleteEntityList(Ps,Pe)
Stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
