1
$\begingroup$

I need to select Meshes from a Scene Collection and I'm hoping that there's a better way than doing it by string matching. Here's my Scene Collection with my Meshes. The 'Vert' meshes are meshes with only 1 vert:

Scene collection

This code finds the 'Vert' meshes in a collection using startswith() for string recognition:

import bpy

print('printing objects in scene')
for obj in bpy.context.scene.objects: 
    print('obj.name is:', obj.name, 'obj is:', obj, 'obj.type is', obj.type)
    if obj.name.startswith('Vert'): 
        print('found vert:', obj.name)

I'm eventually planning to add meshes with an operator, so the names will be standardized, but this method feels sloppy. Is there a better way?

$\endgroup$
4
  • 1
    $\begingroup$ Hard to know based on info in question, is the "Vert" mesh a mesh with only one vert? $\endgroup$
    – batFINGER
    Jul 16, 2020 at 17:09
  • $\begingroup$ A bit confusing to use the term 'Vert' here as they are both meshes. $\endgroup$ Jul 16, 2020 at 17:09
  • $\begingroup$ It appears that the Vert is a mesh with only one vert. I generated them with Add>Mesh>Single Vert $\endgroup$
    – Marike
    Jul 16, 2020 at 17:17
  • $\begingroup$ IIRC from the add mesh extra objects addon?. Could you please edit this detail into question $\endgroup$
    – batFINGER
    Jul 16, 2020 at 17:27

1 Answer 1

0
$\begingroup$

By vert count

If they are still single vert meshes could also look for a single vert count.

import bpy
context = bpy.context

single_vert_obs = [o for o 
        in context.scene.objects
        if o.type == 'MESH'
        and len(o.data.vertices) == 1]
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .