Posts: 317
Threads: 42
Joined: Apr 2019
Reputation:
4
Hello,
I need to edit the names of the group addresses in bulk. For example, from group 1/1:
1/1/1 -> LIGHTING - ON/OFF - L01
1/1/2 -> LIGHTING - ON/OFF - L02
and so on...
1/1/100 -> LIGHTING - ON/OFF - L100
Only the object name needs to be changed, without modifying labels or data types.
Posts: 5802
Threads: 31
Joined: Aug 2017
Reputation:
266
Do you want to just set names of your object to the rule defined above or modify them?
------------------------------
Ctrl+F5
Posts: 5802
Threads: 31
Joined: Aug 2017
Reputation:
266
Run this script once
Code:
-- Bulk rename: 1/1/1 → LIGHTING - ON/OFF - L01 ... 1/1/100 → LIGHTING - ON/OFF - L100
for i = 1, 100 do
local addr = string.format('1/1/%d', i)
local name = string.format('LIGHTING - ON/OFF - L%02d', i)
-- grp.create overwrites an existing object's name without touching
-- its datatype, tags, comment, or value — when you pass only
-- address + name + forcename=true.
local ok, err = grp.create({
address = addr,
name = name,
forcename = true, -- replace the name even if the object already exists
})
if ok then
log(string.format('Renamed %s → "%s"', addr, name))
else
log(string.format('SKIP %s (does not exist or error: %s)', addr, tostring(err)))
end
end
log('Bulk rename complete.')
------------------------------
Ctrl+F5