
! script name: v3dextend.d/ctrimtaperpln
! var_topic: extend trim curve with taper bicubic surface to a plane

!A
!A NAME:
!A
!A 	Taper Extend Trim Curve To A Plane: Bicubic	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will create a new bicubic surface by extending a trim curve
!A 	of the surface with the specified taper to a specified plane.
!A
!B INSTRUCTIONS:
!B
!B 	TAPER ANGLE: Enter the angle of taper.
!B
!B 	PICK PLANE: Pick the plane of the bottom.
!B
!B 	PICK PROJECTION LINE: Pick the line defining the direction of
!B 		projection.
!B
!B 	PATCH WIDTH : Enter the width of the patch to be used along
!B 		the trim curve.
!B
!B 	PICK TRIM CURVE ON SURFACE: Pick the trim curve on surface.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: cubic trim taper to plane ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Destination$[256]
DIM Surface$[256]
DIM Taper_var$[256]
DIM Project_plane$[256]
DIM Project_line$[256]
DIM Name$[256]
DIM Patch_var$[256]

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


ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.25)
Tol=NamedVarVal("3D Fillet Tol",Ws3DSystemVars,0.005)

Start:!
stat= SetInputFormat("n4","")
stat= SetAngleEquals(Taper_angle)
Taper_angle= InputAngle("TAPER ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_taper_var= LastVariableInput(Taper_var$)

Pick_plane:stat= SetInputFormat("n4=","")
Stat= SetPickMask(WsPickSurfOnly)
Project_plane= PickEntity("PICK PLANE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Project_plane) THEN Pick_plane
Stat= EntityNameCheck(Project_plane,Project_plane$)
Etype= EntityType(Project_plane)
IF Etype<> WsPlaneSolidEnt THEN Pick_plane
Stat= SetPickMask(WsPickAll)


Pick_line:stat= SetInputFormat("n4=","")
Project_line= PickSpecificEnt("PICK PROJECTION LINE ",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Project_line) THEN Pick_line
Stat= EntityNameCheck(Project_line,Project_line$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Patch_width)
V_width= GetValue("PATCH WIDTH ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_patch_var= LastVariableInput(Patch_var$)
U_width= V_width
Patch_width= V_width

Intersect2:!
Pick_loop:!
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Surface=PickEntity("PICK TRIM CURVE ON SURFACE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_loop
Stat= EntityNameCheck(Surface,Surface$)

Which1=LastSurfTrimPick(Surface)
Stat=SetPickMask(WsPickGeometry)
Dir1=1


Stat= GenerateVarName(WsCubicSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("BICUBIC: Taper trim extension to plane")
Stat= SetRecDelLastExec
V1= FreeParameter("Which curve",Which1)
V2= FreeParameter("Direction",Dir1)
V3= FreeParameter("Tolerance",Tol)
IF No_taper_var THEN
        V4= FreeParameter("Taper",Taper_angle)
ELSE
        V4= FreeParameter("Taper",Taper_var$)
END IF
IF No_patch_var THEN
        V5= FreeParameter("Patch width",Patch_width)
ELSE
        V5= FreeParameter("Patch width",Patch_var$)
END IF
Norm_line= SurfNormalLine(Project_plane$,0.0,0.0,1.0,WsForward)
Proj_center= ParameterPt(Norm_line,0.0)
Plane_normal= LineVector(Norm_line)
Proj_vector= LineVector(Project_line$)
S1= TrimExtendSurf(WsTaperExt,WsCubicSurfEnt,Surface$,V1,V2,V4,V5,V5,V3,Proj_Center,Plane_normal,Proj_Vector)
Stat= NameEntity(S1,Name$)
stat= DeleteEntityList(Proj_Vector,Proj_Center,Plane_normal,Norm_line)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cubic ext surf")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2

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