
! script name: vpksolids.d/vpktwinextruder
! solids: twin extruder screw shape
!A
!A NAME:
!A
!A 	Variable Pitch Twin Extruder Screw:   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script creates a simple variable lead screw.
!A
!B INSTRUCTIONS:
!B		NUMBER OF FLIGHTS: Number of flights
!B
!B		Left or Right HAND SCREW: Is the screw left or right hand.
!B
!B
!B NOTES:
!B
!B
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: var lead twin extruder ")

OPTION BASE 1
DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point$[256]
DIM A$[512]
DIM B$[512]
DIM C$[512]
DIM Name$[512]
DIM Prop_dir$[512]
DIM Prop_class$[512]
DIM Class_dir$[512]
DIM Class_name$[512]
DIM Filename$[512]
DIM Screw_pname$[512]
DIM Namelist$[32000]
DIM D_label$[512]
DIM Choice$[512]
DIM Current_dir$[512]
DIM Ques$[512]


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


ActivateUndo
Units= CurrentUnits

Filename$= FileNameString("/usr/weber/database/properties/ExtrusionScrews.d","TwinExtruder")
Start:!
Stat= GLPlotOn

New_zone:!
Stat=SetInputFormat("n0","")
Zone_number= GetValue("ZONE NUMBER")
IF (ExitScript(Destination$)) THEN Leave


Zone_name$= "Zone_"&VAL$(Zone_number)
Zone_group= FindNamedEntity(Zone_name$)
IF NOT ValidGeometry(Zone_group) THEN
	Zone_group= CreateGroup(Zone_name$,WsGrpOfProperties)
	Stat=NameEntity(Zone_group,Zone_name$)
	New_zone=1
ELSE
	New_zone=0
END IF

New_section:!
Section_number= GroupCount(Zone_group)+1
IF Section_number=1 THEN
	IF Zone_number>1 THEN
		Last_zone_group= FindNamedEntity("Zone_"&VAL$(Zone_number-1))
		IF ValidGeometry(Last_zone_group) THEN
		    E1= GroupElement(Last_zone_group,GroupCount(Last_zone_group))
		    Screw_prop= CopyEntity(E1)
		    Screw_pname$= "Zone_"&VAL$(Zone_number)&"_Section_"&VAL$(Section_number)
		    Stat= PutUserString(Screw_prop,"Name:",Screw_pname$)
		    Stat=NameEntity(Screw_prop,Screw_pname$)
		ELSE
		  Id_number=GetExtUserValue(Filename$,"Class id number:")
		  Name$= ExtUserDataStr(Filename$,"Name:")
		  Screw_prop= ReadUserData(Id_number,Name$,Filename$)
		  Screw_pname$="Zone_"&VAL$(Zone_number)&"_Section_"&VAL$(Section_number)
		  Stat= PutUserString(Screw_prop,"Name:",Screw_pname$)
		  Stat=NameEntity(Screw_prop,Screw_pname$)
		END IF
	ELSE
		Id_number=GetExtUserValue(Filename$,"Class id number:")
		Name$= ExtUserDataStr(Filename$,"Name:")
		Screw_prop= ReadUserData(Id_number,Name$,Filename$)
		Screw_pname$= "Zone_"&VAL$(Zone_number)&"_Section_"&VAL$(Section_number)
		Stat= PutUserString(Screw_prop,"Name:",Screw_pname$)
		Stat=NameEntity(Screw_prop,Screw_pname$)
	END IF
ELSE
	E1= GroupElement(Zone_group,(Section_number-1))
	Screw_prop= CopyEntity(E1)
	Screw_pname$= "Zone_"&VAL$(Zone_number)&"_Section_"&VAL$(Section_number)
	Stat= PutUserString(Screw_prop,"Name:",Screw_pname$)
	Stat=NameEntity(Screw_prop,Screw_pname$)
END IF

List_fields:!
Namelist$= DataFieldListStr(Screw_prop,":",",",WsNoOrder,WsTrue)

D_label$="ZONE "&VAL$(Zone_number)&" SECTION "&VAL$(Section_number)
Choice$="PARAMETER SELECTED"
Stat=GeneralListBox(D_label$,Choice$,Namelist$)

Data_field:stat= SetInputFormat("a99","",WsFalse)
stat= GetValue("SELECT SCREW PARAMETER: Undo , New section, End zone ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT LEN(Answer$) THEN Data_field
IF POS(Answer$,"Undo") THEN Answer$="U"
LowerSelectBox
SELECT Answer$
CASE "CANCEL"
	Stat= DeleteEntity(Screw_prop)
	GOTO New_section
CASE "U","u","UNDO","undo"
	Element_num=GroupCount(Zone_group)
	E1=GroupElement(Zone_group,Element_num)
	Stat=RemoveFromGrp(Zone_group,Element_num)
	Stat= DeleteEntity(E1)
	GOTO New_section
CASE "New","N","n","new"
	Stat=AddToGroup(Zone_group,Screw_prop)
	GOTO New_section
CASE "End","E","e","end"
	Stat=AddToGroup(Zone_group,Screw_prop)
	IF New_zone THEN
		GOTO Make_record
	ELSE
		LOAD "vcontrol.d/lrgexecall"
	END IF
END SELECT
IF POS(Answer$,"=") THEN
	A$= DataFieldStr(Answer$,"=",1)
	B$= DataFieldStr(Answer$,"=",2)
	B$= TRIM$(B$)
ELSE
	A$= Answer$
	B$=""
END IF
GOTO New_value

New_value:!
IF LEN(B$) THEN
	Stat= AddBackSlashChars(B$,C$)
	stat= SetInputFormat("a99=","",WsFalse)
	Stat= SetEqualsValue(0,C$)
	Stat=SetEditString(C$)
ELSE
	stat= SetInputFormat("a99","",WsFalse)
END IF
stat= GetValue(A$&" = ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Answer$= TRIM$(Answer$)
IF NOT LEN(Answer$) THEN New_value
Stat= BackSlashChars(Answer$,B$)
Stat= PutUserString(Screw_prop,A$&":",B$)

GOTO List_fields


Make_record:!
Screw_pname$= UserDataStr(Screw_prop,"Name:")
Stat=NameEntity(Screw_prop,Screw_pname$)
PlotAll
WPKClearErrorFlag
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("EXTRUSION SCREW: Twin")
Stat= DisplayMessage("Current Section #"&VAL$(VariableValue("Curr_section")+1))
Workr= CurrentWorkplane
Stat= SetWorkplane
Ps= PointXYZ(VariableValue("Curr_Start_Length"),0,0)
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
V1= FreeParameter("Xstart",0)
V2= FreeParameter("Starting angle",0)
Bodygroup= WPKTwinScrewZone(Zone_name$)
Stat= WPKNameBodyGroup(Bodygroup,Name$)
Stat= WPKSetBodyParent(Bodygroup,1)
Stat= DeleteEntity(Bodygroup)
Stat= SetWorkplane
Pe= PtIncrXyz(Ps,V5,0,0)
Stat= NameEntity(Pe,Pname$)
Stat=SetWorkplane(Workr)
Stat= DeleteEntityList(Ps)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("twin extruder screw")
Stat= AddItemToUndo(WsUBCreateMode,Pname$)
Stat= AddItemToUndo(WsUBCreateMode,Screw_pname$)
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




