1
$\begingroup$

I want to pull data from a bpy.ops command, something like

for x in bpy.data.objects:
    if x.name in bpy.context.view_layer.objects.keys():
        bpy.context.view_layer.objects.active = x
        bpy.ops.mesh.select_non_manifold((extend=True, use_wire=True, use_boundary=True)

and follow it up with commands like

a = bpy.data.objects['obj'].data.total_edge_sel

to grab non-manifold edge data (other other data gatherable if the model were in edit mode) without throwing the model into edit mode. Currently I'm getting out of context errors (the model is in Object Mode. I understand why the error, but...)

Is something like this it possible without flashing 200+ mesh objects into edit mode to get the data?

EDIT: Thanks for the info batFINGER, the report is starting to take shape!

'Model Name: 00000000DE66'
'Model Armature: 00000000DE66_Skeleton'
'Armature Bone Count: 377'
'Number of Bones Without Vertex Groups: 28'
'Armature Scene Rotation Mode: XYZ'
'Armature Rotation: (90.0, 0.0, 0.0)'
'Number of Bones Layers: 1'
'Number of Mesh Objects in Model: 9'
'Number of Vertices in Model: [10188, 178, 264, 1598, 226, 92, 1740, 396, 226]'
'Number of Vertex Groups in Model: 349'
"Number of Vertex Groups That Don't have Bones: None"
'Number of Vertices Influenced By More Than 3 Bones: 1175'
'Number of Vertices Not Weight Painted: 0'
'Number of Materials: 8'


'Model Name: Sesshomaru'
'Model Armature: Sesshomaru_arm'
'Armature Bone Count: 204'
'Number of Bones Without Vertex Groups: 44'
'Armature Scene Rotation Mode: XYZ'
'Armature Rotation: (0.0, 0.0, 0.0)'
'Number of Bones Layers: 3'
'Number of Mesh Objects in Model: 1'
'Number of Vertices in Model: [9599]'
'Number of Vertex Groups in Model: 162'
"Number of Vertex Groups That Don't have Bones: 2"
'Number of Vertices Influenced By More Than 3 Bones: 2905'
'Number of Vertices Not Weight Painted: 0'
'Number of Materials: 30'
```
$\endgroup$
1
$\begingroup$

Edit multiple objects.

AFAIK it is impossible to use bpy.ops.mesh outside of edit mode. It would be possible to emulate the select non manifold operator in object mode, however since all objects can be placed into edit mode at once, and the operator called once, it feels unnecessary to bother

enter image description here

As of blender 2.8 it is possible to edit a number of mesh objects at once. So instead of "flashing" each object, select all the objects to edit, call the operator once, then output the meshes total_edge_sel count, or update all edit meshes by either toggling out of edit mode or calling Object.update_from_editmode() and read the selected edges, and count the edges selected, to get both the total and which edges are selected.

import bpy

context = bpy.context
scene = context.scene

# select and put all in edit mode
for o in scene.objects:
    o.select_set(o.type == 'MESH')
# make sure active object is included
context.view_layer.objects.active = context.selected_objects[0] 
context.tool_settings.mesh_select_mode = (True, True, True)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_non_manifold()

for o in context.objects_in_mode_unique_data:
    print(o.name, o.data.name, o.data.total_edge_sel)

Test run on 4 objects in image, two cubes, a plane and suzanne.

Cube Cube 0
Plane Plane 4
Suzanne Suzanne 42

Note the second cube shares same mesh as first (linked data), hence only one with unique data shown.

$\endgroup$
4
  • $\begingroup$ As this is my first real attempt at actually writing something useful, I was hoping there was a way or a mode that would emulate bpy.ops.mesh outside edit mode that I haven't discovered yet, But if this type of data has to be pulled that way, then so be it. I can do this and populate the dictionary just before I start writing the report. I knew all objects could be selected at once, but forgot about that, so the process would only have to be run once and the flashes will be quick so it will give people who use this a quick show... lol. Thanks for confirming what I suspected, batFINGER. $\endgroup$
    – PteJack
    Apr 10 at 17:07
  • $\begingroup$ Also, I did see these in the list of methods, (.objects_in_mode_unique_data: and .update_from_editmode) but wasn't sure how to employ them, so again thanks for the demonstration. $\endgroup$
    – PteJack
    Apr 10 at 17:15
  • $\begingroup$ NP. This one blender.stackexchange.com/a/128263/15543 is an example of using bmesh to make convex hulls of all selected meshes in object mode. Whereas bpy.ops.mesh.convex_hull is an edit mode operator. But for this case would involve making 200 bmeshes and testing for non manifold edges is probably not going to be quicker than above. $\endgroup$
    – batFINGER
    Apr 10 at 17:23
  • $\begingroup$ Thanks batFinger, I saw that before asking this question. But I still don't fully understand BMesh yet and I don't think I even have it enabled, so I'm staying away from that for now. But, thanks to your help here, see my edited question above. (Not sure if edit the question is the correct protocol for this forum though - lol) $\endgroup$
    – PteJack
    Apr 10 at 19:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.