def execute(self, context):
for x in bpy.context.object.material_slots:
bpy.context.object.active_material_index = 0
bpy.ops.object.material_slot_remove()
D = bpy.data
if len(D.objects['Cube'].material_slots) < 1:
D.objects['Cube'].data.materials.append(D.materials['Cube material'])
else:
D.objects['Cube'].material_slots[0].material = D.materials['Cube material']
if len(D.objects['Cone'].material_slots) < 1:
D.objects['Cone'].data.materials.append(D.materials['Cone material'])
else:
D.objects['Cone'].material_slots[0].material = D.materials['Cone material']
My simple scrypt first deletes existing material, then assigns for Cube, âCube materialâ, Script does the same for Cone Everything works fine as long as the Cube and Cone are on scene. When the Cube is missing, I get this Error: KeyError: âbpy.prop_collection[key]: key âCubeâ not foundâ What to do to make scrypt work even though the Cube is not on scene, but there is one of the objects[for example Cone] included in the script?
I would like the script to work, for example one object is on the scene [of two], for example a Cube. Now, the script doesnât work, because if there is only a Cube on the scene, it writes an error that there is no Cone.
Greets
And I have problem with bpy.ops.sculpt.mask_expand When I press my button i have such a error RuntimeError: Operator bpy.ops.sculpt.mask_expand()failed, context is incorrect What I should change or add to code ?
I will be very grateful for any help
Without running your code, in guessing itâs the mask operator that is throwing the error- if thatâs the case itâs because you are not in sculpt mode when the operator is run. This could be because you are setting the mode to âSCULPTâ and then toggling it back off on the next line. Try removing the toggle and see if that helps.
Without this toggle I have this same problem. Is not working. This mask_expand is start working after You press LMB, and with second LMB You are finish creating this mask. Maybe I should use Invoke but I donât know how âŚ