
! script name: 3dmacros.d/wtaperedbox
! EXAMPLE: create a rectangular cavity with rounded corners and tapered sides

!A
!A NAME:
!A
!A 	Cavity
!A
!A DESCRIPTION:
!A
!A 	This script creates a rectangular cavity with rounded corners and
!A 	tapered sides.
!A
!B INSTRUCTIONS:
!B
!B 	RECTANGLE CENTER ABS X,Y: Enter the X,Y coordinates of the rectangles'
!B 		center.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	X LENGTH OF RECTANGLE: Enter the length of the rectangle, parallel to
!B 		the X axis.
!B
!B 	Y WIDTH OF RECTANGLE: Enter the width of the rectangle, parallel to the
!B 		Y axis.
!B
!B 	CORNER RADIUS: Enter the radius to be used in all corners.
!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
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: cavity ")

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

ActivateUndo
Rect_loop:!
Stat=SetInputFormat("n4","")

Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

Stat=SetInputFormat("n4=","")
Pc=XyzInput("RECTANGLE CENTER ",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetEqualsValue(Xlenr)
Xlength=GetValue("X LENGTH OF RECTANGLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Xlenr=Xlength

Stat=SetEqualsValue(Ywidr)
Ywidth=GetValue("Y WIDTH OF RECTANGLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Ywidr=Ywidth

Radius=InputRadius("CORNER RADIUS")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetEqualsValue(Depthr)
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

Stat=SetRadiusEquals(Radius)

Xcen=XPointValue(Pc)
Ycen=YPointValue(Pc)

Xlen= Xlength- 2*Radius
Ywid= Ywidth- 2*Radius

IF Xlen< 0.0005 THEN Rect_loop
IF Ywid< 0.0005 THEN Rect_loop

X0= Xcen- Xlength/2
Y0= Ycen

X01= X0
Y01= Y0 + Ywid/4

X1=Xcen-Xlen/2
Y1=Ycen+Ywid/2

X2=Xcen+Xlen/2
Y2=Y1

X3=X2
Y3=Ycen-Ywid/2

X4=Xcen-Xlen/2
Y4=Y3

X04= X0
Y04= Y0 - Ywid/4

R1=Radius

Tp0=Type1(1,X0,Y0,X01,Y01)
Tp1=Type3(3,X01,Y01,X1,Y1,0,R1)
Stat=JoinTypes(Tp0,Tp1)
Tp2=Type3(3,X1,Y1,X2,Y2,R1,R1)
Stat=JoinTypes(Tp1,Tp2)
Tp3=Type3(3,X2,Y2,X3,Y3,R1,R1)
Stat=JoinTypes(Tp2,Tp3)
Tp4=Type3(3,X3,Y3,X4,Y4,R1,R1)
Stat=JoinTypes(Tp3,Tp4)
Tp5=Type3(3,X4,Y4,X04,Y04,R1,0)
Stat=JoinTypes(Tp4,Tp5)
Tp6=Type1(1,X04,Y04,X0,Y0)
Stat=JoinTypes(Tp5,Tp6)
Stat=CloseType(Tp6)
Contour1=TypesContour(Tp6,1)

Stat=DeleteEntity(Pc)

T1=ParallelTransform(Work,-Depth)
Stat=SetWorkplane(T1)

R2=Radius-Depth*TAN(Taper)

X0= Xcen- Xlength/2 +Depth*TAN(Taper)
Y0= Ycen

X01= X0
Y01= Y0 + Ywid/4

X04= X0
Y04= Y0 - Ywid/4

Tp0=Type1(1,X0,Y0,X01,Y01)
Tp1=Type3(3,X01,Y01,X1,Y1,0,R2)
Stat=JoinTypes(Tp0,Tp1)
Tp2=Type3(3,X1,Y1,X2,Y2,R2,R2)
Stat=JoinTypes(Tp1,Tp2)
Tp3=Type3(3,X2,Y2,X3,Y3,R2,R2)
Stat=JoinTypes(Tp2,Tp3)
Tp4=Type3(3,X3,Y3,X4,Y4,R2,R2)
Stat=JoinTypes(Tp3,Tp4)
Tp5=Type3(3,X4,Y4,X04,Y04,R2,0)
Stat=JoinTypes(Tp4,Tp5)
Tp6=Type1(1,X04,Y04,X0,Y0)
Stat=JoinTypes(Tp5,Tp6)
Stat=CloseType(Tp6)
Contour2=TypesContour(Tp6,1)

Stat=DeleteEntity(Pc)

Blend: !
StdWorkplane
Ruled_type= 1
Surf1= RuledSurface(Ruled_type,contour1,contour2,"RULED SURFACE")

ActivateUndo
Stat= AdvanceUndoNumber("ruled surf")
Stat= AddItemToUndo(WsUBCreateMode,Surf1)

stat= UnLink(Contour1)
stat= DeleteGroup(Contour1,1)
stat= UnLink(Contour2)
stat= DeleteGroup(Contour2,1)
GOTO Rect_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
