
! script name: 3dmacros.d/taperedcurve
! EXAMPLE: create a cavity with tapered sides in the shape of the cavity

!A
!A NAME:
!A
!A 	Tapered Contour
!A
!A DESCRIPTION:
!A
!A 	This script creates a cavity with tapered sides in the shape of the
!A 	contour.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick the contour to be used to create the cavity.
!B
!B 	CAVITY DEPTH: Enter the depth of the cavity.
!B
!B 	TAPER ANGLE: Enter the angular taper of the sides of the cavity.
!B
!B 	PATCH WIDTH: Enter the patch width to be used.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: tapered contour ")

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

ActivateUndo
Surface_type=WsRuledSurfEnt

Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1
Stat=SetInputFormat("n4","")

Pick_loop: !
StdWorkplane
Stat=SetInputFormat("n0",",P,")
Contour1=PickGroupEnt("PICK CONTOUR",0)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Contour1) THEN Pick_loop

Stat=Highlight(Contour1,WsPickPen,WsDirArrowOff)

Depth=GetValue("CAVITY DEPTH",Answer$)
IF ExitScript(Destination$) THEN Leave
Depthr=Depth

Stat=SetEqualsValue(Taperr)
Taper=InputAngle("TAPER ANGLE")
IF ExitScript(Destination$) THEN Leave
Taperr=Taper

IF Surface_type=WsCubicSurfEnt THEN
	Stat=SetInputFormat("n4=","")
	Stat=SetEqualsValue(Patch_width)
	Patch_width=GetValue("PATCH WIDTH",Answer$)
	IF ExitScript(Destination$) THEN Leave
END IF

Direction=WsForward
Dist=0
Path1=OffsetContour(Contour1,Dist,Direction,WsNoLook,WsCircleMoves,Pen_color,WsDirArrowOff)

Dist=Depth*TAN(Taper)
Path2=OffsetContour(Contour1,Dist,Direction,WsNoLook,WsCircleMoves,Pen_color,WsDirArrowOff)

Pc=PointXYZ(0,0,-Depth)
T1=AngleTransform(Pc,0,0,0)

Stat=TransGroupTrans(Path2,T1)

Stat=DeleteEntity(Pc)
Group=CreateGroup("TEMP")
Stat=AddToGroup(Group,Path1)
Stat=AddToGroup(Group,Path2)

Blend: !
StdWorkplane

SELECT Surface_type
    CASE WsRuledSurfEnt
	Ruled_type=1
	Surf1=RuledSurface(Ruled_type,path1,path2,"RULED SURFACE")
    CASE WsCubicSurfEnt
	Group=CreateGroup("TEMP")
	Stat=AddToGroup(Group,Path1)
	Stat=AddToGroup(Group,Path2)

	Grp_count=GroupCount(Group)
	Surf1=EqualElementSurf(WsCubicSurfEnt,Group,"BLEND",Patch_width)

	Stat=DeleteGroup(Group,1)
END SELECT
ActivateUndo
Stat= AdvanceUndoNumber("ruled surf")
Stat= AddItemToUndo(WsUBCreateMode,Surf1)

GOTO Pick_loop

Leave:!
IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
Stat=DeleteEntity(Pc)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
