2
$\begingroup$

I made a script that creates a circle, deselects all vertices in edit mode, selects first 5 vertices and then scales those vertices. I expected those vertices to be scaled with 3D cursor which sits in the middle of the circle, but instead the vertices are scaled with their median point.

I was experimenting with bpy.ops.transform.transform() function too, but to no avail.

import bpy

bpy.ops.mesh.primitive_circle_add(vertices=35, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
obj = bpy.context.active_object
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.editmode_toggle()
obj.data.vertices[0].select = True
obj.data.vertices[1].select = True
obj.data.vertices[2].select = True
obj.data.vertices[3].select = True
obj.data.vertices[4].select = True
bpy.ops.object.editmode_toggle()
bpy.ops.transform.resize(value=(0.5, 0.5, 0.5),orient_type='CURSOR')

Script result:

enter image description here

Expected result:

enter image description here

$\endgroup$
4
$\begingroup$

Halve the coordinates.

Prob not an answer to question as asked, more so another approach without operators, mode switching or cursors.to produce the result.

Since the circle has origin at (0, 0, 0) then each verts coordinate is also the radial vector.

Simply halve vertex coordinate over the desired index range.

Test script.

import bpy

bpy.ops.mesh.primitive_circle_add(vertices=35, location=(0, 0, 0))
obj = bpy.context.active_object
me = obj.data
for i in range(5):
    me.vertices[i].co /= 2
$\endgroup$
1
  • $\begingroup$ Yeah that works. I have to pick up again school math. $\endgroup$ Jul 30 at 19:24
0
$\begingroup$

This is not a direct anser just typical knowledge from vector maths in game engines

usually you have to subtract origin from position so you localize the position vector then perform any transforms on the vectors and then re-add the origin

so,

x = position - origin
x += scalar
x += origin

in your case the line bpy.ops.transform.resize(value=(0.5, 0.5, 0.5),orient_type='CURSOR')

the value 0.5 looks to be half the original position while 1.0 should show no visual change and 1.5 and so on should be greater

edit: no that 0.5 is in Blender units space not a scalar

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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