1
$\begingroup$

im creating a popup menu with invoke_props_dialog and i want to add a already existing panel, kind of like layout.popover but i want the content directly in my menu.

import bpy


class Test_Popup(bpy.types.Operator):
    bl_idname = 'test.popup'
    bl_description = 'test'
    bl_label = 'test'

    bl_options = {'UNDO'}


    @classmethod
    def poll(cls, context): 
        return True


    def invoke(self, context, event):

        return context.window_manager.invoke_props_dialog(self, width=250)


    def execute(self, context):
        return {'FINISHED'}


    def draw(self, context):
        layout = self.layout

        #NOT this, like this but i want the content directly in the panel
        layout.popover('CYCLES_RENDER_PT_sampling')


def register():
    bpy.utils.register_class(Test_Popup)

register()
bpy.ops.test.popup('INVOKE_DEFAULT')
$\endgroup$
1
$\begingroup$

Import the classes, use their draw method.

If you enable developer tools in preferences you can right click in the UI and choose view source. Doing this for the cycles render panels you will see the classes are defined in ui.pyof the cycles addon. Can import them with

from cycles.ui import CYCLES_RENDER_PT_sampling, CYCLES_RENDER_PT_sampling_advanced

Note: some areas have their own context members. Eg PROPERTIES might use context.speaker for the data panel of a speaker object. This may lead to errors using the method outlined here.

enter image description here Test run in text editor

Test code.

import bpy
from cycles.ui import CYCLES_RENDER_PT_sampling, CYCLES_RENDER_PT_sampling_advanced

class TEST_OT_popup(bpy.types.Operator):
    bl_idname = 'test.popup'
    bl_description = 'test'
    bl_label = 'test'
    bl_options = {'UNDO'}

    @classmethod
    def poll(cls, context): 
        return CYCLES_RENDER_PT_sampling.poll(context)

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self, width=250)

    def execute(self, context):
        return {'FINISHED'}

    def draw(self, context):
        layout = self.layout

        CYCLES_RENDER_PT_sampling.draw(self, context)
        layout.label(text="Advanced")
        CYCLES_RENDER_PT_sampling_advanced.draw(self, context)

# for testing      
def register():
    bpy.utils.register_class(TEST_OT_popup)

register()
bpy.ops.test.popup('INVOKE_DEFAULT')
$\endgroup$
  • $\begingroup$ so i got it working but now i get an error ModuleNotFoundError: No module named 'ui' any ideas why this happens ? $\endgroup$ – Syler Mar 26 '19 at 14:07
  • $\begingroup$ Whoops, cycles.ui duly edited. $\endgroup$ – batFINGER Mar 26 '19 at 15:41

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.