I am new to programming. Since Blender, I communicate with the PostgeSQL database. The purpose of the code is:
1 / Browse the table "works" and find new date_works for each object. 2 / affect the material to each object based on the date. 3 / if an object is in the group 'work', we find the parent. If date_works of the child is higher than that of the mother, we hide the child object.
This is the point 3, which does not. What do you think of my code? What is wrong? Thank you.
#Find the most recent work in the table "works"
for works ,recentW in db.prepare("SELECT mesh_ works,max(date_ works) FROM works GROUP BY mesh_ works"):
year=str(recentW.year)
mat_M= bpy.data.materials.get(year)
mesh=bpy.data.meshes["%s"% works]
for obj in bpy.data.objects:
if (obj.data==mesh):
c=obj
# materials allocation in accordance with the date found. (example: finding dates 2015 => material it affects the "2015")
c.active_material=mat_M
# ensure that these objects are visible
c.hide=False
# hide child objects whose work dates predate those of parents
#if it is a child,
if c.name in bpy.data.groups["Child"].objects:
#find parent
parent=c.parent
#search in the database of the most recent date of the parent
recentParent=db.prepare("SELECT MAX(date_ works) FROM works WHERE id_ works='%s'"%parent)
#if the date of the parent is more recent than that of the child while the child is masked.
for recent in recentParent:
if(recent[0]!=None):
yearParent=str(recent[0].year)
if(yearParent>=year):
c.hide=True
return {'FINISHED'}
if (obj.data==mesh):
should be ifobj.type == 'MESH':
. My advice would be to add print statements to what the script does and if it doesn't behave as you want add more prints of variable to find out why. If you want answer here, isolate part 4, or give it a try on stackoverflow. $\endgroup$