1
$\begingroup$

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!

$\endgroup$
2
  • $\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$ Commented Jul 11, 2017 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$ Commented Jul 12, 2017 at 11:18

1 Answer 1

2
$\begingroup$

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

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.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.