Logic Machine Forum
Any way to delete all NON LM objects? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Any way to delete all NON LM objects? (/showthread.php?tid=1722)



Any way to delete all NON LM objects? - MantasJ - 15.11.2018

Hello,

What I want to achieve: I want to set all names of my objects (knx) to exact names that are in my ets project, but the only way to do this is to delete the existing objects and import new ones. Problem is that there are very many objects and I dont want to delete them in small quantities - I want to delete them all at once and import all at once, here I face a problem: if I delete all my objects I will delete my LM created objects too and I have very many scripts and won't remember them all. Maybe there is a way to delete only knx objects from logicmachine?

Thanks, I hope those who read understood my point  Rolleyes


RE: Any way to delete all NON LM objects? - Daniel - 15.11.2018

Hi
You can do it like that
https://forum.logicmachine.net/showthread.php?tid=1621&pid=9898#pid9898
BR


RE: Any way to delete all NON LM objects? - MantasJ - 15.11.2018

Thank You!


RE: Any way to delete all NON LM objects? - MantasJ - 18.11.2018

Code:
data = io.readfile('/home/ftp/data.esf')

if data then
  lines = data:split('\n')

  for _, line in ipairs(lines) do
    props = line:split('\t')

    if #props >= 5 then
      addr = props[1]:match('[0-9]+/[0-9]+/[0-9]+$')

      if addr then
        name = props[2]:trim()
        id = buslib.encodega(addr)
        db:update('objects', { name = name }, { id = id })
      end
    end
  end

  os.remove('/home/ftp/data.esf')
end
Is there any way to use this code with .json files instead of .esf? The reason is that .esf does not export knx objects which are not linked to anything and in addition it does not support some symbols from my language so instead of normal symbol it puts "?" in that place.


RE: Any way to delete all NON LM objects? - Daniel - 19.11.2018

Hi
You can try to use this tool to convert ESF text symbols in better format. http://openrb.com/convert/
BR


RE: Any way to delete all NON LM objects? - MantasJ - 19.11.2018

Yes I've tried it but it converts to other symbols not from my language so it's not really helping. If I import a clean .json file though, everything works perfectly - all symbols are in their places so I want a solution with .json file.


RE: Any way to delete all NON LM objects? - admin - 21.11.2018

Use this for JSON:
Code:
require('json')
file = '/home/ftp/data.json'
data = json.pdecode(io.readfile(file))

if type(data) == 'table' and type(data.objects) == 'table' then
  for id, obj in pairs(data.objects) do
    id = tonumber(obj.id or id)

    if type(id) == 'number' and type(obj.name) == 'string' then
      db:update('objects', { name = obj.name }, { id = id })
    end
  end

  os.remove(file)
end



RE: Any way to delete all NON LM objects? - MantasJ - 21.11.2018

Thank You very much! I'll try it as soon as possible and report how it went Smile

P.S It works perfectly!