
! script name: milacron.d/weldgrooves
! topic: create weld groove bodies

!A
!A NAME:
!A
!A 	Make Weld Groove Bodies
!A
!A DESCRIPTION:
!A	
!A	This function creates bodies which are used to make the weld grooves on the
!A	screw flights. Use this function to make the bodies. Use the Trim Weld Groove 
!A	function to modify them. Use Subtract Weld groove Bodies to subtract the
!A	grooves from the main screw body.
!A
!B INSTRUCTIONS:
!B
!B
!B NOTES:
!B
!B

DIM Answer$[256]
DIM Name$[512]
DIM Body$[512]
DIM Destination$[512]
DIM Wclear_var$[256]
DIM Wdepth_var$[256]

OPTION BASE 1

Stat=ChangeLabelStr("ScriptNameStatus","Function: Weld Grooves ")

Start:!
ActivateUndo

Pick_body:!
Body$="Mainscrew"
IF NOT WPKIsEntity(Body$) THEN
    Pkbody= WPKCurrentBody
    IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
	E1=WPKPickEntity("PICK MAIN SCREW BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Pick_body
        Pkbody= WPKParentBody(E1)
    END IF
    Stat= EntityNameCheck(Pkbody,Body$)
END IF
Main_body= WPKParentBody(Body$)


Weld_clearance=NamedVarVal("weld clearance",WsSystemVars,2.0)
Stat=SetEqualsValue(Weld_clearance)
Stat=SetInputFormat("n4=","")

Weld_clearance=GetValue("WELD GROOVE CLEARANCE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_wclear_var= LastVariableInput(WClear_var$)
V1=CreateVariable("weld clearance",WsSystemVars,Weld_clearance)

Weld_depth=NamedVarVal("weld depth",WsSystemVars,2.0)
Stat=SetEqualsValue(Weld_depth)
Stat=SetInputFormat("n4=","")

Weld_depth=GetValue("WELD GROOVE DEPTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_wdepth_var= LastVariableInput(Wdepth_var$)
V1=CreateVariable("weld depth",WsSystemVars,Weld_depth)

Zone_number:!
Active_zone= VariableValue("Active_zone")
IF Active_zone<1 THEN
	Stat=SetInputFormat("n0","")
	Zone_number=GetValue("ZONE NUMBER")
	IF (ExitScript(Destination$)) THEN Leave
END IF



Make_record:!
PlotOff
WPKClearErrorFlag
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("EXTRUSION SCREW: Weld grooves")
Stat= DisplayMessage("PROCESSING WELD GROOVES:")
Workr= CurrentWorkplane
Stat= SetWorkplane
Pt= PointXYZ(0,0,0)
T1=AngleTransform(Pt,90,-90,0)
Stat=SetWorkplane(T1)
Stat= DeleteEntity(Pt)
Screw_group= GrpOfUserProps(20000,21000)
IF No_wclear_var THEN
	V1= FreeParameter("Weld groove clearance",Weld_clearance)
ELSE
	V1= FreeParameter("Weld groove clearance",Wclear_var$)
END IF
IF No_wdepth_var THEN
	V2= FreeParameter("Weld groove depth",Weld_depth)
ELSE
	V2= FreeParameter("Weld groove depth",Wdepth_var$)
END IF
IF Active_zone THEN
	V3= FreeParameter("Zone number",VariableValue("Active_zone"))
ELSE
	V3= FreeParameter("Zone number",Zone_number)
END IF
Bodygroup= WPKWeldGrooves(Body$,Screw_group,V3,V1,V2,WsFalse)
Stat= WPKNameBodyGroup(Bodygroup,Name$)
Stat= WPKSetBodyParent(Bodygroup,1)
Stat= DeleteEntity(Bodygroup)
Stat= DeleteEntity(Screw_group)
Stat=SetWorkplane(Workr)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("weld grooves")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

PlotAll
GOTO Zone_number


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

