
! script name: v3dinter.d/trimfreept
! var_topic: free point on a surface trim curve

!A
!A NAME:
!A
!A 	Trim Curve Free Point	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a free point on a surface trim curve.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ON SURFACE TRIM CURVE: Pick the free point on the surface
!B 		trim curve.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: free trim curve 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
Start:!
Intersect2:!

Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface=PickEntity("PICK ON SURFACE TRIM CURVE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Surface) THEN Intersect2
IF NOT ValidDependency(Surface) THEN Intersect2
Stat= EntityNameCheck(Surface,Surface$)
Stat= SetPickMask(WsPickGeometry)

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

Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Trim Curve Free Point")
Stat= SetRecDelLastExec
Stat= NullReference(Surface$)
V1= FreeParameter("U value",U)
V2= FreeParameter("V value",V)
UVPoint=ClosestTrimUV(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("trim curve 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
