
! script name: pkmacros.d/whirler_syn
! solids: simulates the action of a whirler on a body
!A
!A NAME:
!A
!A 	Whirler Simulator
!A
!A DESCRIPTION:
!A
!A
!A
!B INSTRUCTIONS:
!B
!B
!B NOTES:
!B
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: Whirler Simulator ")

DIM Destination$[256]
DIM Answer$[256]

ActivateUndo
IF ARGC<2 THEN
        Use_sheet=1
ELSE
        Use_sheet= VAL(ARGV(1))
END IF


Stat= GLPlotOn
Start:!

E1=WPKPickEntity("PICK WHIRLER HEAD")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Body_loop
Pkbody= WPKParentBody(E1)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0)
STilt_angle=GetValue("START WHIRLER HEAD TILT",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Stilt_angle)
ETilt_angle=GetValue("END WHIRLER HEAD TILT",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Depth1)
Depth1=GetValue("START CUTTING DEPTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Depth1)
Depth2=GetValue("END CUTTING DEPTH",Answer$)
IF ExitScript(Destination$) THEN Leave


Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("CYLINDER RADIUS")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(3.0)
Pitch=GetValue("PITCH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(360)
Angle=GetValue("ANGULAR EXTENT",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(5)
Angle_incr=GetValue("ANGULAR INCREMENT",Answer$)
IF ExitScript(Destination$) THEN Leave

Number= INT(Angle/Angle_incr + 0.5)
Ang1= Angle/Number

Length1= Angle/360.0*Pitch

Ps= PointXYZ(-2,0,0)
Pe= PointXYZ(length1+4,0,0)
Axis_line= LineTwoPoints(Ps,Pe)
WPKClearErrorFlag

IF Use_sheet THEN
	P1= PointXYZ(Length1/2,0,0)
	P2= PointXYZ(1,0,0)
	P3= PointXYZ(0,1,0)
	PkCylinder=WPKRectangle(P1,P2,P3,length1+4,2*Radius)
	Stat= DeleteEntity(P1)
	Stat= DeleteEntity(P2)
	Stat= DeleteEntity(P3)
ELSE
	PkCylinder=WPKCylinder(Ps,Pe,Radius,Length1+4)
END IF
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
PlotOff
Pc= PointXYZ(0,0,0)
T1=AngleTransform(Pc,0,0,0,WsWorkplaneVals)
PkHead=WPKTransCopyBody(Pkbody,T1)
Stat= DeleteEntity(T1)
Stat= DeleteEntity(Pc)
Stat= HideEntity(PkHead)
Stat= HideEntity(PkBody)
PlotOn
Stat= DeleteEntity(Axis_line)
Ps= PointXYZ(0,0,0)
Pe= PointXYZ(length1,0,0)
FOR I= 0 TO Number
	T= I/Number
	Ang= T*Angle
	Nrevs= Ang/360
	Xmove= Nrevs*Pitch
	Ymove= 0.0
	Zmove= -(Depth1+ T*(Depth2-Depth1))
	Tilt_angle= Stilt_angle+ T*(Etilt_angle-Stilt_angle)
	Pm=PointXYZ(Xmove,Ymove,Zmove)
	Z= Depth1+ T*(Depth2-Depth1)
	T1=AngleTransform(Pm,0,0,Tilt_angle,WsWorkplaneVals)
	Pkheadcopy=WPKTransCopyBody(PkHead,T1)
	Stat= UnHideEntity(Pkheadcopy)
	Stat= WPKUpdateBody(Pkheadcopy)
	Stat= DeleteEntity(Pm)
	T2=AngleTransform(Ps,-Ang1,0,0,WsWorkplaneVals)
	Stat=WPKTransformBody(PkCylinder,T2)
	G1= WPKTrimBody(PkCylinder,Pkheadcopy,WsOutside)
	Stat= WPKDeleteBody(PkHeadCopy)
	Stat= DeleteEntity(T1)
	Stat= DeleteEntity(T2)
	Stat= DeleteEntity(G1)
NEXT I
Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)
Stat= WPKDeleteBody(PkHead)
Stat= UnHideEntity(PkBody)
PlotOn
PlotAll

ActivateUndo
Stat= AdvanceUndoNumber("whirler syn")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Start

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