Logic Machine Forum
Set export option with 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: Set export option with script (/showthread.php?tid=3427)



Set export option with script - sebastian.strasser - 18.06.2021

Hello,

how can i set the option export for a groupaddress with a script?


Background:
I have to set export for many addresses on many different spacelynks for bacnet access.
I want to create a script who makes this automatic. The scheme is on every spacelynk the same, so i can catch the right addresses with a script.

Many Thanks


RE: Set export option with script - Erwin van der Zwart - 19.06.2021

Can be done with script, but fastest way is to set a filter and do a mass edit to enable the export flag..


RE: Set export option with script - sebastian.strasser - 19.06.2021

Hello Erwin,

no, for me is the fastest way with a script. I have to set to many different filters for this on 50 different Spacelynks.

What is the command for setting the option? I don't see it in the documentation.

Thanks


RE: Set export option with script - admin - 21.06.2021

You can set the export field via a DB query:
Code:
db:update('objects', { export = 1 }, { id = 1 })
db:update('objects', { export = 1 }, { id = 2 })
db:update('objects', { export = 0 }, { id = 3 })
db:update('objects', { export = 1 }, { id = 4 })

script.reloadbacnet()

Check if you have the latest firmware because there was a bug when the BACnet service stopped working after a certain number of reload calls.


RE: Set export option with script - christian.hegland@caverion.com - 30.05.2023

(21.06.2021, 06:42)admin Wrote: You can set the export field via a DB query:
Code:
db:update('objects', { export = 1 }, { id = 1 })
db:update('objects', { export = 1 }, { id = 2 })
db:update('objects', { export = 0 }, { id = 3 })
db:update('objects', { export = 1 }, { id = 4 })

script.reloadbacnet()

Check if you have the latest firmware because there was a bug when the BACnet service stopped working after a certain number of reload calls.

Hi admin,

Would it be possible to "reverse" this function, and make a script that outputs all the objects that's already exported?
The usecase would be when I'll have to mass delete all knx objects and re-import them, I could run the script beforehand, to get all exported objects,
and then easily set them with the script you provided earlier in this thread.

Would be awesome if this functionallity were implemented in LM5. By using for instance the object filter, and filter by exported objects


RE: Set export option with script - admin - 31.05.2023

Save all objects IDs with export enabled to storage:
Code:
ids = db:getlist('SELECT id FROM objects WHERE export=1')
storage.set('export_ids', table.concat(ids, ','))

Restore from storage:
Code:
ids = storage.get('export_ids')
if type(ids) == 'string' and #ids > 0 then
  db:query('UPDATE objects SET export=1 WHERE id IN (' .. ids .. ')')
end
script.reloadbacnet()



RE: Set export option with script - christian.hegland@caverion.com - 31.05.2023

(31.05.2023, 06:44)admin Wrote: Save all objects IDs with export enabled to storage:
Code:
ids = db:getlist('SELECT id FROM objects WHERE export=1')
storage.set('export_ids', table.concat(ids, ','))

Restore from storage:
Code:
ids = storage.get('export_ids')
if type(ids) == 'string' and #ids > 0 then
  db:query('UPDATE objects SET export=1 WHERE id IN (' .. ids .. ')')
end
script.reloadbacnet()

Fantastic! Thank you very much Big Grin
Would it also be possible to use the script to add a tag called (export)?
Then i could filter objects by the tag name

(31.05.2023, 09:26)christian.hegland@caverion.com Wrote:
(31.05.2023, 06:44)admin Wrote: Save all objects IDs with export enabled to storage:
Code:
ids = db:getlist('SELECT id FROM objects WHERE export=1')
storage.set('export_ids', table.concat(ids, ','))

Restore from storage:
Code:
ids = storage.get('export_ids')
if type(ids) == 'string' and #ids > 0 then
  db:query('UPDATE objects SET export=1 WHERE id IN (' .. ids .. ')')
end
script.reloadbacnet()

Fantastic! Thank you very much Big Grin
Would it also be possible to use the script to add a tag called (export)?
Then i could filter objects by the tag name


RE: I think i solved it:

ids = db:getlist('SELECT id FROM objects WHERE export=1')
storage.set('export_ids', table.concat(ids, ','))

-- loop over the ids and add the 'export' tag
for _, id in pairs(ids) do
    grp.addtags(id, 'export')
end



RE: Set export option with script - admin - 31.05.2023

In this case you need to store ids as a table, not as a string:
Code:
ids = db:getlist('SELECT id FROM objects WHERE export=1')
storage.set('export_ids', ids)

Tag script:
Code:
ids = storage.get('export_ids')
for _, id in ipairs(ids) do
  grp.addtags(id, 'export')
end