I used a slightly different approach to digitizing an item using "mc.mcCntlProbeFileOpen". This code works for me. I am new to scripting; and, am suprised about how little code this requires. However, it will grow if a user interface is added to obtain parameters. I have just been editing the parameters within the script. I may add a user interface if I were to use this more frequently.
ProbeSurface = coroutine.create(function()
inst=mc.mcGetInstance()
local GridX = 0.1 -- Spacing of X probing
local GridY = 0.1 -- Spacing of Y probing
local ProbeX = 0 -- X Work Coordinates of Probe Start
local ProbeY = 0 -- Y Work Coordinates of Probe Start
local ProbeZ = mc.mcAxisGetPos(inst,mc.Z_AXIS) -- work coordinate starting location
local ProbeXmax = 2 -- Width of Part
local ProbeYmax = 0.2 -- Height of Part
local ProbeZdist = .5 -- Distance to probe Z axis
local ProbeRate = 5.0 -- Inches per Minute
local JogRate = 20 -- Inches per Minute
local File = "C:\\Mach4Hobby\\GcodeFiles\\ProbeValues.csv" -- Path and filename to save the mapped points
mc.mcCntlProbeFileOpen(inst, File, "%.3AXIS_X, %.3AXIS_Y, %.4AXIS_Z \n" ,true) -- Open and format the file to write the XYZ coordinates
wx.wxMessageBox("This will map the surface of a part and save the XYZ coordinates to the file.")
repeat
ProbeX = 0
-- Jog to Y probe Location
mc.mcCntlGcodeExecute(inst,"G90 G01 Y" ..ProbeY.. " F" .. JogRate)
coroutine.yield()
repeat
-- Jog to X probe Location
mc.mcCntlGcodeExecute(inst,"G90 G01 X" ..ProbeX.. " F" .. JogRate)
coroutine.yield()
-- Probe for Z
mc.mcCntlGcodeExecute(inst,"G91 G31.0 Z-" ..ProbeZdist .. " F".. ProbeRate)
coroutine.yield()
mc.mcCntlGcodeExecute(inst,"G90 G01 Z" ..ProbeZ.." F" .. JogRate)
coroutine.yield()
ProbeX = ProbeX + GridX
until (ProbeX > ProbeXmax + 0.001)
ProbeY = ProbeY + GridY
until (ProbeY > ProbeYmax + 0.001)
mc.mcCntlProbeFileClose(inst) --close probe file
mc.mcCntlSetLastError(inst, "Probing Complete")
mc.mcCntlReset(0)
end)
-----------------------------------------------------------
--Coroutine ProbeSurface
-------------------------------------------------------------
if (ProbeSurface ~= nil) and (machState == 0) then --ProbeSurface exist and state == idle
local state = coroutine.status(ProbeSurface)
if state == "suspended" then --ProbeSurface is suspended
coroutine.resume(ProbeSurface)
end
end
-David