Hello Guest it is March 28, 2024, 05:32:09 PM

Author Topic: Calling an "Action" from a lua script  (Read 2034 times)

0 Members and 1 Guest are viewing this topic.

Calling an "Action" from a lua script
« on: January 28, 2016, 10:21:46 PM »
Greetings.

I have built an external pendant that removes a lot of the need for clicking on screen buttons. Using the lua scripts and the resources, almost everything is currently working, including multiple handwheels, start/stop/feedhold, M01, jogging, overrides, etc.

However, I do have an issue that I haven't been able to find the solution for. I've done a ton of searches, but haven't come up with the answer yet.

In the standard screens, the jogging page has a button the increments the jogging step through the steps defined in the configuration. This is triggered via the "Left Up Action" event on the button, and calls the internal action "Cycle Jog Increment". Within these actions, there are other useful actions, (sticking with the jog motif), "Jog Inc. 1" ... Etc. This allows you to directly set the increment to the one selected in the configuration file. (Or as another example, the enable button using the "Left Down Action" and "Left Up Action" to triggering the "Enable On/Enable Off".)

Looking over the documentation, there doesn't seem to be a mc function that allows you to trigger these actions from lua, and there is not an equivalent function to directly trigger these events.

On some older code, they mentioned deprecated ways of using the scr. functions to trigger button presses and such. Not only are they not the "correct" way now, but they have been mostly removed. Trying the existing GetProperty/SetProperty doesn't work, as they don't trigger actions or scripts, only allow you you to set the properties of the items on the screen. (The stuff on the first tab on the item properties in the editor.)

I may have missed them, but is there a way of triggering these "internal" actions from lua? And by extension, is there a way of trigging any of the other "events" that are registered on the second tab of a screen button/item. (Yes, you could directly call script actions from within lua. Actions seem to be the main missing piece, with perhaps "goto screen", but I haven't researched that one.)

I know there are other ways of doing this. As an example, I have code written that uses "mcJogSetInc()" to set the individual axis increments. (Which in some ways is more powerful, as you can have different increments for each axis.) However, there may be cases that you need to trigger the internal action from lua. And in this case, the direct call does not give the use a way of using the configured jog increments from the configuration file.

Is there a way of triggering this action, perhaps a "mcTriggerAction(inst, "Cycle Jog Increment")", or are there plans to directly map all the actions to mc lua calls (IE. "mcActionCycleJogIncrement())?

Thanks all.

Jim

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Calling an "Action" from a lua script
« Reply #1 on: January 30, 2016, 04:40:43 AM »
To do something like this you would need to script your own function, heres a start for ya.

Code: [Select]
local inst = mc.mcGetInstance() -- declare our instance
local CurInc = mc.mcProfileGetInt(inst,"Preferences","JogIncSet",0) --make a new setting in profile to hold our current inc number

CurInc = CurInc + 1 -- increment our CurInc by 1

if CurInc > 10 then CurInc = 1 end -- if our CurInc is greater than 10 then go back to 1

local SetInc = mc.mcProfileGetDouble(inst,"Preferences","JogInc"..CurInc,0.00) -- fetch our inc value from the profile JogInc + 2 say = [Preferences][JogInc2]

mc.mcJogSetInc(inst, mc.X_AXIS, SetInc) -- set inc for axis
mc.mcJogSetInc(inst, mc.Y_AXIS, SetInc) -- set inc for axis
mc.mcJogSetInc(inst, mc.Z_AXIS, SetInc) -- set inc for axis

mc.mcProfileWriteInt(inst,"Preferences","JogIncSet",CurInc) --set our profile to new CurInc

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Calling an "Action" from a lua script
« Reply #2 on: January 30, 2016, 08:52:00 AM »
Thanks for the help.

I haven't played a lot with the profile functions yet, but it makes sense how you are getting the values from the profile to fill in the values for the jog inc.

The code is also easily extended to support skipping non-used increments. (IE. iterate past any 0's you find until you get to the non-zero result, rolling over as needed.)

Additionally, we would then change the text box displaying the current jog increment (txtJogInc in wx4 for example,) to not use the label code "Current Jog Increment", but instead set the label directly with the set properties command. (Or, alternatively, setup a register for that value, and set that box to use that register.)

This should solve the problem nicely, although in a slightly different way.

Thanks again.

Jim