
! script name: vpksolids.d/vpkconttaper
! var_solids: extend contour with taper 

!A
!A NAME:
!A
!A 	SOLID: Contour Taper	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will create a sheet body by extending a contour with
!A 	the specified taper.
!A
!B INSTRUCTIONS:
!B
!B 	TAPER ANGLE: Enter the angle of taper.
!B
!B 	Z CONSTANT: Enter the z of the bottom.
!B
!B 	PATCH WIDTH ALONG CONTOUR: Enter the width of the patch to be used along
!B 		the contour.
!B
!B 	PICK CONTOUR: Pick the contour.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: contour taper extension")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Patch_var$[256]
DIM Angle_var$[256]
DIM Z_var$[256]
DIM Name$[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)

Stat= GLPlotOn
Start:!

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

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Patch_width)
Z_const=GetValue("Z CONSTANT ",Answer$)
IF ExitScript(Destination$) THEN Leave
No_z_var= LastVariableInput(Z_var$)

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

Pick_contour: !
stat= SetInputFormat("a1",",P,")
Stat= SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK CONTOUR",0)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat= EntityNameCheck(Contour,Contour$)

Dir1=1

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Contour Taper")
IF No_taper_var THEN
        V1= FreeParameter("Taper angle",Taper_angle)
ELSE
        V1= FreeParameter("Taper angle",Taper_var$)
END IF
IF No_z_var THEN
        V2= FreeParameter("Z constant",Z_const)
ELSE
        V2= FreeParameter("Z constant",Z_var$)
END IF
IF No_patch_var THEN
        V3= FreeParameter("Patch width",Patch_width)
ELSE
        V3= FreeParameter("Patch width",Patch_var$)
END IF
V4= FreeParameter("Tolerance",Tol)
Proj_Vector=PointXYZ(0.0,0.0,1.0)
Proj_Center=PointXYZ(0.0,0.0,V2)
Plane_normal=PointXYZ(0.0,0.0,1.0)
PlotOff
S1=ExtendContour(WsTaperExt,WsCubicSurfEnt,Contour$,Dir1,V1,V3,V3,V4,Proj_Center,Proj_Vector,Plane_normal)
RecordFunctionOff
IF ValidGeometry(S1) THEN
        Make_record= WsTrue
        RecordFunctionOn
	Pkbody=WPKMakeBsurf(S1)
        Stat=DeleteEntity(S1,WsFalse)
        Stat= WPKNameBody(Pkbody,Name$)
        Stat= WPKSetBodyParent(Pkbody)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
PlotOn
RecordFunctionOn
Stat=DeleteEntityList(Proj_Vector,Proj_center,Plane_normal)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

IF Make_record= WsFalse THEN
        DelLastVarRecord
ELSE
	Stat= WPKUpdateBody(Pkbody)
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("tapered contour sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Pick_contour

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