3
$\begingroup$

I'm trying to update a script I used in 2.79 to delete all custom transform orientations (CTOs).

The new API replaced bpy.context.scene.transform_orientations with bpy.context.scene.transform_orientations_slots. The problem is, for some reason, this is returning only the active CTO, not a list of the CTOs that I created. I couldn't find a way to return a list of CTOs so I can later iterate through them and delete them.

Tried:

Researching the matter, the closest thing I could find is bpy.ops.transform.select_orientation(orientation="some_CTO_name").

However this is not useful in my case, since the argument will only accept a string enum.

Also the info window isn't helping. When I change the Transform Orientation manually, the listener is printing bpy.context.scene.type = "TO_Name". Trying to use this in the console or the script will throw an AttributeError: 'Scene' object has no attribute 'type'.

The Script:

Following is the script. If you try it, it will only delete the CTO if it's already active. My question is, how to get the list of the CTOs?

import bpy
orient = bpy.context.scene.transform_orientation_slots
views = [area.spaces.active for area in bpy.context.screen.areas if area.type == 'VIEW_3D']
areas = [area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D']

for o in orient:
    if views and areas:
        views[0] = o
        override = bpy.context.copy()
        override['area']= areas[0]
        try:
            bpy.ops.transform.delete_orientation(override)
        except:
            pass
$\endgroup$
1
$\begingroup$
orient_slot = bpy.context.scene.transform_orientation_slots[0]
custom = orient_slot.custom_orientation
custom.matrix

reference: https://blenderartists.org/t/2-80-cheat-sheet-for-updating-add-ons/1148974

$\endgroup$
  • $\begingroup$ bpy.context.scene.transform_orientation_slots[0] returns the active transform orientation, I'm looking for a way to get a list of the custom transform orientations, I don't see how your answer relates to my question. $\endgroup$ – Georges Jul 17 at 14:30
  • $\begingroup$ maybe iterate over slots ? $\endgroup$ – Stephen Leger Aug 2 at 19:28

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.