I want to modify the sculpt mode header, do I really have to copy everything from space_view3d.py?

I want to change the pretty barren header for sculpt mode. Add some buttons, dropdowns, etc.

It seems the only way to properly do that is to go into space_view3d.py copy the code for the ENTIRE VIEW3D_HT_header class, paste it into my addon and register it over there again. Then make the changes to the area of the code responsible for the sculpt header.

Feels a little bit overkill, the thing is 500 lines and I just want to add/change maybe 10, but I can’t see any other way to make those changes to the sculpting header. The way I’ve been doing it up till now is to append the stuff I wanted to the end of the View / Sculpt / Mask / Face Sets menu. This approach worked when the whole sculpt header was empty, but now thare are those Color Attribute and Masking popovers, and they get in the way. There’s no way to prepend on their other side, since there are no menus there, just panels. It’s also a messy way and if I collapse the menus into a “hamburger” [≡], then the appended stuff also gets collapsed and disappears.

So… THE QUESTION(s): is there maybe another way? An easier way? Is overwriting this pretty important looking class a bad idea? Does Blender really care where the code for that class is located and where it’s registered?

As a side note, I don’t get why Blender has to have everything for the header stuffed into one class. It’s a giant jumble of conditions in there: if grease_pencil elif texture_paint elif vertex_paint elif whatever. Everything is on top of everything else. I feel it would be much nicer and more readable if every header was separated into it’s own thing, but maybe there’s some technical reason :man_shrugging:

I’m 99% certain you can unregister VIEW3D_HT_header, add your changes, and then re-register- no copy and paste needed. I just can’t remember exactly how to do it. I’m sure someone who does will be along any second, though :slight_smile:

1 Like

You don’t need to unregister anything if your only intention is to add to them, and not reorder or remove stuff aswell. When registering script just use

bpy.types.VIEW3D_MT_editor_menus.append(your_menu_definition)

And in menu definition make a poll that checks that it’s sculpt mode, so you only add there

1 Like

Oh, I didn’t even think about unregistering the old ones! Blender did make some warnings in the console, but they were like this already exists, lemme unregister that for you, dumbass :stuck_out_tongue:

Tip for anyone trying to unregister the class: the path is not bl_ui.space_view3d.VIEW3D_HT_header, it’s bpy.types.VIEW3D_HT_header. Took me a while to figure it out…

I also did find an old thread about this, and another method is to overwrite just the draw method of the class. Seems cleaner, but at the end of the day I’m still copying a lot of code that I’ll have re-copy for every Blender release because grease pencil might have added a button to their header.

@nickberckley my intention is definitely to reorder and remove stuff. I was using append before but it just wasn’t enough for what I wanted to do.

1 Like