Hi, As I'm playing with creating my own panel, I'm trying to understand how buttons on the panels actually work. In the video you added the operator to the layout, that then creates a button on the layout. But what if I want to create a custom function and assign this to the button. Do I need to create a custom operator and then add this custom operator to the layout? I did not go through the next chapter yet, BTW.
The other way that seems to create buttons on the interface is to add prop to the layout. In the video we added: row.prop(active_object,'hide_viewport',text='Viewport'). When we actually change the visibility, in the info panel, the log is:
bpy.context.object.hide_viewport = False
So, by logic I would guess that, if I want to change the shading type on the 3D View, changing the shading type gives me on the logs:
bpy.context.space_data.shading.type = 'SOLID'
So, adding the following to the code:
scene_data = context.space_data
column.prop(scene_data,'shading.type')
Gives me an error: rna_uiItemR: property not found: SpaceView3D.shading.type.
So what defines what is a property and what is not?
What I'm trying to do (either through a custom function/operator or properties) is to add a button to change the shading type on the 3D view).
BTW, If I add this code:
scene_data = context.space_data
shading_type = scene_data.shading.type
column.label(text=shading_type)
It gives me the shading type on the label correctly.
Thanks,
Mauro
I could be wrong, but I believe you need to shift your object call like so:
column = prop(scene_data.shading, 'type')
You could also just do:
Scene_data = context.space_data.shading
column = prop(Scene_data, 'type')
Hi dillenbata3, you are not wrong. That worked well! With that the four buttons show exactly like the Blender default toolbar. I'm still wondering how I can create a button to toggle the Wireframe shading type only without having the other modes. And if this can be done using a custom function instead of a prop
Yeah, I don't know anything about custom functions, but you can do an operator. I'm at work right now so don't have access to my computer. To help guide you, you can go to preferences->keymap. Then in the search area click key bind and in the search field type "shift z" without the quotes. Under 3d view you should see the key map for shift+z. Expand that and under that is the operator and any properties passed to it for toggling wireframe shading mode.
So found out what you want:
operator("view3d.toggle_shading", text="Wireframe")
hi dillenbata3, that's great. And an interesting way to find the operators by looking in the keymaps. Thanks!