Skip to content

Commit

Permalink
Fix copy & paste issue
Browse files Browse the repository at this point in the history
This works around an issue in Blender 4.2 where IDPropertyGroups cannot be assigned a dictionary

Fixes #473
  • Loading branch information
hlorus committed Aug 21, 2024
1 parent 9c45b6f commit 6cabd1f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions serialize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pickle
from typing import Union, Optional
from pathlib import Path
from typing import Dict

from bpy.types import Scene

Expand All @@ -25,16 +26,29 @@ def dict_extend(original_dict, other):
# }


def scene_to_dict(scene):
def apply_dict(parent, d: Dict):
"""Applies values from a dictionary to members of a IDPropertyGroup"""
for key, value in d.items():
if not isinstance(value, dict):
parent[key] = value
continue

# Handle dictionaries recursivley
apply_dict(parent[key], value)


def scene_to_dict(scene: Scene) -> Dict:
"""Returns a dictionary which represents the relevant contents of the given scene"""
original = scene["sketcher"].to_dict()
elements = {key: original[key] for key in ("entities", "constraints")}
return elements


def scene_from_dict(scene, elements):
def scene_from_dict(scene: Scene, elements: Dict):
"""Constructs a scene from a dictionary"""
original = scene["sketcher"].to_dict()
original.update(elements)
scene["sketcher"].update(original)
apply_dict(scene["sketcher"], original)


def _extend_element_dict(scene, elements):
Expand All @@ -49,7 +63,7 @@ def _extend_element_dict(scene, elements):
return scene_dict


def fix_pointers(elements):
def fix_pointers(elements: Dict):
"""Go through all properties and offset entity pointers"""

import bpy
Expand Down

0 comments on commit 6cabd1f

Please sign in to comment.