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?
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')
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?
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')
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).