Multi Exporter error

When selecting a group of objects with LODs ( all their names ends with _LOD0
to _LOD6 ), with all LOD values sets in the Multi Exporter, pressing the
“Generate XML” button results in the following error seen in the Max listener.

Traceback (most recent call last):
  File "C:\MSFS_SDK\Tools\3dsMax\FlightSimPackage\scripts\MultiExporter\multiExporter.py", line 84, in 
    self.btnGenerateXML.pressed.connect(lambda: self._clickedGenerateXML())
  File "C:\MSFS_SDK\Tools\3dsMax\FlightSimPackage\scripts\MultiExporter\multiExporter.py", line 287, in _clickedGenerateXML
    log += exporter.createLODMetadata(metadataPath, objects)
  File "C:\MSFS_SDK\Tools\3dsMax\FlightSimPackage\scripts\MultiExporter\exporter.py", line 375, in createLODMetadata
    xmlLog = writeXML(xmlPath, modelInfo)
  File "C:\MSFS_SDK\Tools\3dsMax\FlightSimPackage\scripts\MultiExporter\exporter.py", line 421, in writeXML
    dom_string = os.linesep.join([s for s in xmlstr.splitlines() if s.strip()])
TypeError: sequence item 0: expected str instance, bytes found

With no XML file generated. Also, the behavior changes if there’s already an
XML file for that object in the Export folder. If there is one, instead of
being updated, it becomes locked to write (likely because due the above error
it wasn’t closed). If there isn’t one, it’s not created. Also, when using the
“Export ticked” or “Export selected”, I get the following error on all LODs:

Something went wrong while updating the XML file of FSDT_KCLT_Light_Taxi_LOD0, the XML will not be updated but the export will still be performed : 
ERROR : This file doesn't exist. can't update it

This error repeats for LOD0 to LOD6, but the .BIN/.GLT files are exported.
This happens regardless if layers are not used ( all objects on default layer
0 ) or are conformed using the “Conform Layers” option.

@lpierabella FYI

Hi! I’ve wanted to experiment exporting models with some LODs, but,
unfortunately, I’m getting the same error, however the error repeats for all
LODs and no files are exported at all. Did you found what’s causing this? Thx!

Had this issue for a while now so I decided to find out and make a fix for it.
(Had to export over 500 objects)… Here is the code that should work for
exporting XML’s from the multiexporter.

def writeXML(xmlPath, root):
    """Write a xml.etree.ElementTree to a xml file.

    \nin:
          xmlPath= str
          root= xml.etree.ElementTree.Element
    \nout:
          log= str
    """

    maxVersion = rt.maxversion()

    output = ET.tostring(root)
    xmlstr = minidom.parseString(output).toprettyxml(
        encoding='utf-8', indent="   ")
    if(maxVersion[0] > 22000):
        utfStr = str(xmlstr, "utf-8")
    else:
        utfStr = str(xmlstr)
    dom_string = os.linesep.join([s for s in utfStr.splitlines() if s.strip()])
    exists = os.path.exists(xmlPath)
    sdkperforce.P4edit(xmlPath)
    try:
        myfile = open(xmlPath, "w+")
        myfile.write(dom_string)
        if(not exists):
            sdkperforce.P4edit(xmlPath)
        return ""
    except IOError:       
        return "\nPermission denied. The XML file is not writable. Please make sure your perforce environment is the same as your 3dsMax Project.\nIf you're not using perforce, make the xml file writable."




File is in: %MSFS SDK%\Tools\3dsMax\FlightSimPackage\scripts\msfs_max_py\MultiExporter\expoter.py

Hope that this should work Itay

Hi, Itay! With your fix, I can now generate XMLs, however, I’m not sure if I
do something wrong, but there’s no ModelFile name in XML. This is the
generated file

when it should be like this (???)

Thank you!

Hello, If your gltf names end with _LODX, (X being a number), the sim will
find the gltf names based on the xml name plus the _LODX suffix. This is valid
and the sim can work with that.

That’s awesome! Thank you!!!