質問

Starting with a single cube, I have changed some properties (material, color, reflection attributes), and then duplicated the object into a dozen cubes, placing them in the scene. After rendering, I'd like to change the color of all of them. How do I do this efficently?

I have found multiple ways already:

  1. In object mode, select all objects (B, then rectangular select), join the meshes ctrl-j, change the color, tab into edit mode, P to seperate the objects again. This is quite possible since the meshes of all my objects do not touch. Basics docs
  2. Someone wrote a Python script to do similar stuff, here

Number 1 is error prone and too tedious for regular use. Number 2 is more specialized and much worse. Just selecting multiple objects and changing the value does not work because the property selections apply only to the active object which is only one of those selected.

As this is a common use case I'm probably missing the easy way. What is it?

役に立ちましたか?

解決 2

While I did not find the much preferred simple button or gui solution, it turned out that hacking your own Python code in Blender is easier than one might think.

The cubes I am working with are more like domino stones. Subsequently all objects looking like dominoes have a name starting with "Domino". It is very easy to alter all objects in a scene based on their name:

for o in bpy.data.objects:
    if not "Domino" in o.name:
        continue
    o.rigid_body.mass = 500
    o.rigid_body.friction = 0.4
    o.rigid_body.restitution = 0.95
    o.rigid_body.angular_damping = 0.2
    o.rigid_body.linear_damping = 0.05

To use this code I simply opened a new window (drag the little upper right triangle icon on any existing Blender window), changed the window type to "Python Console" (lower left window type select icon), and then paste the above code into it.

The code can be edited in an external text editor. Alternatively one can open a text editor window inside Blender as well. Upon saving a scene, both the Python console and the internal text editor are stored along the 3D model which makes for a very nice workflow.

Finding the correct object names - such as bpy.data.objects["Domino.033"].rigid_body.mass is very easy, because Blender does show these when hovering over any form entry field with the mouse pointer. If one has identified an object, use Python's dir() function to get a list of all known methods and attributes of an object. There may be more than the gui allows to modify or use.

This was much easier than I thought. It probably explains why one can think of some complex manipulation for which there is no gui element - it's simply much easier to handle in code. I'll probably use this to duplicate and position objects along lines, circles, spirals instead of using Blender's own array attributes. It will allow for easier later position adjustments.

他のヒント

If you just want to change one parameter for multiple objects RMB click on control(text field for example) and choose Copy to selected.

Activate 3D View: Copy Atributes Menu in User Preferences and call it with ctrl+c if you want to copy modifiers or such

http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Copy_Attributes_Menu

Here's a Blender 3D Tip: To work on a bunch of objects at a time, enable the "Copy Attributes" plugin that comes with Blender but isn't on by default: open "User Preferences", click "Addons", then search for "copy attributes" to find the "3D View: Copy Attributes Menu" plugin. Enable the plugin then close preferences.

To use:, in the 3D view, select one or more TARGET objects, then lastly select the SOURCE object. Press "Ctrl-C" on keyboard and see menu of every attribute type you can copy. Click one (e.g. scale) and you will see the scale of the source object will be applied to the previously selected objects.

Here's the manual entry http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Copy_Attributes_Menu

This in response to:

http://obasandbox.wordpress.com/2011/10/23/cg-blender-setting-properties-on-multiple-objects/

I'm curious why you couldn't just tune a Material. Blender makes it really easy to re-use the elements of an object. You can have 100 objects that share a single mesh. You can have 100 meshes that share a set of 4 materials.

I'm imagining a set of dominos would have 21 meshes (for all the 1-6 x 1-6 combinations). Those meshes would have 2 or 3 materials (one for the pips, and one or two more for the body). If properly linked you could change out the color on all the pips by changing the one material used by all the meshes.

Using python to bulk-modify object is very powerful and applicable to a great many problems, but sometimes the solution is easier.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top