1
$\begingroup$

I want to get "Use Count" Panel to attach to My Panel, what should I do? I know its Class is "PARTICLE_PT_render_collection_use_count", as shown below. Hope to get help, Many Thanks!

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ You can enable Developer Extras right click on the area and select View Source to copy the elements to your custom panel. Although that might be a nice exercise for you, I personally don't think having duplicated properties in one UI would make any sense... What's the reason to display the items twice? $\endgroup$
    – brockmann
    Sep 5 '20 at 13:49
  • $\begingroup$ Related or dupe: Copy existing property from e.g. Properties window to a custom panel? $\endgroup$
    – brockmann
    Sep 5 '20 at 13:53
  • $\begingroup$ @brockmann I'm writing an addon, related to particles, the image above is just an example. I want to get that table via my addon so that I can quickly access that part without particle switching Before posting, I tried your way, and your link is copy props, I have done it many times, but this time I want to copy the template_list, it seems much more complicated. row.template_list("UI_UL_list", "particle_instance_weights", part, "instance_weights", part, "active_instanceweight_index") it always gives an error $\endgroup$
    – Kim Quyen
    Sep 5 '20 at 14:59
  • 1
    $\begingroup$ What error exactly? Please add all relevant information to your actual question. Please read: blender.stackexchange.com/help/how-to-ask Consider that you can always change the layout to get "easy access" to the particle properties. I still think your idea can be confusing to users discovering the original uilist at some point. BTW: I don't get any error: i.stack.imgur.com/3qbcd.png $\endgroup$
    – brockmann
    Sep 5 '20 at 15:14
3
$\begingroup$

Reuse the code.

enter image description here

Can turn on developer extras and view the source of most of blenders UI.

An option would be to copy the code needed and add to a new Panel class.

A rub is the properties area often has context members unique to the region. For this case context.particle_system is defined in the properties area in particles tab.

Would instead need to be edited to context.object.particle_systems.active

Monkey patching and passing context object with extra members.

As an example have given new panel a method which refers to blenders UI class draw method. A namespace object is used to create a context with the extra members and passed to the draw method as a proxy context object.

Similarly with the poll method of the PARTICLE_PT_render_collection class.

Could do same for draw_header

Have, however, simply added the use count property to the draw method, it could however be used in a draw header method to replace "Hello World" title.

import bpy
from argparse import Namespace

from bl_ui.properties_particle import (
         PARTICLE_PT_render_collection_use_count,
         PARTICLE_PT_render_collection)
         

class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'

    @classmethod
    def poll(cls, context):
        ps = context.object.particle_systems.active
        c = Namespace(**context.copy())
        c.particle_system = ps
        return PARTICLE_PT_render_collection.poll(c) 
    # monkey       
    draw_part = PARTICLE_PT_render_collection_use_count.draw
    
    def draw(self, context):
        layout = self.layout
        ps = context.object.particle_systems.active
        if ps:
            layout.prop(ps.settings, "use_collection_count")
            c = Namespace(**context.copy())
            c.particle_system = ps
            self.draw_part(c)


def register():
    # fake a pin_id for 3d view.
    bpy.types.SpaceView3D.pin_id = None
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    del bpy.types.SpaceView3D.pin_id
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()

Note, this is only a proof of concept. Other things to consider when moving from properties area elsewhere is context.space.pin_id for when the panel is pinned. Have added another monkey patch to set pin in 3d view to none.

$\endgroup$

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.