pivot point to CURSOR

Dear All,

I’m having some problems to set the pivot point to… anything.
I tried googling around, and all I find is this:

bpy.context.space_data.pivot_point = ‘CURSOR’

…but it returns me “AttributeError: ‘SpaceTextEditor’ objext has no attribute ‘pivot_point’”.

currently I’m trying to manage everything with boring and annoying rotation on the 3D cursor done mathematically, but I realize I cannot live with that, or I’ll have too messy scripts.

What am I doing wrong? I tried to change the context (to EDIT mode, OBJECT etc), but it really doesn’t seem to work. How should I do?

Thank you in advance!

Try this, worked for me:


import bpy

def set_pivot_point(type):
    
    if type not in ('BOUNDING_BOX_CENTER', 'CURSOR', 'INDIVIDUAL_ORIGINS',
                    'MEDIAN_POINT', 'ACTIVE_ELEMENT'):
        return False
    
    for a in bpy.context.screen.areas:
        if a.type == 'VIEW_3D':
            break
    else:
        return False
    
    a.spaces[0].pivot_point = type
    return True
        
set_pivot_point('CURSOR')

Thank you CoDEmanX!!!

Indeed, it worked for what concerns the switching to the desired pivot point.
I didn’t think that it would have been so complicated, I thought the identification of the Area (to find the one with type “VIEW_3D”) by iterating all the possible ones wasn’t a duty of the scripter.

Anyway, even if the pivot point is correctly set to CURSOR (and I can confirm it watching Blender’s GUI), all the transformations (in the script) performed afterwards behave like using MEDIAN POINT…

Is there a reason for it? Isn’t it enough to set the pivot to 3D CURSOR to have the expected behaviour?

Thanks again!

dunno… what functions do you use to do changes? might they have a parameter for pivot / location?

I just use this to scale 4 vertices, instead of using their median point, I want to scale with respect to the 3D cursor:



...
bpy.ops.object.mode_set(mode='EDIT')

set_pivot_point('CURSOR') #THIS IS YOUR FUNCTION!
bpy.ops.transform.resize(value=(0.9,0.9,0.9), proportional='ENABLED', proportional_edit_falloff='SHARP', proportional_size=1.0)

bpy.ops.object.mode_set(mode='OBJECT')
...

Am I doing it right?

looks right

dunno, but maybe you need to update scene / object to make the pivot work?

bpy.context.scene.update()

Unlikely but worth a try:
bpy.context.object.data.update()

to be called before the resize operator

sunseeker make sense!
On GUI works as well, but on python scripting not. This sounds like a bug… you agree? or not
=/
I’ve trying to change the origin of the object to 3D cursor, then the origin and the pivot point change. So I make the rotation and almost work as well. Unfortunately my obj is rotating two times…one around its own axis and the other around the 3D cursor, without counting the high computational cost.

Follows the code:


def recalculateHandCoordinates(self, r_hand=False, l_hand=False):
	if r_hand:
		bpy.data.objects['r_hand'].select = 1
	if l_hand:
		bpy.data.objects['l_hand'].select = 1
	bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
	bpy.ops.transform.rotate(value=(radians(self._sumAngleRotationZ),), axis=(0,0,1))
	bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
	bpy.ops.object.select_all(action='DESELECT')

Any idea?

Thanks in advance

I tested the update scene method (CoDEmanX tip). But doesn’t worked…

bpy.context.scene.update()

Guys,

I found a kind of solution.
I created an object and then I put it in the center of scene (0,0,0). After I set parent between my object (would like rotate) obj in the center.
So when I rotate the object from the center also will rotate my object (around x,y,z arbitrary).

Follows a figure.

Bye