
! script name: gears.d/defgeardiametr
! topic: create gear given number of teeth, pressure angle, and outside diameter

!A NAME:
!A
!A 	DEFINE GEAR (# of teeth, pressure angle, outside diameter)
!A
!A DESCRIPTION:
!A
!A 	This script will generate a gear given the number of teeth, pressure
!A 	angle, and outside diameter.
!A
!B INSTRUCTIONS:
!B
!B 	NUMBER OF TEETH IN FULL GEAR: Enter the number of teeth on the gear
!B 		when a full circle of teeth is used.
!B
!B 	PRESSURE ANGLE: Enter the angle used to define the gear.
!B
!B 	OUTSIDE DIAMETER: Enter the diameter of the circle that forms the
!B 		tops of the teeth.
!B
!B 	TOOTH TOP -- Radial or Flat:
!B 		R - indicates the top of the tooth will be radial.
!B 		F - indicates the top of the tooth will be flat.
!B
!B 	TOOTH BOTTOM -- Radial or Flat:
!B 		R - indicates the bottom space between the teeth will be radial.
!B 		F - indicates the bottom space between the teeth will be flat.
!B
!B 	TOOTH TOP BLEND RADIUS: Enter the blending radius to be used to blend
!B 		the involute curve to the tooth top.
!B
!B 	TOOTH BOTTOM BLEND RADIUS: Enter the blending radius to be used to
!B 		blend the involute curve to the bottom of the tooth.
!B
!B 	SHRINKAGE PER INCH: Enter the amount of shrinkage that should be
!B 		included in the calculations.
!B
!B 	INVOLUTE TOLERANCE: Enter the acceptable tolerance to be used in
!B 		calculating the involute curve.
!B
!C NOTES:
!C
!C 	The Diametral Pitch, Root Diameter, Pitch Diameter, Base Diameter,
!C 	and Circular tooth Thickness will be calculated from the given
!C 	information.
!C 	The direction may be changed very easily using synergy.  Therefore for
!C 	creating the gear it is assumed to be clockwise.
!C
!# see also - htdocs/help.d/gearinfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","define gear")

DIM A$[256]
DIM Answer$[256]
DIM Destination$[256]
DIM File_name$[256]
DIM Question$[256]
DIM Tbot$[256]
DIM Ttop$[256]
DIM Title$[256]

DEG

GearDescript=11335

File_name$="/usr/weber/ascrpt/gears.d/gearinfo"
Gear_desc=FindUserData("GEAR DESCRIPTION",GearDescript)
IF NOT ValidGeometry(Gear_desc) THEN
	Gear_desc=ReadUserData(GearDescript,"GEAR DESCRIPTION",File_name$)
ELSE
	Stat=DeleteEntity(Gear_desc)
	Gear_desc=ReadUserData(GearDescript,"GEAR DESCRIPTION",File_name$)
END IF

Stat=SetInputFormat("n0"," ")
Stat=SetInputMinMax(1.0,999.0)
No_of_teeth=GetValue("NUMBER OF TEETH IN FULL GEAR",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4"," ")
Stat=SetInputMinMax(0.001,89.999)
Pressure_angle=GetValue("PRESSURE ANGLE",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n5"," ")
Stat=SetInputMinMax(0.001,1000.0)
Outside_dia=GetValue("OUTSIDE DIAMETER",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave
Diametral_pitch=(No_of_Teeth+2)/Outside_dia
Stat=PutUserString(Gear_desc,"Outside dia:","Known")

Module=1/Diametral_pitch
Pitch_dia=No_of_teeth/Diametral_pitch
Root_dia=(No_of_teeth-2.5)/Diametral_pitch
Circ_thickness=1.5708/Diametral_pitch
Chord_thickness=Pitch_dia*SIN(Circ_thickness/Pitch_dia*180/PI)

Stat=SetInputFormat("a1=",",R,F,")
Stat=SetEqualsValue(0,"R")
Stat=GetValue("TOOTH TOP -- Radial or Flat",Ttop$)
IF ExitScript(Destination$) THEN Leave
T_top=(Ttop$="R")

Stat=SetInputFormat("a1=",",R,F,")
Stat=SetEqualsValue(0,"R")
Stat=GetValue("TOOTH BOTTOM -- Radial or Flat",Tbot$)
IF ExitScript(Destination$) THEN Leave
T_bot=(Tbot$="R")

IF Outside_dia-Pitch_dia<.001 THEN Leave
Stat=SetInputFormat("n5="," ")
Rep_value=MIN(.01,Outside_dia-Pitch_dia)
Stat=SetEqualsValue(Rep_value)
Stat=SetInputMinMax(0.001,Outside_dia-Pitch_dia)
! Ttbr=GetValue("TOOTH TOP BLEND RADIUS ( 0.001 - "&VAL$(Outside_dia-Pitch_dia)&" )",Answer$)
Ttbr=GetValue("TOOTH TOP BLEND RADIUS",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n5="," ")
Stat=SetEqualsValue(Rep_value)
Stat=SetInputMinMax(0.001,Outside_dia-Pitch_dia)
! Tbbr=GetValue("TOOTH BOTTOM BLEND RADIUS ( 0.001 - "&VAL$(Outside_dia-Pitch_dia)&" )",Answer$)
Tbbr=GetValue("TOOTH BOTTOM BLEND RADIUS",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Shrinkage: !
Stat=SetInputFormat("n5="," ")
Stat=SetInputMinMax(0.0,0.1)
Rep_value=0
Stat=SetEqualsValue(Rep_value)
Shrink=GetValue("SHRINKAGE PER INCH",Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Tolerance: !
Stat=SetInputFormat("n5="," ")
Minimum=MAX(1.E-5,1.E-6*Outside_dia)
Stat=SetInputMinMax(Minimum,0.1)
OUTPUT A$ USING "D.8D,8A";Minimum," - 0.1 )"
Rep_value=MAX(Minimum,.0001)
Stat=SetEqualsValue(Rep_value)
Involute_tol=GetValue("INVOLUTE APPROX. TOLERANCE (RANGE: "&A$,Answer$)
Stat=UnSetInputMinMax
IF ExitScript(Destination$) THEN Leave

Stat=PutUserValue(Gear_desc,"Number of teeth:",No_of_teeth)
Stat=PutUserValue(Gear_desc,"Pressure angle:",Pressure_angle)
Stat=PutUserValue(Gear_desc,"Diametral pitch:",Diametral_pitch)
Stat=PutUserValue(Gear_desc,"Module:",Module)
Stat=PutUserValue(Gear_desc,"Pitch diameter:",Pitch_dia)
Stat=PutUserValue(Gear_desc,"Outside diameter:",Outside_dia)
Stat=PutUserValue(Gear_desc,"Root diameter:",Root_dia)
Stat=PutUserValue(Gear_desc,"Circular thickness:",Circ_thickness)
Stat=PutUserValue(Gear_desc,"Chord thickness:",Chord_thickness)

Dedendum=.5*(Pitch_dia-Root_dia)
Stat=PutUserValue(Gear_desc,"Dedendum:",Dedendum)

Addendum=.5*(Outside_dia-Pitch_dia)
Stat=PutUserValue(Gear_desc,"Addendum:",Addendum)

Whole_depth=Addendum+Dedendum
Stat=PutUserValue(Gear_desc,"Whole depth:",Whole_depth)

Base_dia=Pitch_dia*COS(Pressure_angle)
Stat=PutUserValue(Gear_desc,"Base diameter:",Base_dia)

Circular_pitch=PI*Pitch_dia/No_of_teeth
Stat=PutUserValue(Gear_desc,"Circular pitch:",Circular_pitch)

Stat=PutUserValue(Gear_desc,"Radial tooth top:",T_top)
Stat=PutUserValue(Gear_desc,"Tooth top blend radius:",Ttbr)
Stat=PutUserValue(Gear_desc,"Radial tooth bottom:",T_bot)
Stat=PutUserValue(Gear_desc,"Tooth bottom blend radius:",Tbbr)
Stat=PutUserValue(Gear_desc,"Shrinkage:",Shrink)
Stat=PutUserValue(Gear_desc,"Involute tolerance:",Involute_tol)

Read_all_data=1
Stat=PutUserValue(Gear_desc,"Read all data:",Read_all_data)

LOAD "gears.d/calculategear"

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