[Bf-python] re-ordering collection items

CoDEmanX codemanx at gmx.de
Wed May 14 09:11:38 CEST 2014


Some support re-ordering by re-assignment, just like regular python lists:

m = Object.materials # assuming there are only two!
m[0], m[1] = m[1], m[0]

The Modifier stack does not support this. There is no other way to 
re-order modifiers than to use operators.

CollectionProperty() creates objects from <class 
'bpy_prop_collection_idprop'>, which comes with a handy method move().
You give it the index of which element you want to move, and another 
index for the target position to swap these two elements.


Am 14.05.2014 04:02, schrieb Tamito KAJIYAMA:
> Hi,
>
> Is there a general way to re-order items of bpy_prop_collection
> in Python? For example, how can we swap two modifiers in
> bpy.context.object.modifiers? Since the collection is read-only,
> the general Python sequence protocol seems not to work.
>



More information about the Bf-python mailing list