0
$\begingroup$

i'm using blender via it's python API and encounter the following strange behavior.

I produced the following Blend file with my code :

Now i want to do some modifications on those objects as follows :

if modify:
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.join()

    bpy.ops.object.mode_set(mode="EDIT")


    for i in range(insets):
        bpy.ops.mesh.inset()

    bpy.ops.mesh.select_all(action="SELECT")
    bpy.ops.mesh.remove_doubles()

    bpy.ops.mesh.subdivide(number_cuts=subdivides)

    bpy.ops.mesh.separate(type="MATERIAL")

Summary of the code above : Join the objects, perform 4 insets, perform a subdivide with 4 cuts, seperate the object by material.

This works as expected.

Now to the curcial part:

I want to export this into a custom file format. To do so i iterate over the bpy.context.scene.objects (which are 3, as expected) over every face. Here it occurs that the object "SI_O2" (bpy.context.scene.objects[2].data.polygons) has only 50 faces which, compared to the number displayed in "Edit Mode" within Blender (12.325 faces) is far off.

Why does this happen ?

I found a way to get the correct face count:

Delete the other 2 Objects in the GUI.

EDIT:

Deleting the first two ".001" and ".002" objects via

bpy.ops.object.select_pattern(pattern=obj.name)
bpy.ops.object.delete(use_global=False)

lets blender crash with a SegmentationFault

EDIT2:

doing a

bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.select_all(action="DESELECT")

the above (under EDIT) works without the SegmentationFault.

Nonetheless this procedure does not appear to be the intended Behavior of the .polygons attribute.

...

But this can't be the ideal/correct solution to achieve this.

Any help on this is very appreciated.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.