
! script name: milacron.d/readzone
! topic: read zone file and create packets


!A
!A NAME:
!A
!A 	Read Zone File
!A
!A DESCRIPTION:
!A
!A 	This script allows a Zone file to be read.
!A 	The data is converted to Synergy data packets which 
!A 	are then used to create a solid model.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT FILE: A File selection box will appear at this
!B 		time to allow the filename/location to be specified.
!B
!B NOTES:
!B
!B				STRAIGHT FLIGHT
!B~ image location - images/StraightFlight.jpg
!B
!B	The Zone Files are all in metric. Make sure that you are working
!B	in metric coordinates. To do this select File->New and select
!B	metric_ansi or metric_iso from the drop down menu.
!B
!B	All flight shapes are calculated from the flight width at the pitch
!B	diameter and the flank angle using the depths at the pitch diameter
!B	and the depth at the root diameter. If a compound flank angle
!B	is to be used it must be specified in the section data in the zone file.
!B	All flank angles are measured relative to the axis line of the screw.
!B	The Flight Width at the Pitch Diameter is measured along the axis line
!B	of the screw.
!B
!B	Chamfers are specified by the chamfer depth and the chamfer angle.
!B	The chamfer depth is measured relative to the outer diameter.
!B	The chamfer angle is measured relative to the axis line of the screw.
!B
!B				TAPERED FLIGHT
!B~ image location - images/TaperedFlight.jpg
!B
!B	For a tapered flight the flight width at the pitch diameter is measured
!B	along the axis of the screw. This distance is measured from where a line
!B	perpendicular to the axis intersects the pitch diameter at the leading and
!B	trailing edges of the flight. From this point the flight shape is calculated
!B	by using the flank angles measured from the points on the pitch dismater.
!B
!B

DIM Answer$[256],Destination$[256],Dir1$[256]
DIM A$[3000],B$[80],File$[256]
DIM Name$[512]
DIM Prop_dir$[512]
DIM Screw_dir$[512]
DIM Screw_name$[512]
DIM Screw_file$[512]
DIM Prop_file$[512]
DIM Ques$[512]
DIM Mask$[512]
DIM D_label$[512]
DIM F_label$[512]
DIM Sub_label$[512]
DIM Choice$[512]
DIM Dir$[512]

OPTION BASE 1

Conical_flanks=NamedVarVal("Screw Conical Flank Angles",WsSystemVars,0.0)
V2=CreateVariable("Screw Conical Flank Angles",WsSystemVars,Conical_flanks)
Stat=ChangeLabelStr("ScriptNameStatus","Function: Read Zone File ")
Stat= NamedVarStr("Current_screw_name",WsVariationVars,"",Screw_name$)
Stat= NamedVarStr("Current_screw_file",WsVariationVars,"",Screw_file$)
Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO OPEN"
Mask$= "Zone Files (*.wbr)|*.wbr|"
Mask$= Mask$&"All Files (*.*)|*.*||"

GLPlotOff
Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$,"Synergy")
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT EXISTING ZONE FILE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox

File$=Answer$
Answer$=""
StdWorkplane

Stat=ReadZoneFile(File$,Answer$)
IF LEN(Answer$)<1 THEN Leave
Screw_file$=File$

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

ActivateUndo
Units= CurrentUnits

Stat= GLPlotOn

Prop_dir$="/usr/weber/database/properties/ExtrusionScrews.d/"

Start:!
DeActivateUndo
Screw_dir$=Prop_dir$&Answer$
Screw_name$= PathNameFile(File$)


Screw_group= FindNamedEntity(Screw_name$)
IF ValidGeometry(Screw_group) THEN 
	 Stat= DeleteGroup(Screw_group,WsTrue)
END IF

Group= GrpOfUserProps(20000,21000)
IF ValidGeometry(Group) THEN
	 Stat= DeleteAllObjects
	 Stat= DelAllStrategyVars(WsFalse)
	 Stat= DeleteGroup(Group,WsTrue)
END IF
	

Screw_group= PDirSearchValGrp(Screw_dir$,"Class id number:",0,0,20000,20020)
Stat= AutoNameGroup(Screw_group,Screw_name$)
IF NOT ValidGeometry(Screw_group) THEN Leave
V1=CreateVariable("Current_screw_name",WsVariationVars,Screw_name$)
V2=CreateVariable("Current_screw_file",WsVariationVars,Screw_file$)

Make_record:!
PlotOff
WPKClearErrorFlag
!  Stat= GenerateVarName(WsGroupEnt,Name$)
Name$="MainScrew"
RecordFunctionOn
Stat= RecordDescr("EXTRUSION SCREW: Twin extruder")
Stat=DisplayMessage(JoinStrings("PROCESSING:",VariableString("Current_screw_name")))
Stat=PrintToVarRecord("WPKEndSession")
Prop_grp= GrpOfUserProps(20000,21000)
Workr= CurrentWorkplane
Stat= SetWorkplane
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
V1= FreeParameter("Make opposite hand",0)
V2= FreeParameter("Active zone",0)
V3= FreeParameter("Conical flank angles",Conical_flanks)
Bodygroup= WPKTwinScrewZone(Prop_grp,V1,V3,V2)
Stat= WPKNameBodyGroup(Bodygroup,Name$)
Stat= WPKSetBodyParent(Bodygroup,1)
Stat= DeleteEntity(Bodygroup)
Stat=DeleteEntity(Prop_grp)
V4=CreateVariable("Active_zone",WsVariationVars,VariableValue(V2))
V5=CreateVariable("Conical_flanks",WsVariationVars,VariableValue(V3))
Stat=SetWorkplane(Workr)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("twin extruder screw")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
! WPKErrorCheck

ResizeAll


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

