This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Mass generating new GAs via script
#1
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)
Reply
#2
(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.
Reply
#3
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.
Reply
#4
(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.
Reply
#5
I just tried and it worked for me. Did you set the password?
Reply
#6
(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...
Reply
#7
(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?
Reply
#8
No ... that's it Sad
sorry ...
everything works well after emptying the cache and Export objects ...
Thanks a lot.
B.R.
Reply


Forum Jump: