0
$\begingroup$

I've already added the buttons, but strangely they appear on the left and right.

Here is my python script:

import os
import bpy

bl_info = {
   "name": "Name",
   "author": "Name",
   "version": (1, 0, 0),
   "blender": (3, 3, 1),
   "location": "Outliner",
   "description": "Adds an example button to the outliner header.",
   "wiki_url": "",
   "category": "Outliner"}

class My_Button(bpy.types.Panel):
  bl_idname = "example.something"
  bl_label = "Test"
  bl_description = "This operator does something"
  bl_options = {"REGISTER"}


def draw(self, context):

   self.layout.operator(
       operator='import_scene.gltf',
       icon='MESH_CUBE',
       text='Import GLB'
 )      
  self.layout.operator(
     operator='export_scene.gltf',
     icon='MESH_CUBE',
     text='Export GLB'
  )


classes = (
  My_Button,
  )

def register():    
   bpy.types.TOPBAR_HT_upper_bar.append(draw)

def unregister():
   bpy.types.TOPBAR_HT_upper_bar.remove(draw)


if __name__ == "__main__":
   register()

Image

$\endgroup$

1 Answer 1

0
$\begingroup$

Check context.region.alignment:

import os
import bpy

def draw(self, context):
   if context.region.alignment == 'LEFT':
       self.layout.operator(
           operator='import_scene.gltf',
           icon='MESH_CUBE',
           text='Import GLB'
       )      
       self.layout.operator(
         operator='export_scene.gltf',
         icon='MESH_CUBE',
         text='Export GLB'
       )

def register():    
   bpy.types.TOPBAR_HT_upper_bar.append(draw)

def unregister():
   bpy.types.TOPBAR_HT_upper_bar.remove(draw)

if __name__ == "__main__":
   register()

This can be easily found, if you enable developer extras and check source of the panel:

enter image description here

$\endgroup$
3
  • $\begingroup$ Ok, thanks, that works. $\endgroup$ Oct 19, 2022 at 7:33
  • $\begingroup$ But what I don't understand is, how can you run a script with a click on the button? For example: I want to export glb to a specific location with one click. How do I find out what to write there? Unfortunately I haven't programming knowledge, I'm just a 3D Artist $\endgroup$ Oct 19, 2022 at 7:41
  • $\begingroup$ If you have another question, please post it as a separate question. $\endgroup$
    – Crantisz
    Oct 19, 2022 at 9:54

You must log in to answer this question.

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