Add BlendFileBlock.get_pointer helper function

This commit is contained in:
2014-10-16 16:29:23 +02:00
parent f3fa2d9407
commit 4987505ed5

View File

@@ -227,6 +227,22 @@ class BlendFileBlock:
return dna_struct.field_set(
self.file.header, self.file.handle, path, value)
# ---------------
# Utility get/set
#
# avoid inline pointer casting
def get_pointer(self, path):
result = self.get(path)
assert(self.file.catalog.structs[self.sdna_index].field_from_path(self.file.handle, path).dna_name.is_pointer)
if result != 0:
# possible (but unlikely)
# that this fails and returns None
# maybe we want to raise some exception in this case
return self.file.find_block_from_offset(result)
else:
return None
# ----------------------
# Python convenience API