Need some python help

Hello everyone,

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:

  1. Why objects have different indexes in bpy.context.scene.objects vs
  2. 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?
  3. 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.
  4. 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)?

Thanks in advance.

  1. Why objects have different indexes in bpy.context.scene.objects vs

one has to do with objects list
the other one has to do with the mesh data for each object

bpy.context.scene.objects and bpy.context.active_object

first one has all the objects as a list in the scene
last one is the last selected object = active object
which can be selected or not

mat nodes ?
you can make an add node script for any material
in bl or Cycles
just add a new mat slot and add node mat to it !

now for unconnected back faces
give us a logical way to select these and then easy to get rid of
otherwise you will have to do it manually !

hope it helps
happy bl

  1. 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.

  1. 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.

  2. You can create a “template” Material and copy it, then change its references.

  3. This sentence is incomprehensible to me, but the question probably goes too far for me to answer, anyway.

Hello, Colleagues,

Regarding removing of inner geometry I thing the logic could be:

  1. Put all lightings
  2. 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
  3. So if it is possible to find baking data for each plain I will just remove all which are less lightened

Please advice

lighting is done only during rendering and not available directly with python scripting!

can you show some pics for what you mean !
might be another way to do it

how many of these do you have ?
is it necessary to do it with a script why not do it manually?

happy bl

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:

  1. Determine plains paralleled to general mesh biggest areas
  2. From those determine all plains which have same materials but closer to center of mesh mass
  3. Using local coordinates

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 !

happy bl