if(Currenttool!=0) // No need to drop down tool if current tool number is zero
{
// Move to old tool position on XY plane
exec.Code("G00 G53 X" + ToolX[Currenttool] + " Y" + ToolY[Currenttool]);
while(exec.IsMoving()){}
// Drop current tool
exec.Setoutpin(Dustopenport, Dustopenpin); // Open the Dust with pneumatic valve
exec.Wait(3000); // Wait one 5000msec
exec.Code("G00 G53 Z"+ Ztoolrelease); // Move Z axis down to tool holder position
while(exec.IsMoving()){}
exec.Wait(2000); // Wait one 5000msec
exec.Setoutpin(Rackopenport, Rackopenpin); // Open the Rackin with pneumatic valve
exec.Wait(3000); // Wait one 5000msec
exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
exec.Wait(1000); // Wait one 1000msec
exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
while(exec.IsMoving()){}
}