10.01.2020, 10:52
Hi
I am trying to create a script that can find a certain text inside the object name and replace it with another string. This is so I do not need to do this manually every time there is a large change.
For normal GA I would just use the update from ESF-file solution, but I often have a lot of virtual addresses as well, and they also must be updated.
I am able to find the adresses to update, and to generate the new name, but for some reason I am not able to update the name of the object. If anyone has an idea of why, please give me a hint.
The code I have entered is as follows;
I am sorry for Norwegian names in variables, but that makes it more easy to prevent using a word that has a LUA-meaning....
I am trying to create a script that can find a certain text inside the object name and replace it with another string. This is so I do not need to do this manually every time there is a large change.
For normal GA I would just use the update from ESF-file solution, but I often have a lot of virtual addresses as well, and they also must be updated.
I am able to find the adresses to update, and to generate the new name, but for some reason I am not able to update the name of the object. If anyone has an idea of why, please give me a hint.
The code I have entered is as follows;
Code:
finn = '360.001'
replace = '360.002'
kriterie = '08-0'
liste = db:getall('SELECT name FROM objects WHERE name LIKE "%'.. kriterie .. '%" AND name LIKE "%'.. finn .. '%"')
--
for _, name in ipairs(liste) do
navn = name.name
--log(navn)
if string.find(navn, finn, 1, true) == nil then
log('fikk nil')
else
log('fant strengen')
newName = string.gsub(navn, finn, replace)
log(navn, newName)
ga = grp.find(navn)
--db:update('objects', { name = newName }, { id = id })
--log(ga)
address = grp.create({
address = ga.address,
name = newName,
})
end
end
log('Ferdig')
script.disable(_SCRIPTNAME)
I am sorry for Norwegian names in variables, but that makes it more easy to prevent using a word that has a LUA-meaning....
There are 10 kinds of people in the world; those who can read binary and those who don't