// Macros for use the ATC by Hugo Neil if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) { MessageBox.Show("The machine has not yet been homed, HOME before executing!"); exec.Stop(); return; } double Zoriginalpos = exec.GetZmachpos(); double Zmin = -150; //Max.Z depth double FeedrateFast = 400; //Feedrate for probing double FeedrateSlow = 40; //Feedrate for probing double SafeZ = 100; double Retractheight = 30; //The retract height double Retractforsecondmeasurement = 2; double[] ZabsoluteT = new double[30]; double[] ZdisT = new double[30]; double CurrentTool = 0; int Numbertoolsint = 1; int Singletoolsint = 1; ZdisT[1] = 0; AS3.Setfield(ZdisT[1], 196); AS3.Validatefield(196); exec.Wait(100); DialogResult result; result = MessageBox.Show("This Macro will automatically adjust the tool offsets for the ATC for a single or multiple tools. The recomended position of the Zero Length Sensor is in front and left of the tool holder to have a clear movement of the ATC, position the tool on top of the tool lenght sensor and press ok to continue (this macro overwrite the current offset settings) ", "Important!!!" , MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.Cancel) { MessageBox.Show("Correct the positions and execute the macro again"); exec.Stop(); return; } double Numbertools = exec.Question("How many tools are on the ATC?, Enter 1 to adjust a single tool on the holder"); if(Numbertools<=0) { MessageBox.Show("Verify the number of tools (minimum 1, maximum 30)"); exec.Stop(); return; } if(Numbertools==1) { double Singletool = exec.Question("Which tool number do you want to adjust the offset?"); if(Singletool<=0) { MessageBox.Show("Verify the number of the tool you want to change"); exec.Stop(); return; } if(Singletool==1) { MessageBox.Show("You cant adjust the value of the tool 1 (this value its zero)"); exec.Stop(); return; } if(Singletool>=31) { MessageBox.Show("This Macro only works max with 30 tools!"); exec.Stop(); return; } if(Singletool>=2) { Singletoolsint = Convert.ToInt32(Singletool); if(!exec.Ismacrostopped()) { exec.Code("M6T1"); while(exec.IsMoving()){} } exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); while(exec.IsMoving()){} exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} ZabsoluteT[1] = exec.GetZmachpos(); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); //Retract the axis while(exec.IsMoving()){} // MessageBox.Show("Tool 1 height " + ZabsoluteT[1]); if(!exec.Ismacrostopped()) { exec.Code("M6T"+Singletool); while(exec.IsMoving()){} } exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); while(exec.IsMoving()){} exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} ZabsoluteT[Singletoolsint] = exec.GetZmachpos(); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); //Retract the axis while(exec.IsMoving()){} ZdisT[Singletoolsint]=(ZabsoluteT[1]-ZabsoluteT[Singletoolsint])*(-1); AS3.Setfield(ZdisT[Singletoolsint], (195+Singletoolsint)); AS3.Validatefield(195+Singletoolsint); exec.Wait(100); exec.Code("G43 H"+Singletool); exec.Wait(100); } } if(Numbertools>=30) { MessageBox.Show("This Macro only works max with 30 tools!"); exec.Stop(); return; } if(Numbertools>1) { DialogResult result2; result2 = MessageBox.Show("The Macro will adjust the offset for " + Numbertools + " tools (this will not change the zero value). If this is correct pres OK", "Important!!!" , MessageBoxButtons.OKCancel); if (result2 == System.Windows.Forms.DialogResult.Cancel) { MessageBox.Show("Correct the positions and execute the macro again"); exec.Stop(); return; } } if(Numbertools>=2) { CurrentTool=1; if(!exec.Ismacrostopped()) { exec.Code("M6T"+CurrentTool); while(exec.IsMoving()){} } exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); while(exec.IsMoving()){} exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} ZabsoluteT[1] = exec.GetZmachpos(); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); //Retract the axis CurrentTool=CurrentTool+1; Numbertoolsint=Numbertoolsint+1; while(exec.IsMoving()){} // MessageBox.Show("Tool 1 height " + ZabsoluteT[1]); while(CurrentTool<=Numbertools){ if(!exec.Ismacrostopped()) { exec.Code("M6T"+CurrentTool); while(exec.IsMoving()){} } exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); while(exec.IsMoving()){} exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} ZabsoluteT[Numbertoolsint] = exec.GetZmachpos(); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); //Retract the axis while(exec.IsMoving()){} // MessageBox.Show("Tool "+CurrentTool+" height " + ZabsoluteT[Numbertoolsint]); ZdisT[Numbertoolsint]=(ZabsoluteT[1]-ZabsoluteT[Numbertoolsint])*(-1); // MessageBox.Show("Tool offset " + ZdisT[Numbertoolsint]); AS3.Setfield(ZdisT[Numbertoolsint], (195+Numbertoolsint)); AS3.Validatefield(195+Numbertoolsint); CurrentTool = CurrentTool+1; Numbertoolsint=Numbertoolsint+1; exec.Wait(100); exec.Code("G43 H"+CurrentTool); exec.Wait(100); } } if(!exec.Ismacrostopped()) { DialogResult result3; result3 = MessageBox.Show(Numbertools + " Tool(s) offset are calculated. Do you want to save this offsets on the current profile? if you press Cancel the offsets are only applied but not saved.", "Important!!!" , MessageBoxButtons.OKCancel); if (result3 == System.Windows.Forms.DialogResult.Cancel) { exec.Callbutton(168); exec.Wait(200); MessageBox.Show("Settings are only Applied, Returning to Tool #1"); exec.Code("M6T1"); while(exec.IsMoving()){} exec.Stop(); return; } else { exec.Callbutton(168); exec.Callbutton(167); exec.Wait(200); MessageBox.Show("Settings are Applied and Saved in the current Profile, Returning to Tool #1"); exec.Code("M6T1"); while(exec.IsMoving()){} exec.Stop(); return; } } else { exec.StopWithDeccel(); exec.Wait(200); MessageBox.Show("Macro interrupted by user!"); }