
! script name: v3dinter.d/edgecurve
! var_topic: generates a curve along a surface edge

!A
!A NAME:
!A
!A 	EDGE CURVE	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script generates a curve along the edge of a surface.
!A
!B INSTRUCTIONS:
!B
!B 	PICK SURFACE: Pick the surface along the edge desired.
!B
!C NOTE:
!C
!C	When selecting the surface edge, position the mouse slightly toward
!C 	the interior of the surface.  Make sure that the edge pick is clearly
!C 	along the edge desired.  Avoid selecting near the corners.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: edge curve ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[256]
DIM Surface$[256]
DIM Name$[256]

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

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

ActivateUndo
Start:!

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

GOSUB Which_edge
IF NOT Surf_edge THEN Pick_loop
Which1= Surf_edge
Direction= Edge_dir


Stat= SetPickMask(WsPickGeometry)
stat= SetInputFormat("n0","")

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CURVE: Edge curve")
Stat= SetRecDelLastExec
Stat= Set3dInterOffset(0.0)
V1= FreeParameter("Tolerance",Tol)
V2= FreeParameter("Direction",Direction)
V3= FreeParameter("Which edge",Which1)
C1= EdgeCurve(Surface$,V3,V1,V2)
Stat= AutoNameGroup(C1,Name$)
Stat= SetNoPathFlag(C1,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
	Curr_record= 0
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("edge curve")
	Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_loop

Which_edge: Surf_edge= 0
Edge_dir= WsForward
Pt= LastUVSurfPick(Surface)
IF NOT ValidGeometry(Pt) THEN RETURN
U= XPointValue(Pt)
V= YPointValue(Pt)
stat= DeleteEntity(Pt)
Surf_edge= ClosestSurfEdge(Surface,U,V)

SELECT Surf_edge
CASE 1,3
        Edge_dir= WsForward
        IF(U> 0.5) THEN Edge_dir= WsReverse
CASE 2,4
        Edge_dir= WsForward
        IF(V> 0.5) THEN Edge_dir= WsReverse
END SELECT
RETURN


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