Proxy: fix sync_collection() for multiple same entries + add clear_dst option

This commit is contained in:
Moritz Brückner 2020-08-10 00:14:57 +02:00
parent ebce14419b
commit e193b3dae2

View file

@ -94,20 +94,22 @@ def sync_modifiers(obj):
for prop in properties: for prop in properties:
setattr(mDst, prop, getattr(mSrc, prop)) setattr(mDst, prop, getattr(mSrc, prop))
def sync_collection(cSrc, cDst): def sync_collection(col_src, col_dst, clear_dst=True):
cDst.clear() """Synchronizes collection properties. If `clear_dst` is False, the
for mSrc in cSrc: destination collection is not cleared before syncing."""
mDst = cDst.get(mSrc.name, None) if clear_dst:
if not mDst: col_dst.clear()
mDst = cDst.add()
for m_src in col_src:
m_dst = col_dst.add()
# collect names of writable properties # collect names of writable properties
properties = [p.identifier for p in mSrc.bl_rna.properties properties = [p.identifier for p in m_src.bl_rna.properties
if not p.is_readonly] if not p.is_readonly]
# copy those properties # copy those properties
for prop in properties: for prop in properties:
setattr(mDst, prop, getattr(mSrc, prop)) setattr(m_dst, prop, getattr(m_src, prop))
def sync_traits(obj: bpy.types.Object): def sync_traits(obj: bpy.types.Object):
"""Synchronizes the traits of the given object with the traits of """Synchronizes the traits of the given object with the traits of