Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I am trying to set a cursor location and pivot point with

bpy.types.SpaceView3D.pivot_point='CURSOR'
bpy.types.SpaceView3D.cursor_location = (0.0, 0.0, 0.0)

and I see I am not doing it right. How to do it correctly?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

See Adhi's answer here as to why this won't work the way you are doing it.

Using Context

It's easier to read 3D View space's settings through bpy.context, e.g.:

  • Use bpy.context.space_data, if the 3D View area is active (i.e. accessed through an operator executed from the 3D View itself).
  • Use bpy.context.area.spaces[1], if accessed through a Console whose display type is directly switched from a 3D View.
  • Use bpy.context.screen.areas[X].spaces[0] if accessed through a Console in another area, index X must be searched beforehand.

What you want to use is

bpy.context.area.spaces[1].pivot_point='CURSOR'
bpy.context.area.spaces[1].cursor_location = (0.0, 0.0, 0.0)

For the cursor location, there is a shorter alternative. All 3D View's cursor location is linked to the scene's, so it can also be accessed from bpy.context.scene:

bpy.context.scene.cursor_location = (0.0, 0.0, 0.0)
share|improve this answer
    
what worked for me was your third example –  dimus Dec 8 '13 at 0:10
    
@dimus Do you mean that the others don't work or that way is better? –  iKlsR Dec 8 '13 at 0:23
    
I ran it from text editor, and the third example worked -- I added a 'comment-answer' with the code: blender.stackexchange.com/a/5361/1311 –  dimus Dec 8 '13 at 0:31
add comment

Here is a snippet of the code (forgive my bad python) which I ended up using after reading the answer

import bpy

def areas_tuple():
    res = {}                                                               
    count = 0
    for area in bpy.context.screen.areas:                                  
        res[area.type] = count                                             
        count += 1
    return res  

areas = areas_tuple()
view3d = bpy.context.screen.areas[areas['VIEW_3D']].spaces[0]
view3d.pivot_point='CURSOR'
view3d.cursor_location = (0.0, 0.0, 0.0)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.