Skip to content

Commit

Permalink
Fix #88 Python Console buttons
Browse files Browse the repository at this point in the history
- New way in Blender to show buttons in console header
  using bpy.types.CONSOLE_HT_header.append().
  Found an example in the Icon Viewer add-on.
  Seems to work on Blender 2.93 and 3.3.
  • Loading branch information
tkeskita committed Feb 19, 2023
1 parent 600a111 commit 19f5fd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,10 @@ def register():
bpy.types.Scene.bvtknodes_settings = bpy.props.PointerProperty(
type=BVTKNodes_Settings
)

bpy.types.CONSOLE_HT_header.append(b_inspect.draw_console_header)

def unregister():
bpy.types.CONSOLE_HT_header.remove(b_inspect.draw_console_header)
nodeitems_utils.unregister_node_categories("VTK_NODES")
for c in reversed(sorted(core.CLASSES.keys())):
bpy.utils.unregister_class(core.CLASSES[c])
Expand Down
54 changes: 24 additions & 30 deletions b_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,31 @@ def draw(self, context):


# -----------------------------------------------------------------------------
# Add button to console header
# Function to add buttons to Python Console header
# -----------------------------------------------------------------------------
class BVTK_HT_Console(bpy.types.Header):
"""BVTK Header Buttons in Python Console"""

bl_space_type = "CONSOLE"

def draw(self, context):
node_tree = None
for area in context.screen.areas:
if area.type == "NODE_EDITOR":
for space in area.spaces:
if space.type == "NODE_EDITOR":
node_tree = space.node_tree.name

if node_tree:
self.layout.separator()
row = self.layout.row(align=True)
o = row.operator("console.insert", text="Get Node")
o.text = "x=bpy.data.node_groups['" + node_tree + "'].nodes.active"
o = row.operator("console.insert", text="Get VTK Object")
o.text = (
"x=bpy.data.node_groups['" + node_tree + "'].nodes.active.get_vtk_obj()"
)
o = row.operator("console.insert", text="Get Node Output")
o.text = (
"x=bpy.data.node_groups['"
+ node_tree
+ "'].nodes.active.get_vtk_obj().GetOutput()"
)
def draw_console_header(self, context):
node_tree = None
for area in context.screen.areas:
if area.type == "NODE_EDITOR":
for space in area.spaces:
if space.type == "NODE_EDITOR":
node_tree = space.node_tree.name

if node_tree:
self.layout.separator()
row = self.layout.row(align=True)
o = row.operator("console.insert", text="Get Node")
o.text = "x=bpy.data.node_groups['" + node_tree + "'].nodes.active"
o = row.operator("console.insert", text="Get VTK Object")
o.text = (
"x=bpy.data.node_groups['" + node_tree + "'].nodes.active.get_vtk_obj()"
)
o = row.operator("console.insert", text="Get Node Output")
o.text = (
"x=bpy.data.node_groups['"
+ node_tree
+ "'].nodes.active.get_vtk_obj().GetOutput()"
)


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -165,6 +160,5 @@ def execute(self, context):

# Register classes
add_ui_class(BVTK_PT_Inspect)
add_ui_class(BVTK_HT_Console)
add_ui_class(BVTK_OT_SetTextEditor)
add_ui_class(BVTK_OT_OpenWebsite)

0 comments on commit 19f5fd3

Please sign in to comment.