I am self teaching myself how to use python with blender. I am just a bit confused as to how to manipulate objects using the bpy modules.
Is there a way to pass an object as an argument to the bpy.ops-module functions? It seems I always have to make an object active first in order to use a function of the ops module on it.
Instead, doing everything with direct references to an object, like with the bpy.data module, seems a lot more natural to me and also safer to deal with. (eg: I dont want to be dependent on whether or not an object gets selected after it’s creation to catch it in a variable)
Try to remove a modifier from an object without using the bpy.ops module only and you ll see what I mean (I hope)
You should be able to do everything without involving the .ops module. The availability of the ops is more of a convinient side effect of the recode of Blender. You can use them (and sometimes save some coding work by doing so) but as you have noticed that can have some limitations as the modifiers are dependent on the context.
If you look at all the addons you’ll notice that they all mainly use the .data and .context to manipulate objects and only occasionally use operators.
If you don’t allready know:
drop into #blenderpython on freenode to talk about blender python stuff and get help
Awesome, thanks! I just wonder why that is still. Would it not make sense to just unlink an modifier from an object by accessing it via the bpy.data module? Anyway, now that I know that I’m not blind and there actually is no way to unlink a modifier that way, I can adapt to that way…
This reminds me when I had to accept that it was not possible to unlink datablocks straight from the datablock-outliner (which would be awesome to have also!)
A good help is to look at the report view that now is exactly where in 2.49 were the preferences (I love that). You do things in blender and there it shows the code you could use for it.
Yeah but it only throws out the ops commands. Anyway, the autocomplete feature in the console is awesome too, to get a quick overview over available attribs and defs
interesting question. as far as i know this is not possible out of the box. You would have to select all the children and do the duplicating then i guess.
So in this case I would need to resort to the ops, am I right? I try to stay away from it as long as possible as you can see
I suppose I could write a definition that would recursively go through a hierarchy, duplicate elements and put them back together. But that already seems a lot more bulky and slower then going for the ops method. I just wish the ops would return objects, not a string saying that it is ‘FINISHED’.
In fact, here is what I am working on at the moment. I wrote the same script with MEL for Maya and it helped me a lot to understand MEL, so now I want to get it working with Blender. Already solved a lot of problems and got the hang of how to use the blender python api.
The script will generate a pyramide
At the moment, only a single object can be used to make a pyramid. It would be cool to have more objects form a pyramide. Also, I could not figure out how to get the bounding box so at the moment I am just working of the object’s dimensions which will get problematic when I want to get the bounding box of a bunch of objects…
My mind already crossed absurd methods that would work: Duplicate selected, combine them to a single object and then take that object’s dimensions. But that, again like with the copying of a hierarchy, feels rather not very appreciated to do.