05-16-2024, 11:42 PM
Clearly, I don't understand how to use the AppSettings object. The documentation says that it can load and save parameters to the station. My hope was that any script in the station could use this to read/write parameters. This sounds really useful. I made up this little script - assuming that the values would not exist when it was run the first time, but the values would be there the second time it was run:
When this script runs, the first list of attributes (after loading) is always empty and the saving doesn't seem to do what I expect it to. No matter how many times it runs the list of attributes is always empty after loading.
Yes, I did look at the examples on github - the AppTemplate add-in. I don't understand why a script like OptionCheckable.py has to import from AppSettings.py if the settings are stored in the station. If I run the AppSetting.py script from the top menu bar and change the values like this it seems to remember then the second time is it run.
Hoping to learn something, I changed the OptionCheckable.py script so that it ~should~ display the value from the dialog box above. It is no longer setting the parameters, just reading them.
But when I run OptionCheckable (from the top menu) it seems to be ignoring the values from the settings dialog and looks like this:
So I am even more confused. Why is the OptionCheckable script not getting the values from the AppSettings script? Is there a place where it is forcing that setting into a boolean?
Like I mentioned in the first sentence, I am missing some knowledge.
Thanks for your time.
Code:
from robodk import robolink
from robodk import robomath
from robodk import roboapps
# RoboDK reference
RDK = robolink.Robolink()
print('start')
settings = roboapps.AppSettings('MySettings')
# No idea why this does not print anything...
print(type(settings))
# Load settings from the active station
settings.Load()
print(settings.getAttribs())
# Change/Add some settings with their values
settings.forecast = 'cloudy'
settings.color = 'blue'
settings.temperature = 70
print(settings.getAttribs())
# Save the settings back to the station
settings.Save()
print('end')
When this script runs, the first list of attributes (after loading) is always empty and the saving doesn't seem to do what I expect it to. No matter how many times it runs the list of attributes is always empty after loading.
Yes, I did look at the examples on github - the AppTemplate add-in. I don't understand why a script like OptionCheckable.py has to import from AppSettings.py if the settings are stored in the station. If I run the AppSetting.py script from the top menu bar and change the values like this it seems to remember then the second time is it run.
Hoping to learn something, I changed the OptionCheckable.py script so that it ~should~ display the value from the dialog box above. It is no longer setting the parameters, just reading them.
Code:
def ActionChecked():
"""Action to perform when the action is checked in RoboDK."""
RDK = robolink.Robolink()
S = Settings()
S.Load(RDK)
#RDK.setParam(S.APP_OPTION_KEY, 1.0)
#ShowMessage(RDK, ACTION_NAME, str(RDK.getParam(S.APP_OPTION_KEY)), False)
ShowMessage(RDK, "Testing", str(RDK.getParam(S.APP_OPTION_KEY)), False)
def ActionUnchecked():
"""Action to perform when the action is unchecked in RoboDK."""
RDK = robolink.Robolink()
S = Settings()
S.Load(RDK)
#RDK.setParam(S.APP_OPTION_KEY, 0.0)
ShowMessage(RDK, ACTION_NAME, str(RDK.getParam(S.APP_OPTION_KEY)), False)
But when I run OptionCheckable (from the top menu) it seems to be ignoring the values from the settings dialog and looks like this:
So I am even more confused. Why is the OptionCheckable script not getting the values from the AppSettings script? Is there a place where it is forcing that setting into a boolean?
Like I mentioned in the first sentence, I am missing some knowledge.
Thanks for your time.