// Macros for use the ATC by Hugo Neil string ifai=AS3.Getfield(2724);double move=Convert.ToDouble(ifai);if(move==55){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; } while(exec.IsMoving()){} // Wait while there is motion double Resetoffset = 0; double Zoriginalpos = exec.GetZmachpos(); double Zmin = -100; //Max.Z depth double FeedrateFast = 300; //Feedrate for probing double FeedrateSlow = 40; //Feedrate for probing double SafeZ = 100; double Retractheight = 30; //The retract height double Retractforsecondmeasurement = 2; double ZabsoluteT1 = 0; double ZabsoluteT2 = 0; double ZabsoluteT3 = 0; double ZabsoluteT4 = 0; double ZabsoluteT5 = 0; double ZabsoluteT6 = 0; double ZabsoluteT7 = 0; double ZabsoluteT8 = 0; double ZabsoluteT9 = 0; double ZabsoluteT10 = 0; double ZdisT1 = 0; double ZdisT2 = 0; double ZdisT3 = 0; double ZdisT4 = 0; double ZdisT5 = 0; double ZdisT6 = 0; double ZdisT7 = 0; double ZdisT8 = 0; double ZdisT9 = 0; double ZdisT10 = 0; 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 10)"); 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>=11) { MessageBox.Show("This Macro only works max with 10 tools!"); exec.Stop(); return; } if(Singletool==2) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T2"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT2 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT2=(ZabsoluteT1-ZabsoluteT2)*(-1); AS3.Setfield(ZdisT2, 197); AS3.Validatefield(197); exec.Code("G43 H2"); } if(Singletool==3) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T3"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT3 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT3=(ZabsoluteT1-ZabsoluteT3)*(-1); AS3.Setfield(ZdisT3, 198); AS3.Validatefield(198); exec.Code("G43 H3"); } if(Singletool==4) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T4"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT4 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT4=(ZabsoluteT1-ZabsoluteT4)*(-1); AS3.Setfield(ZdisT4, 199); AS3.Validatefield(199); exec.Code("G43 H4"); } if(Singletool==5) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T5"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT5 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT5=(ZabsoluteT1-ZabsoluteT5)*(-1); AS3.Setfield(ZdisT5, 200); AS3.Validatefield(200); exec.Code("G43 H5"); } if(Singletool==6) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T6"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT6 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT6=(ZabsoluteT1-ZabsoluteT6)*(-1); AS3.Setfield(ZdisT6, 201); AS3.Validatefield(201); exec.Code("G43 H6"); } if(Singletool==7) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T7"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT7 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT7=(ZabsoluteT1-ZabsoluteT7)*(-1); AS3.Setfield(ZdisT7, 202); AS3.Validatefield(202); exec.Code("G43 H7"); } if(Singletool==8) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T8"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT8 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT8=(ZabsoluteT1-ZabsoluteT8)*(-1); AS3.Setfield(ZdisT8, 203); AS3.Validatefield(203); exec.Code("G43 H8"); } if(Singletool==9) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T9"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT9 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT9=(ZabsoluteT1-ZabsoluteT9)*(-1); AS3.Setfield(ZdisT9, 204); AS3.Validatefield(204); exec.Code("G43 H9"); } if(Singletool==10) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T10"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT10 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT10=(ZabsoluteT1-ZabsoluteT10)*(-1); AS3.Setfield(ZdisT10, 205); AS3.Validatefield(205); exec.Code("G43 H10"); } } if(Numbertools>=11) { MessageBox.Show("This Macro only works max with 10 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) { exec.Code("M6T1"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT1 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} exec.Code("M6T2"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT2 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT2=(ZabsoluteT1-ZabsoluteT2)*(-1); AS3.Setfield(ZdisT2, 197); AS3.Validatefield(197); exec.Code("G43 H2"); } if(Numbertools>=3) { exec.Code("M6T3"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT3 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT3=(ZabsoluteT1-ZabsoluteT3)*(-1); AS3.Setfield(ZdisT3, 198); AS3.Validatefield(198); exec.Code("G43 H3"); } if(Numbertools>=4) { exec.Code("M6T4"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT4 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT4=(ZabsoluteT1-ZabsoluteT4)*(-1); AS3.Setfield(ZdisT4, 199); AS3.Validatefield(199); exec.Code("G43 H4"); } if(Numbertools>=5) { exec.Code("M6T5"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT5 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT5=(ZabsoluteT1-ZabsoluteT5)*(-1); AS3.Setfield(ZdisT5, 200); AS3.Validatefield(200); exec.Code("G43 H5"); } if(Numbertools>=6) { exec.Code("M6T6"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT6 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT6=(ZabsoluteT1-ZabsoluteT6)*(-1); AS3.Setfield(ZdisT6, 201); AS3.Validatefield(201); exec.Code("G43 H6"); } if(Numbertools>=7) { exec.Code("M6T7"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT7 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT7=(ZabsoluteT1-ZabsoluteT7)*(-1); AS3.Setfield(ZdisT7, 202); AS3.Validatefield(202); exec.Code("G43 H7"); } if(Numbertools>=8) { exec.Code("M6T8"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT8 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT8=(ZabsoluteT1-ZabsoluteT8)*(-1); AS3.Setfield(ZdisT8, 203); AS3.Validatefield(203); exec.Code("G43 H8"); } if(Numbertools>=9) { exec.Code("M6T9"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT9 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT9=(ZabsoluteT1-ZabsoluteT9)*(-1); AS3.Setfield(ZdisT9, 204); AS3.Validatefield(204); exec.Code("G43 H9"); } if(Numbertools>=10) { exec.Code("M6T10"); exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first while(exec.IsMoving()){} exec.Wait(200); exec.Code("G91 G0 Z" + Retractforsecondmeasurement); while(exec.IsMoving()){} exec.Code("G90"); exec.Wait(200); exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading while(exec.IsMoving()){} exec.Wait(200); ZabsoluteT10 = exec.GetZmachpos(); exec.Code("G0 G53 Z" + Zoriginalpos); //Retract the axis while(exec.IsMoving()){} ZdisT10=(ZabsoluteT1-ZabsoluteT10)*(-1); AS3.Setfield(ZdisT10, 205); AS3.Validatefield(205); exec.Code("G43 H10"); } if(!exec.Ismacrostopped()) { exec.Wait(200); 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"); exec.Stop(); return; } else { exec.Callbutton(168); exec.Callbutton(167); exec.Wait(200); MessageBox.Show("Settings are Applied and Saved in the current Profile"); exec.Stop(); return; } } else { exec.StopWithDeccel(); exec.Wait(200); MessageBox.Show("Macro interrupted by user!"); } }