Posts: 84
Threads: 22
Joined: Apr 2022
Reputation:
0
Hi
I'm trying to organize my Objects a bit with giving them tags I can use in scripting or just to filter what I need to see.
All my objects in building "small" is called "Small - Living Room - Light 1 On/Off" I want to give that Object 4 tags (Small, Living Room, Light 1, On/Off).
If I use the Object filter and type "Small" and then Mass edit > Object properties > Field list > Tags and type in "Small" it works.
But if I then use the Object filter again and type in "Living Room" and click Mass edit > Object properties > Field list > Tags, then there is no text and if I write "Living Room" and click "Save" then it deletes everything but the new tag "Living Room".
Posts: 4938
Threads: 28
Joined: Aug 2017
Reputation:
225
Some years ago I made this script, now would do it differently but still will work.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
seperators =
'.,_ =+'
start_main =
0
start_sub =
0
start_address =
1
end_main =
15
end_sub =
7
end_address =
255
function split (
source ,
delimiters )
local elements = {}
local pattern =
'([^' ..
delimiters.. ']+)'
string.gsub (
source ,
pattern ,
function (
value )
elements [#
elements +
1 ] =
value ;
end );
return elements
end
start_objectaddress = ((
start_main *
2048 ) + (
start_sub *
256 ) +
start_address )
end_objectaddress = ((
end_main *
2048 ) + (
end_sub *
256 ) +
end_address )
all_objects =
db :
getall (
'SELECT address, name, tagcache FROM objects' )
for _ ,
object in ipairs (
all_objects )
do
if object.address >=
start_objectaddress and object.address <=
end_objectaddress then
currentrowaddress =
object.address
myobject =
grp.find (
currentrowaddress )
nameTable =
split (
myobject.name ,
seperators )
for _ ,
tag in ipairs (
nameTable )
do
tagvalue =
tag
current_object_tag =
db :
getall (
'SELECT object, tag FROM objecttags WHERE object = ' ..
currentrowaddress ..
' AND tag = "' ..
tagvalue ..
'"' )
object_tagcache =
db :
getone (
'SELECT tagcache FROM objects WHERE address = ' ..
currentrowaddress ..
'' )
if #
current_object_tag ==
0 then
db :
insert (
'objecttags' , {
object =
currentrowaddress ,
tag =
tagvalue , })
if object_tagcache ==
nil or object_tagcache ==
"" then
db :
update (
'objects' , {
tagcache =
tagvalue }, {
address =
currentrowaddress })
else
tag_string =
"" ..
object_tagcache ..
", " ..
tagvalue ..
""
log (
tag_string )
db :
update (
'objects' , {
tagcache =
tag_string }, {
address =
currentrowaddress })
end
end
end
end
end
script.disable (
_SCRIPTNAME )
------------------------------
Ctrl+F5
Posts: 84
Threads: 22
Joined: Apr 2022
Reputation:
0
Thanks alot, do I just add it to the common functions?
Posts: 4938
Threads: 28
Joined: Aug 2017
Reputation:
225
No, you run this script once as a script, can be resident. Based on used separators it will auto generate tags from the object name.
------------------------------
Ctrl+F5