4
$\begingroup$

I'm trying to watch the coordinates of an object as it moves during a simulation, and to this end I want to add a new Panel to the Rigid Body Panel, like this:

class PHYSICS_PT_rigid_body_worldmatrix(PHYSICS_PT_rigidbody_panel, Panel):
    bl_label = "Rigid Body Coordinates"
    bl_default_closed = True

    @classmethod
    def poll(cls, context):
        obj = context.object
        return (obj and obj.rigid_body and
                obj.rigid_body.type == 'ACTIVE' and
                (not context.scene.render.use_game_engine))

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

        ob = context.object
        rbo = ob.rigid_body

        row = layout.row()                                                                     
        row.prop(ob, "matrix_world", index=12, text="X")
        row.prop(ob, "matrix_world", index=13, text="Y")
        row.prop(ob, "matrix_world", index=14, text="Z")

This works if I put the code into startup/bl_ui/properties_physics_rigidbody.py, but not if I put it into a script file and try to load it. It can't find PHYSICS_PT_rigidbody_panel, even if I add this line:

from bpy.types import PHYSICS_PT_rigidbody_panel, Panel

Any ideas how to access class PHYSICS_PT_rigidbody_panel?

Also, when I run it by editing the system files, it still has some issues. It doesn't update in real time during the simulation; I have to move the mouse into the properties window. I'd also like to see the numbers displayed in scientific notation if they are extremely small.

Any suggestions?

$\endgroup$

migrated from stackoverflow.com May 9 '14 at 14:54

This question came from our site for professional and enthusiast programmers.

3
$\begingroup$

The PHYSICS_PT_rigidbody_panel class is only present in the properties_physics_rigidbody.py script - it is simply a base class to provide common properties to the other panels in that script.

The step you are missing is bpy.utils.register_module(), with the properties you need for the panel you get the following -

import bpy

class PHYSICS_PT_rigid_body_worldmatrix(bpy.types.Panel):
    bl_label = "Rigid Body Coordinates"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "physics"
    bl_default_closed = True

    @classmethod
    def poll(cls, context):
        obj = context.object
        return (obj and obj.rigid_body and
                obj.rigid_body.type == 'ACTIVE' and
                (not context.scene.render.use_game_engine))

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

        ob = context.object
        rbo = ob.rigid_body

        row = layout.row()                                                                     
        row.prop(ob, "matrix_world", index=12, text="X")
        row.prop(ob, "matrix_world", index=13, text="Y")
        row.prop(ob, "matrix_world", index=14, text="Z")

if __name__ == "__main__":
    bpy.utils.register_module(__name__)
$\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.