TransWikia.com

In Blender 2.80, how to set a custom transform orientation programmatically?

Blender Asked by egtwobits on August 30, 2020

Transform orientations in Blender 2.80 are marked as read-only. What is the proper way to provide a custom matrix as a transform orientation in 2.80?

It looks like this call is needed to create a new orientation, which has a .matrix attribute which is NOT read only. Is this the intended usage? The user interface and docs for this don’t make it clear.

One Answer

Here's a working solution/snippet, with a description below:

        orthonormal_basis_matrix = mathutils.Matrix(
            [
                [vcross[0], vnorm[0], vdest[0]],
                [vcross[1], vnorm[1], vdest[1]],
                [vcross[2], vnorm[2], vdest[2]]
            ]
        )
        bpy.ops.transform.create_orientation(
            name='MAPlus',
            use=active_item.apl_use_custom_orientation,
            overwrite=True
        )
        orient_slot = [
            slot for slot in
            bpy.context.scene.transform_orientation_slots
            if slot.custom_orientation
               and slot.custom_orientation.name == 'MAPlus'
        ]
        if orient_slot:
            orient_slot[0].custom_orientation.matrix = orthonormal_basis_matrix
        else:
            print('Error: Could not find MAPlus transform orientation...')
  • Call create_transformation to add a named transformation
  • Use a list comprehension to search through the available bpy.context.scene.transform_orientation_slots for a slot having a custom_orientation (TransformOrientation object) with the name you provided
  • Test whether the list comprehension/search came up with any results, then use the discovered object and set its matrix

Answered by egtwobits on August 30, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP