Hello Guest it is March 28, 2024, 09:33:07 AM

Author Topic: Using a button script to set jog increments etc  (Read 14577 times)

0 Members and 1 Guest are viewing this topic.

Re: Using a button script to set jog increments etc
« Reply #10 on: May 20, 2018, 09:13:38 AM »
Hi,
the ScreenScript.lua is the combination of ALL the smaller screen scripts combined. It is compiled at run time and it is this one chunk of code that actually
runs. Its displayed for our convenience, you can't edit it. It useful to search and find a particular bit of code or function but you have to go to the
individual script before you can edit or debug it.

It may appear that its the same script in each profile, its not. There is enough code common to all profiles that it gives the appearance of being identical
but closer inspection will reveal code which is specific to a profile.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #11 on: May 20, 2018, 09:25:48 AM »
Ah, so it's an amalgam of whatever screen scripts are present in all of the profiles then?

I'll have to look at how to create scripts that have function names then, because at the moment I'm just adding scripts where you access them directly from the button.
Re: Using a button script to set jog increments etc
« Reply #12 on: May 20, 2018, 09:33:19 AM »
Hi,

Quote
Ah, so it's an amalgam of whatever screen scripts are present in all of the profiles then?
Yes.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #13 on: May 20, 2018, 09:42:37 AM »
Hi,
a button that has a script will also occur in the combined ScreenScript.lua.

You will have noticed that certain buttons have an action whereas others have a script or scripts.

Actions are selectable from a drop down list. These are standard actions that Mach developers believe will be most often required. They are within the core and are not open to view
or to edit. A script on the other hand is available to view and edit.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #14 on: May 20, 2018, 10:47:29 AM »
Thanks for your patience in explaining what might be obvious to a lot of users.

Just a couple of things...

For example, there's a Cycle Start function in the ScreenScript.lua that's used to select the action taken depending on what tab is active. That's clearly something added as part of the design of that specific screen. It's a named function that I can apply to any button, but how can that be edited? I can see it in the ScreenScript.lua which I appear to be able to edit and modify if I do to Operations->Open Script Editor

So it looks like you can edit ScreenScript.lua and that's where these things are defined. Am I getting the wrong end of the stick? I can't see function CycleStart() defined anywhere else.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #15 on: May 20, 2018, 12:52:27 PM »
The screen script is a screen resource.  Meaning it is part of the screen set.  You edit the screen to edit the script.  It has nothing to do with a machine profile other than the profile determine WHAT screen is use with it.  Fore example, multiple profile could use the same screen set.  Or each profile could use a different set. 

As Craig mentioned, the larger ScreenScript.lua is generated from smaller script snippets in the screen.  So you can't edit the ScreenScript.lua file directly.  See section 5 of "Mach4 Screen Editor V1.0.pdf" in the docs folder.

Usually, if one wants to make a function available for the screen elements, the function is put in the screen load script.  This allows for any button to call that function from their respective event scripts, etc..  So you will see the CycleStart() function in the screen load script. 

Now, do you NEED to put the code into the screen load script?  It depends.  If the code is something that is repetitive and common, then adding it as a function in the screen load script becomes desirable.  But if the button code is very specific to a certain button, then just use the button event script to do the whole job.  A LOT of times, doing all of the the code in the button event script is more clear to the intent.  Readability is important a year from now if you decide to change something and have pretty much forgotten what you are doing now.  :)  It really depends on what is most comfortable/effective for you. 

Steve
Re: Using a button script to set jog increments etc
« Reply #16 on: May 20, 2018, 04:59:22 PM »
Hi Steve,
Now that's the document I could have used days ago! It's not in the Docs folder or anywhere else in the Mach4 download, but I've found it on the internet and now have it in there.

I see your point about scripts being largely dedicated to specific buttons. There's one case where I want to have radio button LED indicators against four buttons. You could argue that it would be neater to have a 'clear all radiobutton LEDs' function that each button could call to clear the others before setting its own LED.

While I'm on that subject, how can you write to the properties of one screen component from the script of another? Say turn on an LED or change the colour of one button from the script of another. You might want to do that if you were creating radio buttons where the background colour of the button indicates which one is selected. This sort of thing is dead easy in something like Delphi or Visual Basic, so I imagine this environment is similar.

Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Using a button script to set jog increments etc
« Reply #17 on: May 20, 2018, 07:20:23 PM »
Yes, you use the screen API.  It is not documented other than you will get the function signatures in the ZeroBrane editor.  The two staples are:

string: value, number: rc = scr.GetProperty(string: ctrlName, string: propertyName)

number: rc = scr.SetProperty(string: ctrlName, string: propertyName, string: value)

The control name is the name you have given the screen element in the Name property.  It is case sensitive.  
The property name is the name of the property as spelled in the property grid.  Value, for example. Or Top, Left, Width, Height, etc...

The value of the property is always a string.  Use tonumber() to convert a string to a number in LUA.  Conversely, use tostring() to convert a number to a string.  Some properties are lists, which have values associated with the string description in the list.  In this case, you will get the value instead of the string description.

Keep in mid that it is ALWAYS better to use the underlying data that backs the screen element instead of the screen element itself, if possible.  For instance, if there is a slider on the screen named "myFROslider" that sets the feed rate override, use mc.mcCntlGetFRO() instead of scr.GetProperty('myFROslider', 'Value").  This is part of the reason that this stuff is not documented.  Because people will use it and not use the main Mach API proper.  I JUST ran into this when support gave me a supposed "BUG" the other day.  It wasn't a bug.  The slider is imprecise because it is pixel based.  If the slider has a range of 0 to 250, but the slider is displayed in less than 250 pixels, well...  there are going to be gaps in the range when using the slider.  Meaning you can start sliding it up from zero and get counts like 1, 2, 3, 5, 6, 7, 9.  So it wasn't a bug at all!!!!  It is why the FRO slider in fresh on my mind.  Yeah, I went down that rabbit hole. 

The other reason is I just don't like writing documentation.  LOL

99% of the time, these scr.* functions are not needed.  If you find yourself needing them all of the time, take a step back and think about how it could be done some other way.  Most of the time, the ONLY time you may absolutely need them is for a screen specific function.  Like the figuring out what tab is current to make the Start Cycle button process MDI commands instead of running a file.  

Steve
« Last Edit: May 20, 2018, 07:26:43 PM by smurph »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Using a button script to set jog increments etc
« Reply #19 on: May 21, 2018, 04:03:21 AM »
Hi Steve,
Ok, I'll look into using that method. Since there's no 'Radio button' group in Mach4, there's no obvious way to turn off an LED that is now inactive unless you force it off directly. In the situation I have, the radio buttons set different values for the jog step increments so you can't just link them to a source.

I hear what you're saying about using the underlying data, but that's hard to find. Again, in the example I have, I want to use a script to mimic several functions such as the one that selects a particular preset jog increment for the jog. That's easy to do when it's selectable from a drop down list, but I can't see a way to accomplish that from a script. Maybe it's in the documentation about how to do this, but I can't find it. I also can't find out where the increment ends up after its been selected, so I can't link a text box to the current jog value.

So in general, to a newbie, there are many obstacles to doing what at first glance ought to be trivial, but it appears to be more difficult. I see there's a partial listing of some of the internal variables, but I really think there should be a complete one for cases such as this.

I know writing documentation sucks, but it would save a lot of heartache for those of us who don't have access to the source to just look this stuff up.