lmartin - 2021-01-22

Hi,

I use the code below to export project and libraries to PLCopenXML. All works well except that in a project resource excluded from build are exported too and I don't want that resources.

When I export manually I export ALL and excluded resources are not exported.

I have attached a project sample ans XML result

from __future__ import print_function
import sys, io, os

proj=projects.primary

if proj is None:
   system.write_message(Severity.Error, "%s" % ("No project opened...",))
   sys.exit()

info = proj.get_project_info()
ext = proj.path.rsplit(".",1)[1]
if ext == "library":
   xmlPath = proj.path.rsplit("\\",1)[0] + "\XML\LIBS"
   filename = "{}\{}.xml".format(xmlPath, info.title)
else:
   xmlPath = proj.path.rsplit("\\",1)[0] + "\XML\CELLS"
   prjName = proj.path.rsplit("\\",1)[1].rsplit(".")[0]
   filename = "{}\{}.xml".format(xmlPath,prjName)

if not os.path.exists(xmlPath):
   try:
      os.makedirs(xmlPath)
   except OSError as e:
      if e.errno != errno.EEXIST:
         raise


nodes = proj.get_children(True)

# Create the export reporter
class Reporter(ExportReporter):
   def error(self, *args):
      system.write_message(Severity.Error, "%s" % (args,))

   def warning(self, *args):
      #system.write_message(Severity.Warning, "%s" % (args,))
      return

   def resolve_conflict(self, obj):
      return ConflictResolve.Copy

   def added(self, obj):
      print("added: ", obj)

   def replaced(self, obj):
      print("replaced: ", obj)

   def skipped(self, obj):
      print("skipped: ", obj)

   def nonexportable(self, object):   
      #system.write_message(Severity.Information, "Object not exportable: %s" % object)
      return

   @property
   def aborting(self):
      return False

#print("Saving project")
proj.save()
system.write_message(Severity.Information, "%s" % ("Project saved",))
#print("Installing library")

if ext == "library":
   repo = librarymanager.repositories [0]
   librarymanager.install_library (proj.path, repo, True)
   system.write_message(Severity.Information, "%s" % ("Library installed",))

reporter = Reporter()
#print("Export XML")
proj.export_xml(reporter, nodes, filename)
system.write_message(Severity.Information, "%s" % ("XML exported",))

Talk Topic about project #scripting

 

Related

Talk.ru: 1