[VarSet,initialyDisabled,0]

[Title,"              ZSpin Animation             "]

[pd][pd][fontSetSizeSmall][sectionBegin," How to use this ZScript ",0,"Click for an explanation of this ZScript."]
[pd][fontSetSizeMedium]
This ZScript takes a 3D object, in Rotate Mode, and rotates it about the Z axis by a specified number of frames.

To begin, select any 3D object in the [buttonFind,tool:,"Tool palette"] and draw it on the canvas. Before doing anything else, enter [buttonFind,transform:rotate,"Rotate mode"]. Use the Canvas Gyro (the helper which appears when in Rotate mode) to orient the object; this script simulates rotating it as if grabbed by the blue ring.

You can import a 3D model by selecting the [buttonFind,tool:polymesh3d,"Poly Mesh tool"] and pressing the Import button in the [buttonFind,tool:inventory,"Inventory sub-palette"] (Import is available only when the Poly Mesh tool is selected).

For more help on using the buttons and sliders, click the [buttonFind,1,"Help"] buttons.
[sectionEnd][fontSetSizeSmall][penMove,12]Press 'Esc' to abort at any time.[fontSetSizeMedium]
[pd]
[PageSetWidth,[TextCalcWidth,"   Z Rotation steps count          "+8]]

[fontSetSizeSmall][sectionBegin,"?",0,"Help",
[Note,"Use this slider to set the number of steps.",1,-1][routineCall,ExitNote][iUnpress,0]][sectionEnd][fontSetSizeMedium][penMove,3]

[ISlider,"Z Rotation steps count           ",10		,1	,1		,360
,"Number of Steps",,initialyDisabled]

[pd][fontSetSizeSmall][sectionBegin,"?",0,"Help",
[Note,"Use this slider to set the starting angle.",1,-1][routineCall,ExitNote]
[Note,"Use this button to set the current Z angle of the object as the starting angle.",2,-1][routineCall,ExitNote][iUnpress,0]][sectionEnd][fontSetSizeMedium][penMove,3]

[ISlider,"Initial Z Orientation            ",-180	,1	,-180		,180
,"Starting angle",,initialyDisabled][iButton,Pick,"Click to pick the current Z orientation",
[if,([IGet,Transform:Rotate]>0)&&([IGet,Transform:Edit]==0),
		[iSet,-1,[iGet,transform:info:zcomponent]]
	, // else
	[routineCall,ModeError]
	] // end if
] // end iButton
[pd][fontSetSizeSmall][sectionBegin,"?",0,"Help",
[Note,"Use this slider to set the final angle.",1,-1][routineCall,ExitNote]
[Note,"Use this button to set the current Z angle of the object as the final angle.",2,-1][routineCall,ExitNote][iUnpress,0]][sectionEnd][fontSetSizeMedium][penMove,3]

[ISlider,"Final   Z Orientation            ", 180	,1	,-180		,180
,"Final angle",,initialyDisabled][iButton,Pick,"Click to pick the current Z orientation",
	[if,([IGet,Transform:Rotate]>0)&&([IGet,Transform:Edit]==0),
		[iSet,-1,[iGet,transform:info:zcomponent]]
	, // else
	[routineCall,ModeError]
	] // end if
] // end iButton
[pd]
[fontSetSizeSmall][sectionBegin,"?",0,"Help",
[Note,"Use this button to see the rotation without saving to disk.",1,-1][routineCall,ExitNote][iUnpress,0]][sectionEnd][fontSetSizeMedium][penMove,3]

[IButton,"  Preview without saving  ","Preview",
[VarSet,doSave,0][RoutineCall,DoIt]]
[pd]
[fontSetSizeSmall][sectionBegin,"?",0,"Help",
[Note,"Use this button to see the rotation and save all steps to disk.",1,-1][routineCall,ExitNote][iUnpress,0]][sectionEnd][fontSetSizeMedium][penMove,3]
[IButton,"  Execute and export images  ","Execute",
[VarSet,doSave,1][RoutineCall,DoIt]]


 	[RoutineDef,DoIt,
 		[If,([IGet,Transform:Rotate]>0)&&([IGet,Transform:Edit]==0),
 		[If,doSave,
			[IPress,document:exportimage]
			[VarSet,name,[FileNameGetLastTyped]]
			//[If,[VarLength,name]<1,[MessageOK,"Action canceled"][Exit]]
		] // end doSave
		, // else proper mode
		[routineCall,ModeError]
 		]  // end if proper mode 

		[VarSet,RepeatCount,ZScript:ZRotationstepscount]
		// first we caculate the delta values
		[VarSet,Angle,[IGet,ZScript:InitialZOrientation]]
		[VarSet,DeltaAngle,[IGet,ZScript:FinalZOrientation]]
		[VarSet,DeltaAngle,(DeltaAngle-Angle)/RepeatCount]
 		// now we do the loop
		//[IPress,Transform:Rotate]
  		[Loop,RepeatCount ,
			[ISet,Transform:zcomponent,angle]
			[If,doSave==1, [FileNameSetNext, #name ] [IPress,document:exportimage]
[VarSet,#name,[FileNameAdvance,#name,2]] ]
			[VarAdd,Angle,deltaAngle]
		]
 	]
[routineDef,ModeError,
	[Note,"\C880000Error: \Cc0c0c0You must be working with a 3D object in Rotate Mode to run this script.",transform:rotate,-1][routineCall,ExitNote]
] // end ModeError routine

[routineDef,ExitNote,
	[Note,"\n\n\C909090(Press Spacebar)\Cc0c0c0"]
]
