I gave you the correct answer and then possibly muddied the water by trying to demonstrate how and why the profile functions are used. For on the fly changes, which is what you are doing, do this:
--Set Mach 4 to home all axes in place at run time to take effect immediately.
--The changes will be written to the profile when Mach is shut down.
--If you don't want the changes to be permanent, then change them back before shutting down Mach.
mc.mcAxisSetHomeInPlace(inst, 0, 1)
mc.mcAxisSetHomeInPlace(inst, 1, 1)
mc.mcAxisSetHomeInPlace(inst, 2, 1)
mc.mcAxisSetHomeInPlace(inst, 5, 1)
--Mach 4 API call to home all of the axes (in-place)
--The home offset in the config dialog will automatically be applied!
-- No need to programmatically set the home offset every time as it probably won't change.
mc.mcAxisHomeAll(inst)
--Do we really need to swap back?
mc.mcAxisSetHomeInPlace(inst, 0, 0)
mc.mcAxisSetHomeInPlace(inst, 1, 0)
mc.mcAxisSetHomeInPlace(inst, 2, 0)
mc.mcAxisSetHomeInPlace(inst, 5, 0)
Use the above code.
But to clarify the profile use case: (which you should NOT use in this circumstance).
--change Mach 4 config for all axes to home in place, save & reload the profile
mc.mcCntlConfigStart(inst)
mc.mcProfileWriteInt(inst, "Axis0", "HomeInPlace", 1)
mc.mcProfileWriteInt(inst, "Axis1", "HomeInPlace", 1)
mc.mcProfileWriteInt(inst, "Axis2", "HomeInPlace", 1)
mc.mcProfileWriteInt(inst, "Axis5", "HomeInPlace", 1)
mc.mcProfileFlush(inst)
mc.mcCntlConfigStop(inst)
Either way will work. But going the config state and profile route is a LOT slower.
Also, for brevity, none of these examples are looking at the return codes from the API calls. You REALLY want to do that in your real live script.
One more thing. Usually, for ABS encoders, this would be the setup:
1. Conifgure Mach axis homing tab.
2. Set home in place for each axis with a ABS encoder.
3. Set the offset for each axis in machine coordinates. Find this for each axis prior to configuring the homing by:
a. Put the position DROs in machine coordinates mode.
b. Jog to the desired home position and record the current machine coordinates. This will become your home offset.
4. Set the desire home order. Base 1. Z is usually 1 on a mill. X and Y can usually be homed together set as 2. Maybe not important for ABS encoders. But set it for completeness.
Then the regular homing buttons will just set the home offset with no modifications required. After a RefAll, issuing "G00 G53 X0 Y0" in MDI should carry the axes to the home positions.
You do not need to set the home offsets again unless you change the encoder to table relationship. In most cases, this would only need to be done once and would not need to be update unless the machine was repaired or something. If you are worried that this relationship will change and need to be updated every so often, I would consider that a mechanical problem that needs to be fixed. Loose servo motor coupler, etc..
But if you have to have the optional switch homing, then you can expand on this stuff. If want to use the profile method to set the home offsets, look at the profile and find an Axis# section (where # is 0 to 5) to get the keys you are interested in. (section, key, value)
If you set values wit the mcProfile*() functions, use mcProfileFlush() to make the modifications stick. If you modify axis values with the API functions, use mcProfileSave() to make the modifications stick.
Steve