I started using Blender two weeks ago for my construction project which was imported using 3ds format. I has about four hundred different objects and definitely I used to start using python to work with it. I already have written few scripts to remove hidden faces, doubles and so on and everything looks nice and works fine. But going deeper in python coding for blender I have some questions which I guess are now well explained yet or I didn’t find them yet. So would you please advise on the following:
Why objects have different indexes in bpy.context.scene.objects vs bpy.data.objects?
What is the difference between bpy.context.scene.objects and bpy.context.active_object and what is better to use? What limitations does each link has?
If i need to use nodes for every mesh in my model is it possible to prepare draft node trees and just apply them changing links to materials, textures and etc.
I wrote a script to remove faces depending on materials applied on them and that allows me to remove building frame, housewraps but roof and walls objects still consist interior faces as backsides of siding/drywall volumes which doubles use baking image areas (removing hidden wall faces significantly improves baking resolution but I would like to have no hidden faces at all)?
bpy.data.objects contains references to the objects in the .blend file, bpy.context.scene.objects contains references to the objects linked to the scene. There can be multiple scenes in a blend file, and any object may or may not be linked to any of them.
Don’t rely on indices for referencing objects (or meshes, materials), use the name instead. Don’t store Python object references either, those will be invalid after UNDO/REDO. Always use the name for tracking data. Also, you can’t really track renames reliably, so be careful with that. In effect, there’s no way (that I’m aware of) to properly track references with the Python API.
bpy.context.active_object is a reference to the active object, i.e. the one that has been selected last. As mentioned, bpy.context.scene.objects contains references to objects in the scene. Whether either is “better to use” depends entirely on what you want to do.
You can create a “template” Material and copy it, then change its references.
This sentence is incomprehensible to me, but the question probably goes too far for me to answer, anyway.
Regarding removing of inner geometry I thing the logic could be:
Put all lightings
Considering that biggest texture areas usually used by walls/roof plains/floor, if it will be possible to choose polygons of these objects depending on illumination they receive from lightings that could work
So if it is possible to find baking data for each plain I will just remove all which are less lightened
Hello, the screen copy is attached. As you could see, right side of the wall has the parallel sides and the inner one takes baking area which I would like to use (second option is just to forget it and make bigger textures but tomorrow another same task could appear so I want to solve it). There could be many of such kind of objects (all walls, roof plains and floors) and for inner geometry which has clear building frame or underlayment materials I already removed them. Another option I guess could be combined of:
Determine plains paralleled to general mesh biggest areas
From those determine all plains which have same materials but closer to center of mesh mass
might be easier to understand it if you could upload a small sample file with this problem
then we can analyse it with you and see if there are any means or tools to help do that !