Logic Machine Forum
Mass generating new GAs via 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: Mass generating new GAs via script (/showthread.php?tid=1246)



Mass generating new GAs via script - buuuudzik - 21.02.2018

Here there is a script for mass generate new GAs via script according to specified template and rules. It can save a lot of time and clicking but before do some BACKUP.

Code:
-- GENERATE all group addresses according to specified template and conditions
firstId, lastId = 1, 10 -- e.g. Blind1 to Blind10

canChangeMiddle = true -- if yes can change e.g. 0/0/255 -> 0/1/0
canChangeMain = false -- if yes can change e.g. 0/7/255 -> 1/0/0
offset = 10 -- address offset between first GA in 2 devices e.g. Blind41_up/down - Blind40_up/down = 0/0/20 - 0/0/10 = 10

curMain, curMiddle, curSub = 0, 0, 0 -- initial GA e.g. 1, 2, 3 means 1/2/3
numberOfAddedGAs, numberOfNotAddedGAs = 0, 0 -- init the counters of new or updated objects and not created objects
for curId = firstId, lastId, 1 do
 curSubMax = curSub + 7 -- maximum subaddress in current iteration
 
 if curSubMax > 255 and canChangeMiddle then
   if ((curMiddle + 1) <= 7) then curSub, curMiddle = 0, curMiddle + 1
   else
     if canChangeMain and (curMain + 1) <= 15 then curSub, curMiddle, curMain = 0, curMiddle + 1, curMain + 1
     else log('Cannot increment main group.'); break end
   end
 elseif (curSubMax > 255 and not canChangeMiddle) then log('Cannot increment middle group.'); break end
 
 curMainAndMiddle = curMain .. '/' .. curMiddle .. '/'
 template = {
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 1, name = 'Blind' .. curId .. '_up/down'},
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 2, name = 'Blind' .. curId .. '_step/stop'},
   {datatype = dt.uint8, address = curMainAndMiddle .. curSub + 3, name = 'Blind' .. curId .. '_scene'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSub + 4, name = 'Blind' .. curId .. '_height'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSubMax, name = 'Blind' .. curId .. '_height status'} -- Maximum subaddress
 };
 
 for k,v in ipairs(template) do
   res = grp.create(v)
   if res then numberOfAddedGAs = numberOfAddedGAs + 1 else numberOfNotAddedGAs = numberOfNotAddedGAs + 1 end
 end
 
 curSub = curSub + offset
end

message = ''
if numberOfAddedGAs > 0 then message = 'Successfully added or updated ' .. numberOfAddedGAs .. ' new GAs. ' end
if numberOfNotAddedGAs > 0 then message = message .. 'There was ' .. numberOfNotAddedGAs .. ' errors(not added or updated objects).' end
if numberOfAddedGAs > 0 or numberOfNotAddedGAs > 0 then log(message) end

script.disable(_SCRIPTNAME)



RE: Mass generating new GAs via script - Gadjoken - 25.06.2019

(21.02.2018, 16:37)buuuudzik Wrote: Here there is a script for mass generate new GAs via script according to specified template and rules. It can save a lot of time and clicking but before do some BACKUP.

Code:
-- GENERATE all group addresses according to specified template and conditions
firstId, lastId = 1, 10 -- e.g. Blind1 to Blind10

canChangeMiddle = true -- if yes can change e.g. 0/0/255 -> 0/1/0
canChangeMain = false -- if yes can change e.g. 0/7/255 -> 1/0/0
offset = 10 -- address offset between first GA in 2 devices e.g. Blind41_up/down - Blind40_up/down = 0/0/20 - 0/0/10 = 10

curMain, curMiddle, curSub = 0, 0, 0 -- initial GA e.g. 1, 2, 3 means 1/2/3
numberOfAddedGAs, numberOfNotAddedGAs = 0, 0 -- init the counters of new or updated objects and not created objects
for curId = firstId, lastId, 1 do
 curSubMax = curSub + 7 -- maximum subaddress in current iteration
 
 if curSubMax > 255 and canChangeMiddle then
   if ((curMiddle + 1) <= 7) then curSub, curMiddle = 0, curMiddle + 1
   else
     if canChangeMain and (curMain + 1) <= 15 then curSub, curMiddle, curMain = 0, curMiddle + 1, curMain + 1
     else log('Cannot increment main group.'); break end
   end
 elseif (curSubMax > 255 and not canChangeMiddle) then log('Cannot increment middle group.'); break end
 
 curMainAndMiddle = curMain .. '/' .. curMiddle .. '/'
 template = {
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 1, name = 'Blind' .. curId .. '_up/down'},
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 2, name = 'Blind' .. curId .. '_step/stop'},
   {datatype = dt.uint8, address = curMainAndMiddle .. curSub + 3, name = 'Blind' .. curId .. '_scene'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSub + 4, name = 'Blind' .. curId .. '_height'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSubMax, name = 'Blind' .. curId .. '_height status'} -- Maximum subaddress
 };
 
 for k,v in ipairs(template) do
   res = grp.create(v)
   if res then numberOfAddedGAs = numberOfAddedGAs + 1 else numberOfNotAddedGAs = numberOfNotAddedGAs + 1 end
 end
 
 curSub = curSub + offset
end

message = ''
if numberOfAddedGAs > 0 then message = 'Successfully added or updated ' .. numberOfAddedGAs .. ' new GAs. ' end
if numberOfNotAddedGAs > 0 then message = message .. 'There was ' .. numberOfNotAddedGAs .. ' errors(not added or updated objects).' end
if numberOfAddedGAs > 0 or numberOfNotAddedGAs > 0 then log(message) end

script.disable(_SCRIPTNAME)
Hello,
Is it possible to copy the G.A. of a logic machine and then paste them on another from a backup?

It is not necessary to copy all the parameters of the BACKUP but only the addresses so as not to rewrite all the addresses on the second L.M. 
(The addresses were not created from ETS but directly on the logic machine can not import them via ESF)
B. R.



RE: Mass generating new GAs via script - Daniel - 25.06.2019

If you export all GAs then you can use import neighbors feature. To use it you have to enable w Remote services first. All exported GAs will be imported to second LM.


RE: Mass generating new GAs via script - Gadjoken - 25.06.2019

(25.06.2019, 09:26)Daniel. Wrote: If you export all GAs then you can use import neighbors feature.  To use it you have to enable w Remote services first.  All exported GAs will be imported to second LM.



Thank you for your quick reply.
Remote services is enable.
It does not work when we use this import between a SpaceLynk and a Logic machine? (Error : host not found)

B.R.


RE: Mass generating new GAs via script - Daniel - 25.06.2019

I just tried and it worked for me. Did you set the password?


RE: Mass generating new GAs via script - Gadjoken - 25.06.2019

(25.06.2019, 11:59)Daniel. Wrote: I just tried and it worked for me. Did you set the password?


I just try again after emptying the cache of my browser it tells me : imported none discarded none
I have standard objects...


RE: Mass generating new GAs via script - Daniel - 25.06.2019

(25.06.2019, 12:30)Gadjoken Wrote:
(25.06.2019, 11:59)Daniel. Wrote: I just tried and it worked for me. Did you set the password?


I just try again after emptying the cache of my browser it tells me : imported none discarded none
I have standard objects...

Did you export the objects?


RE: Mass generating new GAs via script - Gadjoken - 25.06.2019

No ... that's it Sad
sorry ...
everything works well after emptying the cache and Export objects ...
Thanks a lot.
B.R.