1
$\begingroup$

I have a VRML version of a PDB file imported into Blender.
Every geometric segment has its own material assigned even though the materials are identical. Can I select the objects by color instead of by material?

$\endgroup$
  • $\begingroup$ I'm not familiar with this kind of imported file, but is your molecule all represented by a single mesh? If yes, maybe this scripted approach could help. $\endgroup$ – Nicola Sap Sep 5 '17 at 15:51
  • 2
    $\begingroup$ There is no such thing as "colors" in Blender, only materials. Could you clarify what you are trying to do, maybe post some screenshots $\endgroup$ – Duarte Farrajota Ramos Sep 5 '17 at 23:53
  • $\begingroup$ The answer is no, however you can group them to the same vertex group so that you can select them more easily later on. $\endgroup$ – VRM Sep 6 '17 at 0:42
  • $\begingroup$ I opened the PDB file (these are representations of proteins) in Pymol changed the representation to "ribbon" with one color and "saved image as VRML2". When I import this into Blender it comes in as thousands of tiny segments and spheres, each with its own material, but all are the same color (e.g. red 1.0, blue 1.0, green 0.0). When I join them into a single mesh there are thousands of material slots, all identical. I actually wanted to make the mesh semi transparent, (sorry for being unclear). So I used material util add on, removed all slots and made one new one. Thanks for your help! $\endgroup$ – Elyz Sep 6 '17 at 21:07
1
$\begingroup$

This simple script loops through the visible objects, and checks if the active object's diffuse color (blender internal) matches. If they do match, then that object gets selected.

Make sure the active object has a material with the color you want to merge. Then load the script below in blender's text editor and hit "Run Script".

After you run the script all you need to do is press CrtlL then M. Or from the 3D view header Object > Make Links... > Materials.

import bpy
active = bpy.context.scene.objects.active
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.context.visible_objects:
    if obj.type == "MESH":
        if obj.data.materials[0].diffuse_color == active.data.materials[0].diffuse_color:
            obj.select = True
active = bpy.context.selected_objects[0]
| improve this answer | |
$\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.