Hello Guest it is May 07, 2021, 09:14:55 PM

Author Topic: mcMasterModule question  (Read 1769 times)

0 Members and 1 Guest are viewing this topic.

mcMasterModule question
« on: June 28, 2018, 03:07:19 PM »
does the following even work? I added the rc variables to find out where the problem was. mc.mcRegGetHandle returns a -27 which causes mc.mcRegSetValueString to return -27.
#define MERROR_REG_NOT_FOUND        -27

function Master.LoadRegister(ini, name)
   local val, rc = mc.mcProfileGetString(inst , tostring(ini), name, "0.000")
   local hreg, rc = mc.mcRegGetHandle(inst, string.format("iRegs0/%s", name))
   rc = mc.mcRegSetValueString(hreg, val)
   return tonumber(val)

I've been trying to gain access to the scr.* properties. in particular some DRO's I've created for use in the m6() macro.
I added the following to my m6 startup.

if (package.loaded.scr == nil) then
   scr = require "screenipc"

scr.GetProperty("droSafeZ", "Value") always returns "" even though I've set it earlier to a value of 0.75 using scr.SetProperty("droSafeZ", "Value", tostring(num))

I have two functions.. I've modified mcMasterModule.lua's LoadRegister function so it returns the numeric value of the register.

function LoadAll()
   SafeZ = mcp.LoadRegister(N_, "SafeZ", "0.00")
        scr.SetProperty("droSafeZ", "Value", tostring(SafeZ))

function SaveAll()
    val = scr.GetProperty("droSafeZ", "Value")
    mcp.SaveRegister(N_, "SafeZ", val)

if (mc.mcInEditor() == 1) then
Re: mcMasterModule question
« Reply #1 on: June 28, 2018, 03:37:50 PM »
btw Master.LoadRegister is part of the mcMasterModule.lua file which is supposed to be an example.
Re: mcMasterModule question
« Reply #2 on: June 29, 2018, 12:44:04 PM »
I'm not the expert on Lua or Mach4 so take this for what you paid for it.

Not sure about the new versions (using 3741) but the scr variable was not available to macros.  You had to set a register with a value and then retrieve the register value.  I seem to recall a post about it being available in the newer versions though.  While you can load a variable 'scr' from a macro I don't believe you get connected to Mach4's scr.

   SafeZ = mcp.LoadRegister(N_, "SafeZ", "0.00")

I assume N_ was set somewhere from N_=mc.mcGetInstance()
assume typo mcp

mc.mcLoadRegister name is of the form 'iRegs0/SafeZ' or 'gRegs0/SafeZ' depending on where you defined the register.

I think should be    SafeZ = mc.mcLoadRegister(N_, "gRegs0/SafeZ", "0.00")



Re: mcMasterModule question
« Reply #3 on: June 29, 2018, 12:50:58 PM »
found my old thread where smurph says it is a vailable but doesn't say what versions

Re: mcMasterModule question
« Reply #4 on: June 29, 2018, 03:02:00 PM »
mcp is a local version of the mcMasterModule which I load as a require.
N_ is a "section name" which is loaded from the ini file. and of course "SafeZ" is the key and 0.00 is the default.
What this is supposed todo is read a value from the ini file and then set a register with that value in the iRegs0 section
the iRegs0 is in the LoadRegister function from mcMasterModule.lua which is included with Mach4.

My issue's are that scr.GetProperty() doesn't appear to work from a macro even when I have the required module loaded via a require.
and that mc.mGetRegister() doesn't work as per the example file. Now this problem I had a answer for before and forgot about it when I asked this question before.
Registers can only be created from a plugin. It would be much handier if we could mc.mcSetRegister() and create registers from a plugin. But then I guess that's why they
have the pound variables. So basically if I want this to work, I need to create a plugin which creates the appropriate registers and then work from there..

this is in my m6() macro.

  local ToolChangePosX = mcp.GetRegister("ToolChangePosX", 1)
                                  --scr.GetProperty("droToolChangePosX", "Value"))
Since scr.GetProperty() doesn't work, I changed to a Register which doesn't work either.  it looks like I will need to use a ini value and work from there.

Re: mcMasterModule question
« Reply #5 on: June 29, 2018, 04:01:15 PM »
you don't need to create a mcp variable as mc is defined and available at load to macros as well as buttons etc.  If you were to add the line wx.wxMessageBox(tostring(mc)) at the beginning of your m6 macro you will see that it is defined as a table, the one created at Mach4 load.  I don't think the mcp table that is returned links to your running version of Mach4 but rather creates another lua chunk.

You can access the the register values by requesting a handle to it an then requesting the value using the mc variable and the core API's:

hReg, rc = mc.mcRegGetHandle(mInst, 'gRegs0/SafeZ')

mVal, rc = mcRegGetValue(hReg)

Assuming you have created a gReg0 value named SafeZ through Configure->Plugins->Regfile

I can't help with with the scr problem since I get the same result as you do with the version I listed.  maybe there is a development version that allows direct access to the scr variable loaded at screenload.  My workaround shown in the link I provided does work but it would be better if someone (SMURPH) would respond on this one.


Re: mcMasterModule question
« Reply #6 on: June 29, 2018, 04:15:46 PM »
if(package.loaded.Master == nil) then     
    mcp = require "mcMasterModule"

mcp.* is how you access the functions within that module.
Re: mcMasterModule question
« Reply #7 on: June 29, 2018, 04:18:19 PM »
If my understanding of what I'm looking at is correct, we are looking at a "class" of functions which are then accessed through a pointer "mcp"
Re: mcMasterModule question
« Reply #8 on: June 29, 2018, 04:24:27 PM »
Your understanding is correct, but, try this:

wx.wxMessageBox(tostring(mcp)..' - '..tostring(mc))

Are the tables returned the same address?  If not then mcp cannot access the values in Mach4.

Re: mcMasterModule question
« Reply #9 on: June 29, 2018, 04:33:57 PM »
they are differant but I expected that. mc.* are internal mach4 functions. mcp.* are a lua script with functions.