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

!A
!A NAME:
!A
!A 	Add Moves: Incremental Lead Out	VARIATIONAL
!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 CONTOUR TO BE CHANGED: Pick an element
!B 		of the lathe contour 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

IF ARGC>1 THEN
	Feed_move= VAL(ARGV(1))
ELSE
	Feed_move= 1
END IF

ActivateUndo
Stat=SetXyzInput(WsXyzInput)
Start: !

Pick_contour:stat= SetInputFormat("n4","")
Contour= PickGroupEnt("PICK CONTOUR TO BE CHANGED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)
IF NOT IsEntVariational(Contour) THEN
   Stat=SetInputFormat("a99","")
   Stat= GetValue("NON-VDM ENTITY. CANNOT USE ON NON VDM ENTITY ",Answer$)
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF



X_leadout: !
Stat= SetEqualsValue(0.0)
Stat=SetInputFormat("n4=","")
Xmove=GetValue("X 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("X leadout move ",Xmove)
ELSE
	V1= FreeParameter("X 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,V1,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
