
! script name: 3dintersect.d/surffreept
! 3dtopic: free point on a surface

!A
!A NAME:
!A
!A 	Surface Free Point
!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]

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

ActivateUndo
Corner_mode=0
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 ValidGeometry(Surface) THEN Intersect2
        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 ValidGeometry(Surface) THEN Intersect2
        Stat= SetPickMask(WsPickGeometry)

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

ActivateUndo
Stat= AdvanceUndoNumber("point")
Stat= AddItemToUndo(WsUBCreateMode,Pt)
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
