
! script name: v3dinter.d/edgefreept
! var_topic: free point on a surface edge

!A
!A NAME:
!A
!A 	Edge Curve Free Point	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a free point on a surface edge.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ON SURFACE EDGE: Pick the free point on the surface edge.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: free edge point ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface$[256]
DIM Name$[256]

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

Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)

ActivateUndo
Endpoint_mode=0
Start:!
Intersect2:!
IF Endpoint_mode THEN
	Stat= SetPickMask(WsPickSurfOnly)
        stat= SetInputFormat("a1n0",",F,")
        Surface=PickEntity("PICK SURFACE EDGE END, Free point ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$="F" THEN 
		Endpoint_mode=0
		GOTO Start
	END IF

        IF NOT ValidDependency(Surface) THEN Intersect2
        Stat= EntityNameCheck(Surface,Surface$)

        UVPoint=LastUVSurfPick(Surface)
        IF NOT ValidGeometry(UVPoint) THEN Start
        U=XPointValue(UVPoint)
        V=YPointValue(UVPoint)
        Stat= DeleteEntity(UVPoint)

        U= 0.0*(U<= 0.50)+ 1.0*(U> 0.50)
        V= 0.0*(V<= 0.50)+ 1.0*(V> 0.50)
ELSE
	Stat= SetPickMask(WsPickSurfOnly)
	stat= SetInputFormat("a1n0",",E,")
	Surface=PickEntity("PICK ON SURFACE EDGE, Endpoint ",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$="E" THEN
		Endpoint_mode=1
		GOTO Start
	END IF
	IF NOT ValidDependency(Surface) THEN Intersect2
	Stat= EntityNameCheck(Surface,Surface$)

	UVPoint=LastUVSurfPick(Surface)
	IF NOT ValidGeometry(UVPoint) THEN Start
	U=XPointValue(UVPoint)
	V=YPointValue(UVPoint)
	Stat= DeleteEntity(UVPoint)
END IF

Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Edge Curve Free Point")
Stat= SetRecDelLastExec
Stat= NullReference(Surface$)
V1= FreeParameter("U value",U)
V2= FreeParameter("V value",V)
UVPoint=ClosestEdgeUV(Surface$,V1,V2)
Pt= SurfParameterPt(Surface$,UVPoint)
Stat= NameEntity(Pt,Name$)
Stat= DeleteEntity(UVPoint)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Pt) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("edge point")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2


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