
! script name: 3dintersect.d/curve2pts
! 3dtopic: make curve on surface between two points.

!A
!A NAME:
!A
!A 	MAKE CURVE ON SURFACE BETWEEN TWO POINTS
!A
!A DESCRIPTION:
!A
!A 	This script takes a a curve on a surface between two points.
!A	The curve is the resultant of a straight line drawn in the UV
!A	plane mapped onto the surface.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE: Pick the surface.
!B
!B 	PICK POINT #1:  Pick the first point on the surface.
!B
!B 	PICK POINT #2:  Pick the second point on the surface.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: curve two points ")

DIM Destination$[256]
DIM Answer$[256]

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

ActivateUndo
Start:!
Intersect2:StdWorkplane

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

Pick_point1:Stat= SetPickMask(WsPickNoSurf)
Stat=SetInputFormat("n4","")
Ploop:P1=XyzInput("INPUT FIRST POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetLastPoint(P1,WsXyzInput)
UVPoint1= PointOnSurface(P1,Surface,Tol,WsReturnUVPoint)
IF NOT ValidGeometry(UVpoint1) THEN Pick_point1

Pick_point2:Stat= SetPickMask(WsPickNoSurf)
P2=XyzInput("INPUT SECOND POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetLastPoint(P2,WsXyzInput)
Stat= SetPickMask(WsPickGeometry)
UVPoint2= PointOnSurface(P2,Surface,Tol,WsReturnUVPoint)
IF NOT ValidGeometry(UVpoint2) THEN 
	Stat= DeleteEntity(UVPoint1)
	GOTO Pick_point1
END IF

Center= PointXYZ(0.0,0.0,0.0)
Curve1= CreateGroup("TEMP")
L1= LineTwoPoints(UVPoint1,UVPoint2)
Stat= AddToGroup(Curve1,L1)
Curve= ScaleGroup(Curve1,Center,10.0)

XYcurve= UVCurveOnSurf(Curve,Surface,Tol)

Stat= DeleteGroup(Curve,WsTrue)
Stat= DeleteGroup(Curve1,WsTrue)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Center)
Stat= DeleteEntity(UVPoint1)
Stat= DeleteEntity(UVPoint2)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)

ActivateUndo
Stat= AdvanceUndoNumber("surface curve")
Stat= AddGroupToUndo(WsUBCreateMode,XYcurve,1,WsTrue)
GOTO Pick_point1


Leave:!
Stat= DeleteGroup(Curve,WsTrue)
Stat= DeleteGroup(Curve1,WsTrue)
Stat= DeleteEntity(UVPoint1)
Stat= DeleteEntity(UVPoint2)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Center)
stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickGeometry)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
