I have several pieces of geometry, seemingly imported from some parametric modelling tool. They all have an ".ipt" in their object name. My original goal was to write a script that goes through all the objects in the scene, gets the object's dimensions, counts the number of vertices in a an object, compares it to the same parameters in the active object, and replaces object data if it finds a match. To that end I wrote the following:

from bpy import context

scene = bpy.context.scene

actob = bpy.context.selected_objects[0]
actobdat = bpy.context.selected_objects[0].data
ob = bpy.context.object
dimact = actob.dimensions
conapp = 0.007
actobvert = len(actobdat.vertices)

for ob in scene.objects:

    dimob = ob.dimensions
    obvert = len(ob.data.vertices)

    if abs(dimact[1] - dimob[1]) < conapp and abs(dimact[2] - dimob[2]) < conapp and abs(dimact[0] - dimob[0]) < conapp and actobvert == obvert:

        ob.select = True
        ob.data = actobdat

In response to this I received the following error message: AttributeError: 'NoneType' object has no attribute 'vertices'

I did some searching online, but still failed to solve the issue. Any help would be greatly appreciated! Thank you!

  • $\begingroup$ What objects do you have in your scene? And are you using actob = bpy.context.selected_objects[0] to get the active object? $\endgroup$ Jul 11 '17 at 17:58
  • $\begingroup$ I have several identical (but not instance) meshes, that were imported from some parametrical modelling tool. The whole thing is a test for an ocasion when I will need to dig through a very large number of meshes, discern, which of them can use the same mesh data and apply said data to them. To answer your second point - yes, this is why I have this line here. Is that a wrong\inefficient method of doing so? Thank you! $\endgroup$
    – Nick Kaur
    Jul 12 '17 at 11:18

It says 'NoneType' object has no attribute 'vertices', so it can be an empty that is being selected. You must check that the objects are meshes:

actob = bpy.context.active_object
if actob.type == 'MESH':
    actobdat = actob.data
    dimact = actob.dimensions
    for ob in scene.objects:
        if ob.type == 'MESH':
            dimob = ob.dimensions

You use bpy.context.active_object to get the active object, the index 0 of selected_objects will give you the last object added to the scene within the selection.

  • 1
    $\begingroup$ I would flip that condition, and do if actop.type ! = 'MESH': continue. That prevents yet another level of indentation. $\endgroup$
    – dr. Sybren
    Jul 15 '17 at 6:52

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.