
! script name: vlathe.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 CONTOUR TO BE CHANGED: Pick an
!B 		element of the lathe contour 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=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 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("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
Ps= PtIncrXyz(Pe,V2,V1,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
