Blender Python newbie script

Hi,

I’ve some newbie questions relating the Blender python API. I tried the example script (polygon.py) from the docs and like to start with the Blender python API.

My first example is how to create the same polygons, but with the same effect as if I create the poly and then select all meshes and extrude (region) the object to give it a volume. So my question is how to do it. Should I simply paint a second poly a little beside and then connect all the faces or could I use the extrude function from inside the python API?

regards
Andreas

Ok, I got it to work. I created a new poly and then connected all faces in a new loop. Was easier as I thought before. I think I’ll spend some time for learning the blender API… :wink:

regards
Andreas

Hi,

The next problem I’ve with blender python is that I need to copy a object (like shift-D). I tried to create a new object and copy data or properties and lot of stuff, but nothing worked. I read in another thread about deepcopy(), but this doesn’t work too. I wonder why there’s no easy copy_object() function. Could you help me?

regards
Andreas

because copy is a lot simpler than that.
I remeber when i first learned the blender python api. What stopped me for a long time is the way class work. For NMesh stuff for example, assuming you are working on a mesh object, you can do getraw, then putraw under a different name. Because GetRaw is doing a copy of the mesh data to work on it. Working on a Object is different, if you do Object.Get, what you will get is a kinda pointer to the data in memory, mean if you do mesh = Object.Get(“cube”), mesh2 = mesh, mesh2 will be the same thing as mesh, mean two way to acces the same object. Anyway Objects are only container, what really matter is the data linked to it. You could do a alt-d kindof duplication(linked) by creating a new object with Object.New but use the shareFrom to link to another object’s data.

This is a simple way of doing a copy of a mesh. after that you can copy the other data of the main object like property, location or rotation:

import Blender
from Blender import *

mesh = NMesh.GetRaw("Cube")

NMesh.PutRaw(mesh,"cube2")

Great, this worked. But I had to use GetRawFromObject() to make a copy.

Is the new NMesh.PutRaw(mesh,“cube2”) also an object or should I create an object after doing this?

I’m playing with a generator for objects I often use. One way I try is to model a template object and then let a script with GUI copy it, do some rotating, coloring, and such stuff.

Another way I try is to create the objects complete within python, because this is more flexible.

My today learning example was to create a cube (and a plane) with a hole in it with python API. This is really easy with python. I needed only some loops for generating the vertexes and faces. Here is the result:

http://brachttal.net/blender/tmp/cube_with_hole.jpg

My next try is to cut a hole, like on the image, in a yet existing cube or plane. But it seems to be harder than I thought. If I create all vertexes in python I “know” which vertexes I should face together to get a hole (because I have the loop index). In a yet existing cube (or plane) I didn’t know this. Perhaps it’s an idea to look which vertexes are connected to a face, analyse the x/y/z position of its vertexes, delete the faces I don’t need longer and then insert the new vertexes for the hole and insert the new faces for the hole. Could this work? Would you do it another way?