Traceback (most recent call last):
File “\Text.001”, line 3, in <module>
File “C:\Program Files\Blender Foundation\Blender\2.79\scripts\modules\bpy\ops.py”, line 189, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.snap_cursor_to_selected.poll() failed, context is incorrect
Error: Python script fail, look in the console for now…
yeah, I know what’s up. I hate it when it does that. It’s a viewport context issue. To run a “bpy.ops.view3d” operator, you have to be in the 3D viewport. You can make it into a operator and run from 3D viewport or you can fake it out(make it think it’s running in 3D viewport from text editor).
@AWFS : thanks that works. @MartinZ: Usually I used Shift-S and Shift-Ctrl-Alt-C to get this all done. If I use the pies I need both the origin pie and the cursor pie.
With script below I have to click once; (Or twice then to get out of the full-screen mode).
import bpy
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == ‘VIEW_3D’:
override = {‘window’: window, ‘screen’: screen, ‘area’: area}
bpy.ops.screen.screen_full_area(override)
break
bpy.ops.view3d.snap_cursor_to_selected()
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type=‘ORIGIN_CURSOR’)
bpy.ops.view3d.snap_cursor_to_center()
bpy.ops.view3d.snap_selected_to_cursor(use_offset= False)
I should make a button somewhere, but that’s above my head at the moment. (First little script).
@AWFS:
Ahw, that’s great.
After the line: bpy.context.scene.cursor_location = (cursor_location_x, cursor_location_y, cursor_location_z)
I added: bpy.ops.object.mode_set(mode=‘OBJECT’)
So what I have to do:
Go in Edit-Mode > Select a vertec > Press spacebar: type Vertex to find: Origin to vertex
And it wil end up with:
- the Origin placed on the vertex of your choice
- being in Object mode
- Centered (on Grid)
Already very happy with it. Works great before saving assets and transform like scale.
just remove the line above it that keeps it in edit mode. Don’t have to add another line to switch to back object mode. You can remove the cursor code to if you want. That just keeps it in the current location.