From 4987505ed5ac50c016ee226655f80d968943c391 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 16 Oct 2014 16:29:23 +0200 Subject: [PATCH] Add BlendFileBlock.get_pointer helper function --- packer/blendfile.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packer/blendfile.py b/packer/blendfile.py index 8627019..19e4f9e 100644 --- a/packer/blendfile.py +++ b/packer/blendfile.py @@ -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