
! script name: wscturn.d/incrleadin
! var_topic: add a incremental leadin move to a lathe contour

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

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

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= CurrentVarObject
IF NOT ValidGeometry(Var_object) THEN
        Var_object=OpenVarObject("Program")
END IF
! Var_object= CheckVarObject
! IF (ExitScript(Destination$)) THEN Leave
Stat=SetXyzInput(WsLatheInput)

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 LEADIN 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 LEADIN MOVE ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_z_var= LastVariableInput(Z_var$)


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

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

Stat=InsertIntoGrp(Contour$,L1,1)
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=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
