
! script name: 3dintersect.d/trimfreept
! 3DTOPIC: free point on a surface trim curve

!A
!A NAME:
!A
!A 	Trim Curve Free Point Fillet Radius
!A
!A DESCRIPTION:
!A
!A 	This script makes a circle at a trim curve free point.
!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]

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

Solid_axis=1

ActivateUndo
Start:!
Intersect2:StdWorkplane

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

UVPoint=LastUVSurfPick(Surface)
IF NOT ValidGeometry(UVPoint) THEN Start
U=XPointValue(UVPoint)
V=YPointValue(UVPoint)
TrimUV=ClosestTrimUV(Surface,U,V)
IF ValidGeometry(TrimUV) THEN 
	U=XPointValue(TrimUV)
	V=YPointValue(TrimUV)

	Etype= EntityType(Surface)
	SELECT Etype
	CASE WsRuledSurfEnt,WsTranslationEnt
        	UorV=1
       		Circle_type=1
	CASE WsRevolutionEnt
       		UorV=0
        	Circle_type=1
	CASE ELSE
       		UorV=1
        	Circle_type=3
	END SELECT
	Cent= SurfFlowCircle(Surface,U,V,UorV,Circle_type)
	Stat= DeleteEntity(TrimUV)

	ActivateUndo
	Stat= AdvanceUndoNumber("tangents")
	Stat= AddItemToUndo(WsUBCreateMode,Cent)

	SELECT Etype
	CASE WsRevolutionEnt
		IF Solid_axis THEN
			Sline= SolidAxis(Surface)
			IF ValidGeometry(Sline) THEN
			IF ValidGeometry(Cent) THEN
				PlotOff
				Pc= CircleCenter(Cent)
				Ps= ParameterPt(Sline,0)
				Pe= ParameterPt(Sline,1)
				D1= DistTwoPts(Ps,Pc)
				D2= DistTwoPts(Pe,Pc)
				IF D1> D2 THEN
				    L1= ReverseEnt(Sline)
				    Stat= DeleteEntity(Sline)
				    Sline= L1
				END IF
				Stat= DeleteEntity(Pc)
				Stat= DeleteEntity(Ps)
				Stat= DeleteEntity(Pe)
				PlotOn
				Stat= PlotEntity(Sline)
				Stat= AddItemToUndo(WsUBCreateMode,Sline)
			END IF
			END IF
		END IF
	END SELECT
END IF
Stat= DeleteEntity(UVPoint)


GOTO Intersect2


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