
! script name: v3dinter.d/curve2pts
! var_topic: make curve on surface between two points.

!A
!A NAME:
!A
!A 	MAKE CURVE ON SURFACE BETWEEN TWO POINTS    VARIATIONAL
!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 drwn 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]
DIM Surface$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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

Start:!
Intersect2:StdWorkplane

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

Stat= SetPickMask(WsPickNoSurf)
Pick_point1:stat= SetInputFormat("n4","")
E1=PickEntity("PICK POINT #1")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point1
Stat= EntityNameCheck(E1,Point1$)
Pick_para1= LastPickPara
Pick_return1= CurrPickReturn

Stat= SetPickMask(WsPickNoSurf)
Pick_point2:stat= SetInputFormat("n4","")
E1=PickEntity("PICK POINT #2")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point2
Stat= EntityNameCheck(E1,Point2$)
Pick_para2= LastPickPara
Pick_return2= CurrPickReturn

Stat= SetPickMask(WsPickAll)

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: Two points on surface")
Stat= SetRecDelLastExec
Stat= NullReference(Surface$)
Stat= SetWorkplane
SELECT Pick_return1
CASE WsGeometryEnd
     P1= ParameterReturnPt(Point1$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
     P1= ParameterReturnPt(Point1$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
     P1= ParameterReturnPt(Point1$,Pick_para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
     P2= ParameterReturnPt(Point2$,Pick_para2,WsGeometryEnd)
CASE WsGeometryMid
     P2= ParameterReturnPt(Point2$,Pick_para2,WsGeometryMid)
CASE WsGeomCenter
     P2= ParameterReturnPt(Point2$,Pick_para2,WsGeomCenter)
END SELECT
V1= FreeParameter("Tolerance",Tol)
UVPoint1= PointOnSurface(P1,Surface$,V1,WsReturnUVPoint)
UVPoint2= PointOnSurface(P2,Surface$,V1,WsReturnUVPoint)
RecordFunctionOff
IF (NOT ValidGeometry(UVPoint1)) OR (NOT ValidGeometry(UVPoint2)) THEN
	Stat= DeleteEntity(UVPoint1)
	Stat= DeleteEntity(UVPoint2)
	Stat= DeleteEntity(P1)
	Stat= DeleteEntity(P2)
	CloseVarRecord
        DelLastVarRecord
	GOTO Pick_point1
END IF
RecordFunctionOn
Center= PointXYZ(0.0,0.0,0.0)
Curve1= CreateGroup("")
L1= LineTwoPoints(UVPoint1,UVPoint2)
Stat= AddToGroup(Curve1,L1)
Curve= ScaleGroup(Curve1,Center,10.0)
XYZcurve= UVCurveOnSurf(Curve,Surface$,V1)
Stat= AutoNameGroup(XYZcurve,Name$)
Stat= DeleteGroup(Curve,WsTrue)
Stat= DeleteGroup(Curve1,WsTrue)
Stat= DeleteEntityList(L1,Center,UVPoint1,UVPoint2,P1,P2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Xyzcurve) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("curve two pts")
	Stat= AddGroupToUndo(WsUBCreateMode,XYZcurve,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_point1


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