1
$\begingroup$

I am a newbie with Python scripting in Blender. Lately, I have been browsing the Blender API documentation to figure out how to incorporate certain features into my scripts for Python. However, I am confused because I feel as though the documentation fails to provide the examples necessary to understand how the methods provided in the library would actually be used in a script.

For example, I am interested in (as part of a "poll" function in an operator) determining whether a object has been modified. I found the method bpy.types.Object.is_modified. Unfortunately, I can't make heads or tails of the information provided, as I know I can't just type in bpy.types.Object.is_modified to determine whether an object has been modified. It throws an exception in the Python console, even when I type in "scene" and "settings" for the parameters for the function (the parameters are listed as "scene" and "settings" in the library's function definition). I have tried leaving in "Object" in the command, and have also tried replacing "Object" with either the name of the object or a variable being used to represent the object. Similarly, I am not really sure how any methods in bpy.types.Object are normally called, because, although I do not really know, I get the impression that they are normally called using prefixes other than "bpy.types". Can someone please help me?

EDIT: Here is a picture showing what I have tried and the exceptions that I have received: enter image description here

$\endgroup$
1
  • $\begingroup$ what is the error? $\endgroup$
    – krypticbit
    Jul 20, 2016 at 19:01

1 Answer 1

0
$\begingroup$

Take a closer look at the syntax the command needs.

bpy.types.Object is just the general class. In basic programming terms, bpy.types.Object is only a blueprint for what an object should be. You want the instance, or copy, of the class that refers specifically to 'Plane' . In your case, this would be: bpy.types.Object(bpy.data.objects['Plane'])

Secondly, look again at the API for is_modified(). When it says (scene, settings) it doesn't mean those literal words.

  • scene refers to the actual class of your scene. You want bpy.data.scenes['Scene'] (or whatever name is shown in the outliner)
  • settings has two options already determined for you. In the API, it says "(enum in ['PREVIEW', 'RENDER'])," meaning either of those words is what goes in the settings place. PREVIEW checks the object's modifier settings for preview mode, and RENDER checks settings for render mode (what appears when you press SHIFT + Z)

So, to do it right:

import bpy
scene = bpy.data.scenes['Scene']
plane = bpy.data.objects['Plane']

Then:

bpy.types.Object(plane).is_modified(scene, 'PREVIEW')  OR
bpy.types.Object(plane).is_modified(scene, 'RENDER')
$\endgroup$
1
  • 1
    $\begingroup$ what about plain old plane.is_modified(scene, 'PREVIEW') All objects in the bpy.data.objects collection will be instances of type bpy.types.Object $\endgroup$
    – batFINGER
    Jul 21, 2016 at 18:48

You must log in to answer this question.

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