![]() |
|
Export - Import Tags of LM Objects - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2) +--- Thread: Export - Import Tags of LM Objects (/showthread.php?tid=2412) |
Export - Import Tags of LM Objects - p_xatzi - 03.01.2020 Hi, Happy New Year to all! I would like to ask if it is possible to export Tags of LM objects and then after changes to the these objects to be able to import the file again and update the Tags to the new LM Objects. The issue I am facing is that I link Tag names to scripts and after changes to ETS project and importing of .esf file, Tags disappear and so I have to enter them manually. I guess Tags (at least manually) could be linked to object names (for the case of GA shifting) or to GA (for the case of name changes). Thank you in advance. RE: Export - Import Tags of LM Objects - Daniel - 03.01.2020 The thing you ask for is not easly possible. Try this script, it automatically tag objects based on its name. It use defined separators to define tag from name. Code: seperators = '.,_ =+'
-- Start address of objects (min: 0/0/1 = main/sub/address)
start_main = 0
start_sub = 0
start_address = 1
-- End address of objects (max: 31/7/255 = main/sub/address)
end_main = 15
end_sub = 7
end_address = 255
------------------------------------------ End Parameters ------------------------------------------
------------------------------ DON'T CHANGE ANYTHING UNDER THIS LINE -------------------------------
function split(source, delimiters)
local elements = {}
local pattern = '([^'..delimiters..']+)'
string.gsub(source, pattern, function(value) elements[#elements + 1] = value; end);
return elements
end
-- Calculate start address to DB format
start_objectaddress = ((start_main * 2048) + (start_sub * 256) + start_address)
-- Calculate end address to DB format
end_objectaddress = ((end_main * 2048) + (end_sub * 256) + end_address)
-- Get all objects from DB
all_objects = db:getall('SELECT address, name, tagcache FROM objects')
for _, object in ipairs(all_objects) do
-- Check if object is inside given range
if object.address >= start_objectaddress and object.address <= end_objectaddress then
currentrowaddress = object.address
myobject = grp.find(currentrowaddress)
nameTable = split(myobject.name, seperators) --spliting object string in to table
-- log(nameTable)
for _, tag in ipairs(nameTable) do
tagvalue = tag
-- Check if object tag already exists inside DB
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
-- Add object to table objecttags
db:insert('objecttags', {object = currentrowaddress, tag = tagvalue, })
-- Check if object already has other tag values inside DB and add new values to tagcache
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)RE: Export - Import Tags of LM Objects - p_xatzi - 03.01.2020 Hi, Thanks for the reply and script. Basically, I was hoping that there is a way to export and import LM objects (including their Tags). I believe that it should be part of configuration environment as it is common to have an option to export and import objects. This way is really easy to make changes, keep archive and much more. Hope to be included some time because right now I find it really difficult to make changes and to reuse parts of one project to another. Same applies to other sections of the environment like script where for example I want to import only two scripts which I don' t have a way to export them separately and to append them later. Thanks one more! RE: Export - Import Tags of LM Objects - p_xatzi - 04.01.2020 [quote pid='15202' dateline='1578081499'] Hi, For those who are interested I found a solution with help of excel. I attach sample file which shows the logic which is:
The whole process for that file is as follows:
The advantage of this process in my opinion is that first you keep archive through excel file. Then you bind LM Objects to ETS Objects (ETS can be used as a tool even with modbus e.t.c.) and its really easy to make changes to objects. Just change objects fields, refresh, paste and run. In addition there is no need to use dummy Group Objects linked to GA (that are created only for the sake of organizing the objects) in order for those to be part of ETS's ".esf" exported file... For anyone interested I can send him that file. Just PM me and give your e-mail. [/quote] |