Skip to content

[BUG] key error when importing scene #112

@knittinkittin

Description

@knittinkittin

hey, so this is sort of already solved, but just mentioning it in case anyone's having the same problem.

when i went to import MODELS\SPACESTATION\SPACESTATION.SCENE.MXML, i would get this error:

Python: Traceback (most recent call last):
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\NMSDK.py", line 933, in execute
importer.render_scene()
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\ModelImporter\import_scene.py", line 345, in render_scene
added_obj = self._add_empty_to_scene(self.scene_node_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\ModelImporter\import_scene.py", line 612, in _add_empty_to_scene
self.descriptor_data = read_descriptor(descriptor_path + '.MXML')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\ModelImporter\readers.py", line 230, in read_descriptor
data = read_TkModelDescriptorList(data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\ModelImporter\readers.py", line 206, in read_TkModelDescriptorList
'Children': [read_TkModelDescriptorList(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxxxx\AppData\Roaming\Blender Foundation\Blender\4.2\scripts\addons\nmsdk\ModelImporter\readers.py", line 207, in
x['List']) for x in desc['Children']]}
~^^^^^^^^
KeyError: 'List'

but some other models, like MODELS\SPACESTATION\MODULARPARTS\DOCK\ENTRANCESECTION.SCENE.MXML i could import fine, and the only difference between them i could notice, as someone who can only barely follow code, was that the entrancesection model didn't have a descriptors file.

anyway, being lazy and a bad coder, i threw it into deepseek and it gave me this change to the read_TkModelDescriptorList() function in ModelImporter/readers.py:

def read_TkModelDescriptorList(data: dict) -> dict:
    ret_data = dict()
    for d in data:
        desc_data = []
        for desc in d.get('Descriptors', []):
            # Safely handle 'Children' entries
            children = []
            for child in desc.get('Children', []):
                # Check if 'List' exists in the child structure
                if 'List' in child:
                    children.append(read_TkModelDescriptorList(child['List']))
            sub_desc_data = {
                'Id': desc.get('Id'),
                'Name': desc.get('Name'),
                'ReferencePaths': desc.get('ReferencePaths', []),
                'Children': children  # Use the filtered list
            }
            desc_data.append(sub_desc_data)
        ret_data[d['TypeId']] = desc_data
    return ret_data

hope someone finds this helpful in some way!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions