Logic Machine Forum
Read Custom values from Script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Read Custom values from Script (/showthread.php?tid=4946)



Read Custom values from Script - khalil - 05.09.2023

Hello Dear,
I want to use the custom value in the script, How?


RE: Read Custom values from Script - Daniel - 05.09.2023

Can you explain more what you want to do? Do you want to create custom value on a object via script or instead of object value use custom value in scripting?


RE: Read Custom values from Script - admin - 05.09.2023

See this: https://forum.logicmachine.net/showthread.php?tid=2297&pid=14379#pid14379


RE: Read Custom values from Script - khalil - 05.09.2023

(05.09.2023, 12:44)Daniel Wrote: Can you explain more what you want to do? Do you want to create custom value on a object via script or instead of object value use custom value in scripting?

Hello Dear,
Yes the second one

(05.09.2023, 12:49)admin Wrote: See this: https://forum.logicmachine.net/showthread.php?tid=2297&pid=14379#pid14379

Could I use it with Tag_Data = grp.tag(Used_Tag)
or should I use  grp.find


RE: Read Custom values from Script - Daniel - 05.09.2023

Then look on the admin link.


RE: Read Custom values from Script - Erwin van der Zwart - 05.09.2023

grp.find will return a single object properties table, grp.tag will return a table with all objects that have the specified tag so you must iterate this table and then use the sample code if you want to use grp.tag instead of grp.find, so yes possible but requires a small change in the sample code…


RE: Read Custom values from Script - khalil - 06.09.2023

hello Erwin,
Code:
for i, obj in ipairs(Tag_Data) do
log(obj)
.....

the custom values are not in the log table!

Quote:* table:
["decoded"]
  * bool: true
["disablelog"]
  * number: 1
["pollinterval"]
  * string:
["datahex"]
  * string: 01
["units"]
  * string:
["value"]
  * bool: true
["comment"]
  * string:
["updatetime"]
  * number: 1693924997
["datatype"]
  * number: 1
["readoninit"]
  * number: 0
["data"]
  * bool: true
["id"]
  * number: 65878
["address"]
  * string: 32/1/86
["export"]
  * number: 0
["name"]
  * string: TEst For Test-2
["tagcache"]
  * string: Office VRV ON/OFF

How could I achieve that instead of adding a grp.find ?


RE: Read Custom values from Script - admin - 06.09.2023

This won't work without an extra grp.find or a db query:
Code:
json = require('json')
objs = grp.tag('my_tag_name')

for _, obj in ipairs(objs) do
  enums = db:getone('SELECT enums FROM objects WHERE id=?', obj.id)
  enums = json.decode(enums)

  log(enums)
end



RE: Read Custom values from Script - khalil - 06.09.2023

Thank You admin
you have the solution as always, is there a Guide how to use the  db query:  
Also thank you Erwin for pointing on this solution.