Logic Machine Forum
import export script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: import export script (/showthread.php?tid=2136)



import export script - fabiorusco - 29.06.2019

Hello,
I need to export all the scripts of a Spacelynk, find and replace the "Main group address" and after import them in another visualization.

Is it possible do it? How?

Best regards


RE: import export script - admin - 01.07.2019

Do you need to replace group addresses in script source code only or trigger group addresses for event scripts as well?


RE: import export script - fabiorusco - 02.07.2019

(01.07.2019, 10:54)admin Wrote: Do you need to replace group addresses in script source code only or trigger group addresses for event scripts as well?
I need change both, groups addresses in the script sand the trigger groups addresses.


RE: import export script - Snoolik - 03.07.2019

(02.07.2019, 05:59)fabiorusco Wrote:
(01.07.2019, 10:54)admin Wrote: Do you need to replace group addresses in script source code only or trigger group addresses for event scripts as well?
I need change both, groups addresses in the script sand the trigger groups addresses.

Hello, I made alike script for shifting all adresses through db updating today. It shifts all ga with a step in modbus mapping, visualization, trends, object logs and a trigger for event scripts. Also it can change name of ga.
Code:
log('start')
a = grp.all()
step = -( 1 * 2^11 + 2 * 2^8 + 3 ) -- shift for -(1/2/3)
for i = 1, #a, 1 do -- if step < 0
--for i = #a, 1, -1 do -- if step > 0
 old_id = a[i].id
 id = old_id + step
 knx_addr = knxlib.decodega(id)
 old_knx = knxlib.decodega(old_id)
 old_name = a[i].name
 new_name = 'Shifted ' .. old_name
-- change ga
 sql_query = "UPDATE objects SET id=?, rowid=?, address=? WHERE id=?"
 db:query(sql_query, id, id, id, old_id)
-- update name
 sql_query = "UPDATE objects SET name=? WHERE name=?"
 db:query(sql_query, new_name, old_name)
--update modbus ga mapping
 sql_query = "UPDATE modbus_mapping SET bus_address=? WHERE bus_address=?"
 db:query(sql_query, id, old_id)
-- update visualization objects
 sql_query = "UPDATE visobjects SET object=? WHERE object=?"
 db:query(sql_query, id, old_id)
 sql_query = "UPDATE visobjects SET statusobject=? WHERE statusobject=?"
 db:query(sql_query, id, old_id)
-- update ga in object logs
 sql_query = "UPDATE objectlog SET address=? WHERE address=?"
 db:query(sql_query, id, old_id)
-- update ga for trends
 sql_query = "UPDATE trends SET object=? WHERE object=?"
 db:query(sql_query, id, old_id)
-- I don't think that it's necessary, but update tags for ga
 sql_query = "UPDATE objecttags SET object=? WHERE object=?"
 db:query(sql_query, id, old_id)
-- update ga in scheluders
 sql_query = "UPDATE schedulers SET object=? WHERE object=?"
 db:query(sql_query, id, old_id)
-- update trigger ga for event scripts
 sql_query = "UPDATE scripting SET params=? WHERE params=?"
 db:query(sql_query, knx_addr, old_knx)
end

log('end')
 
For changing scripts you can try this:
Code:
function shift_knx(addr)
  step = 0 * 2^11 + 1 * 2^8 + 0
  decode_knx = knxlib.encodega(addr)
  new_knx = decode_knx + step
  new_addr = knxlib.decodega(new_knx)
  return new_addr
end
scripts = db:getall("SELECT script FROM scripting")
for i = 1, #scripts, 1 do
  new_script = string.gsub(scripts[i].script, "%d+/%d+/%d+", shift_knx)
  db:query("UPDATE scripting SET script=? WHERE script=?", new_script, scripts[i].script)
end
I had a event script for ga 0/0/23, which decoded is 23, shifting with a step 256 make it 0/1/23. So, you can improve it to solve your task.
Script was very simple just for testing:
Code:
log(grp.getvalue('0/0/23'))

Both of this scripts were tested on 20180828 LM Firmware. Homelynk can have little difference in db structure.
If you have any questions, I'll try to answer =)


RE: import export script - fabiorusco - 03.07.2019

I only need to change the  "Main group address", in all script and trigger group address for event script.
example 15/7/1 should be 11/7/1 (from 1 to 17, excluded 15 that is the number from I start).


RE: import export script - Snoolik - 04.07.2019

(03.07.2019, 14:32)fabiorusco Wrote: I only need to change the  "Main group address", in all script and trigger group address for event script.
example 15/7/1 should be 11/7/1 (from 1 to 17, excluded 15 that is the number from I start).

I edited my past code a bit to improve its understanding and rewrote script for changing ga in body of scripts. Now the "step" is the sum of the three parameters: main group + middle group + group address. If you need to change only main group then you can change first parameter of "step" and other set to 0.