make bpy.ops.mesh.spin operator scriptable #45410

Closed
opened 2015-07-11 14:16:32 +02:00 by Hasan Yavuz Özderya · 6 comments

Broken: 2.75 c6b042b

When called from a script file or python console, bpy.ops.mesh.spin operator fails:

Traceback (most recent call last):
  File "/test.py", line 7, in <module>
  File "/usr/share/blender/2.75/scripts/modules/bpy/ops.py", line 189, in __call__
    ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.mesh.spin.poll() failed, context is incorrect

I have investigated the code a bit. It seems that, spin operator requires active area to be 'view 3d' so that it can determine center and axis parameters. But these paremeters can be supplied from the script.

A workaround is to temporarily change the current area type to 'View 3D'. But I'm not sure if this will work in every case.

Sample script to reproduce:

import bpy

bpy.ops.mesh.primitive_plane_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.spin(steps=32, dupli=False, angle=3.14, center=(0,2,0), axis=(1,0,0))

Working sample with workaround:

import bpy

current_area_type = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'

bpy.ops.mesh.primitive_plane_add()
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.spin(steps=32, dupli=False, angle=3.14, center=(0,2,0), axis=(1,0,0))

bpy.context.area.type = current_area_type
Broken: 2.75 c6b042b When called from a script file or python console, `bpy.ops.mesh.spin` operator fails: ``` Traceback (most recent call last): File "/test.py", line 7, in <module> File "/usr/share/blender/2.75/scripts/modules/bpy/ops.py", line 189, in __call__ ret = op_call(self.idname_py(), None, kw) RuntimeError: Operator bpy.ops.mesh.spin.poll() failed, context is incorrect ``` I have investigated the code a bit. It seems that, spin operator requires active area to be 'view 3d' so that it can determine `center` and `axis` parameters. But these paremeters can be supplied from the script. A workaround is to temporarily change the current area type to 'View 3D'. But I'm not sure if this will work in every case. Sample script to reproduce: ```lang=python import bpy bpy.ops.mesh.primitive_plane_add() bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.spin(steps=32, dupli=False, angle=3.14, center=(0,2,0), axis=(1,0,0)) ``` Working sample with workaround: ```lang=python import bpy current_area_type = bpy.context.area.type bpy.context.area.type = 'VIEW_3D' bpy.ops.mesh.primitive_plane_add() bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.spin(steps=32, dupli=False, angle=3.14, center=(0,2,0), axis=(1,0,0)) bpy.context.area.type = current_area_type ```

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @hyOzd

Added subscriber: @hyOzd

Added subscribers: @ideasman42, @mont29

Added subscribers: @ideasman42, @mont29

@ideasman42 Indeed find a bit strange to use EDBM_view3d_poll() as poll for this operator, a View3D is only required when invoking it, not for mere execution…

Not quite sure what's the best way to solve this, though? Just use ED_operator_editmesh() as poll and erroring in invoke in case of missing View3D does not sound really good either… :/

@ideasman42 Indeed find a bit strange to use `EDBM_view3d_poll()` as poll for this operator, a View3D is only required when invoking it, not for mere execution… Not quite sure what's the best way to solve this, though? Just use `ED_operator_editmesh()` as poll and erroring in invoke in case of missing View3D does not sound really good either… :/
Chace Campbell was assigned by Bastien Montagne 2015-07-11 23:13:48 +02:00
Chace Campbell was unassigned by Campbell Barton 2015-07-13 12:50:28 +02:00
Campbell Barton self-assigned this 2015-07-13 12:50:28 +02:00

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Resolved blender/blender@e7b3803317
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#45410
No description provided.