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

!A
!A NAME:
!A
!A 	Surface Free Point	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a free point on a surface.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE: Pick the free point on the surface.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: surface free 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)

Corner_mode=0
ActivateUndo
Start:!
Intersect2:!

IF Corner_mode THEN
	Stat= SetPickMask(WsPickSurfOnly)
        Stat= SetInputFormat("a1n0",",F,")
        Surface=PickEntity("PICK SURFACE CORNER:     Free point ",Answer$)
        IF (ExitScript(Destination$)) THEN Leave
        IF Answer$= "F" THEN
                Corner_mode= 0
                GOTO Start
        END IF

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

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

	U= 0.0*(U<= 0.5)+ 1.0*(U> 0.5)
	V= 0.0*(V<= 0.5)+ 1.0*(V> 0.5)
ELSE
	Stat= SetPickMask(WsPickSurfOnly)
	Stat= SetInputFormat("a1n0",",C,")
	Surface=PickEntity("PICK SURFACE:     Corner ",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	IF Answer$= "C" THEN
		Corner_mode= 1
		GOTO Start
	END IF

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

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

Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Surface Free Point")
Stat= SetRecDelLastExec
Stat= NullReference(Surface$)
V1= FreeParameter("U value",U)
V2= FreeParameter("V value",V)
Pt= SurfParameterPt(Surface$,V1,V2)
Stat= NameEntity(Pt,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Pt) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("surface pt")
	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
