1
$\begingroup$

I'm currently writing a small script to help ease exporting objects made in Blender to the Unreal Engine, and one of the things I need to do is scale all mesh objects by 100 about the origin (0,0,0).

Although I have working code, the way I'm doing it seems a bit obtuse and I was wondering if there is a more direct way to do it. This is the code I have:

for ob in context.scene.objects:
  if ob.type == 'MESH':
    ob.scale *= 100
    ob.location *= 100
    ob.select = True
    scn.objects.active = ob
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
    ob.select = False

Because of the selection stuff, in order not to lose the user's selection, I also have a bunch of code to save and restore the selected and active objects, which I'd rather not have. I am also not 100% sure if the scaling code is working flawlessly or not. It seems OK, but there is also bpy.ops.transform.resize, which might be more reliable, but then I need a bunch more code in order to set the 3d cursor position to 0,0,0. Is there a simple function along the lines of ob.set_scale(value=(100,100,100), pivot=(0,0,0), apply_transform=True)?

$\endgroup$
1
  • $\begingroup$ Look to see if importer / exporter has a scale property setting. $\endgroup$
    – batFINGER
    Mar 20, 2019 at 3:23

1 Answer 1

1
$\begingroup$

No solution, but a hint (cannot comment):

Your code runs the danger of scaling parented objects more than once. You could filter/only scale objects with no parent (root scene objects)...like so:

root_objects = []
for obj in context.scene.objects:
    if not obj.parent:
        root_objects.append(obj)

for obj in root_objects:
    ...
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .