Selecting and Moving Objects

Hi Everyone,

I am pretty new to Python in Blender, what I am trying to do is select all the objects on a particular layer then move them to a different layer.

Is there a simply way to do this?

Also does anyone know how to simulate the Add new meshes button from the Radiosity section in Python code.



you could use this for you change layer thingy:

EndLayer = 1
StartLayer = 4

ObList = Blender.Object.Get()

for Object in ObList:
     if Object.Layer == StartLayer:
          Object.Layer = EndLayer

print "done!"

that should work


Object.Layer gives you a bitmask, so Layer1 = 1, Layer2 = 2, Layer3 = 4, Layer4 = 8 and so on. So if you do something like

Object.Layer = 5

your Object will be on Layer1 and Layer3.
And theeths’ code might not work with Emptys, there is no way to move your emptys between layers with Python.

The simplest way to use values from 1 to 20 for the layer you would want to move it to, is:

object.Layer = 1 << (blayer-1)

where blayer is a number from 1 to 20

Or if you would want it to move to multiple layers, you could create a function to make a bitmask contructed from a list containing the layer numbers:

def createLayerBMask(layers):
	bmask = 0
	for layer in layers:
		bmask |= (1 << (layer-1))
	return bmask

So you could do something like:

ob.Layer = createLayerBMask([1, 4, 7])

It does work with Empty’s btw.

Thanks Guys,

That helps a lot. :stuck_out_tongue:

What I am trying to write is a Radiosity Animator Script. It will loop through all of the frames in the animation, calculate the radiosity, then save the radiosity image to a file.

All I have left to do is figure out how to save the rendered image to a file, and how to render the view, the same as pressing the render this view button on the 3d window header.

Is there some documentation anywhere that lists the entire Blender API impementation. I have found a few small examples but nothing complete.



Then your out of luck depending on what you want to do. The only way to start a render is by using the Blender210 module which is available upto Blender version 2.23:

import Blender210
ds = Blender210.getDisplaySettings()

You also can start the radiosity render with this:


BUT, there is no way (at least that I know of) to automatically replace meshes or add meshes, which you would have to do when radiosity calculations have ended…