AnswerBun.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!

Related Questions

Blender instantly closes on startup

1  Asked on November 13, 2021 by throndronis

 

textured filling circle

1  Asked on November 13, 2021 by jinjin

 

Wobbly gear ring needs fixing

2  Asked on November 10, 2021 by dino808

 

Show/hide mantaflow particles

1  Asked on November 10, 2021 by nate_sycro27

   

Blender crashes in Manjaro Linux version

2  Asked on November 10, 2021 by gregthehun

   

What costs so much perfomance in my scene?

0  Asked on November 10, 2021 by croomar

     

Coffee Texture as not Expected

0  Asked on November 10, 2021 by anindya-bhunia

       

Deform a hole on a torus

3  Asked on November 10, 2021 by geomessence

         

How to save materials to image Blender

1  Asked on November 10, 2021 by kye

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir