I want to assign various properties to objects and then select all objects with a certain set of values for those properties.
The objects are graphs from tests (created with CSV Mesh Importer, so they are lines, not solids). They all have a value for, for example, length and width (not of the Blender object but of the object the test was done on). I want to then select all objects that have, say, length 5.3 and width 3.8.
I already found that I can group objects and then select the grouped objects. But for that I have to select one of the objects first. But I want to select the properties, and a set of them, and then select all objects that share that set of properties.
I also found Custom Properties, but I can't figure out how that works, and most explanations use Python, but I want to do it in the GUI. Also, I want to set the properties just once, and that is not what it seems to be meant for.
I can select objects based on a property now. But after 2 hours of searching, I still haven't figured out the first bit, how to assign a custom property. I tried this:
for obj in bpy.data.objects: obj.addProperty("length")
but then I get:
Attribute error: 'Object' object has no attribute 'addProperty'
And that's just assigning a property (I want to assign this to all objects). Next I'lll have to set the value (for objects I select by hand).
I have given up on Custom Properties and decided to set the z-values of various vertices to the values I want to give the graphs. I managed to make that work for one graph, but not for all selected graphs.
This is the relevant section of the code I wrote:
for obj in bpy.data.objects: if obj.select: print(obj) bpy.ops.object.mode_set(mode='EDIT') bm = bmesh.from_edit_mesh(obj.data) # get bMesh representation for vertex in bm.verts: for var in vars: if vertex.index==var and var==1: # If the vertex is on one of the var-locations and that var is marked to be set. vertex.co=var # Set the vertex's z-value to the value for that variable in the variable-list. elif abs(vertex.co-var)<precision: # If the vertex's z-value already has one of the variable-values, that might be confusing, ... vertex.co=0.0 # ... so set it to 0. bpy.ops.object.mode_set(mode='OBJECT')
Again, this works for the first graph, and in the console (from the print-line) I see the names of the first and second graph. But then I get 'the mesh must be in edit mode'. In the 3D view I see the first graph still is in edit mode, so apparently the line
Correction: with this code it got stuck the first time, on the line bm = mesh....., whilst previously this only happened on the second pass. I must have changed something. Sorry, I always get lost in programming.