[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4341] contrib/py/scripts/addons/ object_booleans.py: --- Boolean Operators v0.4 ---

Peter D. Cassetta peter at fingertipsoft.com
Wed Mar 6 01:58:21 CET 2013


Hi Jonathan,

Just wanted to say that due to not-too-recent API changes, context is 
restricted for add-ons during activation.
So on activation your add-on will not actually be enabled, and will 
instead print the following error:

Traceback (most recent call last):
   File "/usr/lib/blender/2.66/scripts/modules/addon_utils.py", line 269, in enable
     mod = __import__(module_name)
   File "/usr/lib/blender/2.66/scripts/addons_contrib/object_booleans.py", line 15, in <module>
     scene = bpy.context.scene
AttributeError: '_RestrictContext' object has no attribute 'scene'


This line in your add-on is what causes the error:

scene = bpy.context.scene

The error occurs because scene is not a part of this restricted context.
Note that you can access bpy.context as normally inside functions and 
such, just not during activation.

Anyway, sorry if this error's been reported already, but maybe this will 
help you get an idea of what's going wrong, and how to fix it.
If you need help, I'd recommend asking on #blendercoders or e-mailing 
the bf-python at blender.org mailing list.

-Peter Cassetta

On 03/05/2013 02:18 AM, Jonathan Williamson wrote:
> Revision: 4341
>            http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4341
> Author:   carter24
> Date:     2013-03-04 18:18:46 +0000 (Mon, 04 Mar 2013)
> Log Message:
> -----------
> --- Boolean Operators v0.4 ---
>
> Committing changes as suggested by Campbell, thanks!
>
> - Cleaned up the Boolean Operator, removing unnecessary code.
> - Declared bpy.context.scene as a variable for cleaner code in the boolean class.
> - Added Tracker and Wiki URL.
>
> Modified Paths:
> --------------
>      contrib/py/scripts/addons/object_booleans.py
>
> Modified: contrib/py/scripts/addons/object_booleans.py
> ===================================================================
> --- contrib/py/scripts/addons/object_booleans.py	2013-03-04 17:40:29 UTC (rev 4340)
> +++ contrib/py/scripts/addons/object_booleans.py	2013-03-04 18:18:46 UTC (rev 4341)
> @@ -1,17 +1,19 @@
>   bl_info = {
>       "name": "Boolean Operators",
>       "location": "View3D > Toolbar",
> -    "description": "Add Boolean Operators",
> +    "description": "Add Boolean Tools for running boolean operations on two selected objects.",
>       "author": "Jonathan Williamson",
> -    "version": (0,3),
> +    "version": (0,4),
>       "blender": (2, 6, 6),
> +    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/booleanoperators",
> +    "tracker_url": "http://projects.blender.org/tracker/index.php?func=detail&aid=34502&group_id=153&atid=467",
>       "category": "3D View",
>       }
>   
>   import bpy
>   
> +scene = bpy.context.scene
>   
> -
>   ###------ Create Boolean Operators -------###
>      
>   class boolean(bpy.types.Operator):
> @@ -33,24 +35,23 @@
>               if len(selected) > 1:
>                   if len(selected) == 2:
>                       for ob in selected:
> -                        if ob != bpy.context.active_object:
> +                        if ob != activeObj:
>                               nonActive = ob
>       
>                       bpy.ops.object.modifier_add(type="BOOLEAN")
> -                    activeMod = bpy.context.active_object.modifiers
>                       
>                       for mod in activeObj.modifiers:
>                           if mod.type == 'BOOLEAN':
> -                            activeMod[mod.name].operation = self.modOp
> -                            activeMod[mod.name].object = nonActive
> -                            activeMod[mod.name].name = modName
> +                            mod.operation = self.modOp
> +                            mod.object = nonActive
> +                            mod.name = modName
>                       
>                       bpy.ops.object.modifier_apply(apply_as='DATA', modifier=modName)
> -                    bpy.context.scene.objects.active = nonActive
> +                    scene.objects.active = nonActive
>                       activeObj.select = False
>                       bpy.ops.object.delete(use_global=False)
>                       activeObj.select = True
> -                    bpy.context.scene.objects.active = activeObj
> +                    scene.objects.active = activeObj
>                   else:
>                       self.report({'INFO'}, "Select only 2 objects at a time")
>               else:
> @@ -123,7 +124,6 @@
>       kmi = km.keymap_items.new('wm.call_menu', 'B', 'PRESS', ctrl=True, shift=True)
>       kmi.properties.name = 'object.boolean_menu'
>   
> -
>       addon_keymaps.append(km)
>       
>   def unregister():
>
>



More information about the Bf-extensions-cvs mailing list