
! script name: vsolids.d/holdersolid
! var_topic: Make a revolution  of a holder shape

!A
!A NAME:
!A
!A 	Mill Holder Revolution  
!A
!A DESCRIPTION:
!A
!A 	This script will make a surface of revolution out of a mill holder shape. 
!A	This script is to be used to create holder images for tool animation.
!A	Holder images are stored in C:/usr/weber/util/tooldata/holders_in or holders_mm.
!A	Holder images should be created in an otherwise empty file.
!A	Holder images must be synergy surfaces or wireframes, Solid models must be 
!A	converted into synergy surfaces.
!A
!B INSTRUCTIONS:
!B
!B	HOLDER SIZE: 30 40 45 50 60:   Input a standard holder size
!B
!B	OUTER DIAMETER:      Input the outer diameter. Answering 0.0 gives the default
!B			     for the size holder.
!B
!B	START COLLET DIAMETER: Input the collet diameter at the bottom of the holder.
!B                             Answering 0.0 gives the default for the size holder.
!B
!B	END COLLET DIAMETER: Input the collet diameter at the top of the collet.
!B                             Answering 0.0 gives the default for the size holder.
!B
!B	LENGTH FROM END OF TAPER TO TOOL: Input the length from the bottom of the holder 
!B				to the end of the standard taper.
!B                             Answering 0.0 gives the default for the size holder.
!B
!B	LENGTH FROM RIM TO TOOL:  Input the length from the bottom of the holder to 
!B				the bottom of the rim.  
!B                             Answering 0.0 gives the default for the size holder.
!B
!B	STRAIGHT COLLET LENGTH: Input the straight collet length if the collet is tapered
!B				at the bottom.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: holder solid")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Center$[256]
DIM Axis_line$[256]
DIM Odia_var$[256]
DIM Scdia_var$[256]
DIM Ecdia_var$[256]
DIM Length1_var$[256]
DIM Length2_var$[256]
DIM Length3_var$[256]
DIM Name$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Smooth=WsTrue
Style=0

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

Start:!
Stat=SetInputFormat("n0=","")
Stat=SetEqualsValue(40)
Holder_size=GetValue("HOLDER SIZE: 30 40 45 50 60",Answer$)
IF ExitScript(Destination$) THEN Leave


Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius1)
Diameter1=InputRadius("OUTER DIAMETER",WsDiaInput)
IF ExitScript(Destination$) THEN Leave
No_odia_var= LastVariableInput(Odia_var$)
Radius1= 0.5*Diameter1

Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius2)
Diameter2=InputRadius("START COLLET DIAMETER",WsDiaInput)
IF ExitScript(Destination$) THEN Leave
No_scdia_var= LastVariableInput(Scdia_var$)
Radius2= 0.5*Diameter2

Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius3)
Diameter3=InputRadius("END COLLET DIAMETER",WsDiaInput)
IF ExitScript(Destination$) THEN Leave
No_ecdia_var= LastVariableInput(Ecdia_var$)
Radius3= 0.5*Diameter3

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(length1)
Length1=InputDepth("LENGTH FROM END OF TAPER TO TOOL")
No_length1_var= LastVariableInput(Length1_var$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(length2)
Length2=InputDepth("LENGTH FROM RIM TO TOOL")
No_length2_var= LastVariableInput(Length2_var$)
IF ExitScript(Destination$) THEN Leave

IF Diameter2<> Diameter3 THEN
	Stat=SetInputFormat("n4=","")
	Stat=SetDepthEquals(length3)
	Length3=InputDepth("STRAIGHT COLLET LENGTH")
	IF ExitScript(Destination$) THEN Leave
	No_length3_var= LastVariableInput(Length3_var$)
ELSE
	Length3=0
	No_length3_var=1
END IF

Stat= GenerateVarName(WsRevSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TOOL HOLDER: Define")
Stat= SetRecDelLastExec
V00= FreeParameter("Holder Size 30 40 45 50 60",Holder_size)
V01= FreeParameter("Holder Style  0 (CAT or ISO)  1 NMBT ",Style)
IF No_odia_var THEN
        V1= FreeParameter("Outer Diameter",Diameter1)
ELSE
        V1= FreeParameter("Outer Diameter",Odia_var$)
END IF
IF No_scdia_var THEN
        V2= FreeParameter("Start Collet Dia",Diameter2)
ELSE
        V2= FreeParameter("Start Collet Dia",Scdia_var$)
END IF
IF No_ecdia_var THEN
        V3= FreeParameter("End Collet Dia",Diameter3)
ELSE
        V3= FreeParameter("End Collet Dia",Ecdia_var$)
END IF
IF No_length1_var THEN
        V4= FreeParameter("Length Taper to Tool",Length1)
ELSE
        V4= FreeParameter("Length Taper to Tool",Length1_var$)
END IF
IF No_length2_var THEN
        V5= FreeParameter("Length Rim to Tool",Length2)
ELSE
        V5= FreeParameter("Length Rim to Tool",Length2_var$)
END IF
IF No_length3_var THEN
        V6= FreeParameter("Straight Collet Length",Length3)
ELSE
        V6= FreeParameter("Straight Collet Length",Length3_var$)
END IF
V7= FreeParameter("Z Offset",0.0)

Pc= PointXYZ(0,0,V7)
Pt= PtIncrXyz(Pc,0.0,0.0,1.0)
Axis_line= LineTwoPoints(Pc,Pt)
C1= HolderSolid(V00,V01,Axis_line,WsForward,Smooth,V4,V5,V6,V1,V2,V3)
Stat= SurfPlotDensity(C1,1,.6)
Stat= NameEntity(C1,Name$)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("tool holder revolution")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Start

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

