
! script name: 3dmacros.d/conicalhole
! EXAMPLE: create a ruled surface which is square blended into a circle

!A
!A NAME:
!A
!A 	SQUARE CIRCLE
!A
!A DESCRIPTION:
!A
!A 	This script creates a ruled surface which is a square blended
!A 	into a circle.
!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 	HEIGHT: Enter the height.
!B
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: square circle ")

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

ActivateUndo

Rect_loop:!

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

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

Diameter=InputRadius("HOLE DIAMETER",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave
Radius= Diameter/2

Taper_angle=InputAngle("TAPER ANGLE")
IF (ExitScript(Destination$)) THEN Leave

Stat=SetEqualsValue(Zheight)
ZHeight=GetValue("HEIGHT",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Xcen=XPointValue(Pc)
Ycen=YPointValue(Pc)
R1= Radius
R2= Radius+ Zheight*TAN(Taper_angle)

X0= Xcen- R1
Y0= Ycen

X1= Xcen+ R1
Y1= Ycen


R1=Radius

Tp0=Type4(4,X0,Y0,X1,Y1,0.0,R1,0.0)
Tp1=Type4(4,X1,Y1,X0,Y0,0.0,R1,0.0)
Stat=JoinTypes(Tp0,Tp1)
Stat=CloseType(Tp1)
Contour1=TypesContour(Tp1,1)

T1=ParallelTransform(Work,Zheight)

X0= Xcen- R2
Y0= Ycen

X1= Xcen+ R2
Y1= Ycen

Tp0=Type4(4,X0,Y0,X1,Y1,0.0,R2,0.0)
Tp1=Type4(4,X1,Y1,X0,Y0,0.0,R2,0.0)
Stat=JoinTypes(Tp0,Tp1)
Stat=CloseType(Tp1)
Contour2=TypesContour(Tp1,1)

Stat=TransGroupTrans(Contour2,T1,0,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
