I would like to set some rules before loading a date object, into the current project. But I don't really know how to do it and if it is possible to do it.
So I give an example:
I would like to import (Then load) an object, only if it has a material in at least bpy.data.objects['object_name'].data.materials[:]
Unfortunately I realized that the bpy.data.libraries.load() method may not do what I have in mind.
Below, I report what I tried to do (which obviously does not work) but forste explains better what I would like to do:
with bpy.data.libraries.load(my_path, link=False) as (data_from, data_to):
objs_to_load=[]
for obj in data_from.objects:
if obj.data.materials[:]: # <--Incorrect example on purpose
objs_to_load.append(obj)
data_to.objects = objs_to_load
Clearly in the example above there is an error, I cannot read obj.data.materials, as it results in a string. The problem is that I don't want to import the object, as I don't want to fill the memory with useless objects for my purpose.
Anyone have any idea how to do it if it is possible?