Hello Guest it is April 23, 2024, 05:38:38 AM

Author Topic: scr.GetProperty  (Read 1317 times)

0 Members and 1 Guest are viewing this topic.

scr.GetProperty
« on: October 30, 2020, 07:26:58 AM »


Hi


I always used scripts to collect information from screen components, and I never had any problems, but for some reason they stopped working.

local scale =scr.GetProperty("sliderScale","Value");

This or another Property , led, texbox , slider etc, always returns nil.


I have no mistake and I can't figure out why, any ideas?


Thanks





Offline Bill_O

*
  •  563 563
    • View Profile
Re: scr.GetProperty
« Reply #1 on: October 30, 2020, 08:59:52 AM »
I think you need to use ' not "

local scale =scr.GetProperty('sliderScale','Value')
Re: scr.GetProperty
« Reply #2 on: October 30, 2020, 09:21:22 AM »
I think you need to use ' not "

local scale =scr.GetProperty('sliderScale','Value')


I had already verified this and it doesn't work, besides all my scripts are this way they will always work.

It has to be something else, I also tried the same command in a totally new mach4 installation and it still doesn't work.

Offline Bill_O

*
  •  563 563
    • View Profile
Re: scr.GetProperty
« Reply #3 on: October 30, 2020, 10:09:50 AM »
Sorry I do not know what could be the problem.
I try to stay away from scr.
I use registers and the mc every chance I get.
Re: scr.GetProperty
« Reply #4 on: October 30, 2020, 12:04:05 PM »
First is to make sure that you have the component name spelled exactly as it appears in the screen tree.  If you run the following script line by line in the debug mode (F5 followed by F11, F11) cursor over sc should be a 'table:' and rc should be the value you were looking for.  I have this tested this since it is using an existing slide component.
 
local sc=scr
local rc=scr.GetProperty('slideSRO','Value')
local tst=1

HTH

RT
Re: scr.GetProperty
« Reply #5 on: October 30, 2020, 01:08:08 PM »
First is to make sure that you have the component name spelled exactly as it appears in the screen tree.  If you run the following script line by line in the debug mode (F5 followed by F11, F11) cursor over sc should be a 'table:' and rc should be the value you were looking for.  I have this tested this since it is using an existing slide component.
 
local sc=scr
local rc=scr.GetProperty('slideSRO','Value')
local tst=1


for me it always returns nill, I can't get any properties from any of the components.

This is very strange, because I never had this problem, it always worked very well, I even tried a new installation  and a different pc.






« Last Edit: October 30, 2020, 01:10:06 PM by marix »

Offline Graham Waterworth

*
  • *
  •  2,673 2,673
  • Yorkshire Dales, England
    • View Profile
Re: scr.GetProperty
« Reply #6 on: November 04, 2020, 07:35:48 PM »
I am not sure you can do that if the property is on a panel.
Without engineers the world stops
Re: scr.GetProperty
« Reply #7 on: November 13, 2020, 12:02:28 AM »
I had the same issue with latest Mach4. It wasn't an issue in past versions. It's also restricting access to the scr API in the modules. This is the workaround I used.

**Note this won't work with sliders or DRO's attached to special functions in Mach4 (ie FeedRate Override or Spindle Override sliders) but you can use the mc API directly to get those values instead of the scr API like this:

Code: [Select]
percent, rc = mcSpindleGetOverride(inst)
percent, rc = mc.mcCntlGetFRO(inst)
percent, rc = mc.mcCntlGetRRO(inst)

The workaround:

Goto Configure->Control->Plugins and enable Regfile plugin and restart Mach4

Goto Configure->Plugins->Regfile and create a new register in the Global Registers tab. Leave persistent unchecked with nothing in initial value (you might want to consider persistence for some components). Hit apply.

Open the screen editor and select the component you want to get the value from (ie slider). Then in the properties select Register and assign it the register you just created. The Regfile register paths are near the bottom of that list and start with prefix gRegs0/.

You should then be able to get the value in an M script from the register like this:

Code: [Select]
local inst = mc.mcGetInstance()
droSliderReg = mc.mcRegGetHandle(inst, 'gRegs0/sroValue')
val = mc.mcRegGetValue(droSliderReg)
mc.mcCntlSetLastError(inst, string.format("Slider value: %s", val))

The information in a text box component will not populate a gReg until you press enter after changing the value of the text or if you click somewhere else on the screen.
« Last Edit: November 13, 2020, 12:06:16 AM by compewter_numerical »