Set Offset From Cursor operator crashes from Search Menu
Open, Needs TriagePublic


System Information
Win 7 64 bit

Blender Version
Tested on: 2.78, 2.77, 2.76

Short description of error
Since the commit rB1923a5c13459 the DupliOffsetFromCursor operator (object.dupli_offset_from_cursor) would crash if called from the Search Menu.

    group =
AttributeError: 'Context' object has no attribute 'group'

Exact steps for others to reproduce the error
Open the default scene> bring up the search menu > search for Set Offset From Cursor.

A proposed workaround (probably it could be done better):
in (scripts\startup\bl_operators\ around line 860)

class DupliOffsetFromCursor(Operator):
    """Set offset used for DupliGroup based on cursor position"""
    bl_idname = "object.dupli_offset_from_cursor"
    bl_label = "Set Offset From Cursor"
    bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}

    def poll(cls, context):
        return (context.active_object is not None)

    def execute(self, context):
        scene = context.scene
        # prevent crashing if called from Repeat History
        group = getattr(context, "group", None)

        if not group:
            message = ("Works only from Properties" if
                       context.area.type not in "PROPERTIES" else
                       "No DupliGroups found")
  {'INFO'}, message)
            return {'CANCELLED'}

        group.dupli_offset = scene.cursor_location

        return {'FINISHED'}

Setting the operator to INTERNAL (and thus removing it from the search) is not enough as it'll still crash if redone from Repeat History.
Unsure about the message.

EDIT: edited the code a bit to provide a better message, removed the else.



The simpler way is to just modify the poll:

def poll(cls, context):
    return (context.active_object is not None and
            context.area.type in "PROPERTIES")

That doesn't give any feedback when accessed through redo history.

Add Comment