1
$\begingroup$

I am new to scripting in Blender and I have a set of commands that work to create my object when pasted into the command line, but not when run as a script. The first major issue I've run into is that the dimensions and location change on a selected object, but the scale does not. How can I resolve this?

import bpy
import bmesh
from bpy_extras.object_utils import AddObjectHelper
from bpy import context

bpy.ops.mesh.primitive_cube_add(size=16, enter_editmode=False, align='WORLD', location=(0, 0, 0))

bpy.context.view_layer.objects.active = bpy.data.objects['6']

bpy.context.object.location[0] = 0
bpy.context.object.location[1] = 0
bpy.context.object.location[2] = 8.6
bpy.context.object.scale[0] = 1250
bpy.context.object.scale[1] = 1250
bpy.context.object.dimensions[2] = 2

The dimensions and location change when I run this, but the scale does not. I appreciate all your help and insights. Thanks very much!

$\endgroup$
0
$\begingroup$

You should apply dimensions first and then scale it. Since set dimension kind of reset the scale to make it work in calculation.

import bpy
import bmesh
from bpy_extras.object_utils import AddObjectHelper
from bpy import context

bpy.ops.mesh.primitive_cube_add(size=16, enter_editmode=False, align='WORLD', location=(0, 0, 0))
# select the last created object
bpy.context.view_layer.objects.active = bpy.data.objects[-1]

bpy.context.object.location.xy = 0.0, 0.0
bpy.context.object.location.z = 8.6

bpy.context.object.dimensions.z = 2.0
bpy.context.object.scale.xy = 1250, 1250

| improve this answer | |
$\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.