2
$\begingroup$

Hey I need to store a list of objects each with a value associated, is storing a list of tuples and splitting it at the end ok? Is there a better way to store multiple values?

#store vars
self.stored_selection = bpy.context.selected_objects
self.stored_bevel_list = []

for obj in self.stored_selection:
    for mod in obj.modifiers:            
        if mod.type == "BEVEL":
            if mod.segments > 1:  

                #store tuple in list (object and number of segments)
                entry = (obj, mod.segments)
                self.stored_bevel_list.append(entry)
                mod.segments = 1

#<modal operator>

#restore each objects segments
for item in self.stored_bevel_list:
    #break tuple into two variables
    item,number = item                
    for mod in item.modifiers:
        mod.segments = number
$\endgroup$
2
$\begingroup$

Custom properties.

Could store the segments in a custom property on the object with the same name as the modifier.

for obj in self.stored_selection:
    for mod in obj.modifiers:            
        if mod.type == "BEVEL" and mod.segments > 1:
            obj[mod.name] = mod.segments
            mod.segments = 1

and restore with

for obj in self.stored_selection:
    for mod in obj.modifiers:            
        if mod.type == "BEVEL":
            segments = obj.get(mod.name)
            if segments:
                mod.segments = segments
                #del(obj[mod.name]) # remove prop?

Another method would be to make a list of all the bevel modifiers with the segments value. Need to proceed with a little caution when saving lists of object, or in this case modifier, references. If you remove an object that has the modifier, then try and reference later from list may produce a system fault and crash blender.

bevel_mods = [m, m.segments for o in context.selected_objects
        for m in o.modifiers
        if m.type == 'BEVEL'
        and m.segments > 1]

for m, segments in bevel_mods:
    # print object name modifier name segments
    print(m.id_data.name, m.name, segments)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.