Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/tree_clipper_addon/src/tree_clipper_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import bpy

from .export_active import SCENE_OT_Tree_Clipper_Export_Active
from .operators_export import (
SCENE_OT_Tree_Clipper_Export_Cache,
SCENE_OT_Tree_Clipper_Export_Modal,
Expand Down Expand Up @@ -46,10 +47,22 @@
SCENE_OT_Tree_Clipper_Import_File_Prepare,
SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare,
SCENE_PT_Tree_Clipper_Panel,
SCENE_OT_Tree_Clipper_Export_Active,
TreeClipperPreferences,
]


def draw_export_active(self, _context):
self.layout.operator(SCENE_OT_Tree_Clipper_Export_Active.bl_idname)


def draw_import(self, _context):
self.layout.operator(
SCENE_OT_Tree_Clipper_Import_Clipboard_Prepare.bl_idname,
text="Import Tree Clipper",
)


def register() -> None:
print("Registering Tree Clipper")
for cls in classes:
Expand All @@ -58,9 +71,13 @@ def register() -> None:
bpy.types.Scene.tree_clipper_external_import_items = bpy.props.PointerProperty( # ty: ignore[unresolved-attribute]
type=Tree_Clipper_External_Import_Items
)
bpy.types.NODE_MT_context_menu.append(draw_import)
bpy.types.NODE_MT_context_menu.append(draw_export_active)


def unregister() -> None:
bpy.types.NODE_MT_context_menu.remove(draw_export_active)
bpy.types.NODE_MT_context_menu.remove(draw_import)
del bpy.types.Scene.tree_clipper_external_import_items # ty: ignore[unresolved-attribute]
for cls in reversed(classes):
bpy.utils.unregister_class(cls)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import bpy


class SCENE_OT_Tree_Clipper_Export_Active(bpy.types.Operator):
bl_label = "Export Tree Clipper"
bl_idname = "scene.tree_clipper_export_active"
bl_description = (
"Export the selected and active node group as a Tree Clipper string."
)

@classmethod
def poll(cls, context: bpy.types.Context) -> bool:
node = context.active_node
return (
node is not None
and isinstance(
node,
bpy.types.CompositorNodeGroup
| bpy.types.GeometryNodeGroup
| bpy.types.ShaderNodeGroup
| bpy.types.TextureNodeGroup,
)
and node.node_tree is not None
)

def execute(self, context: bpy.types.Context) -> None: # ty:ignore[invalid-method-override]
assert isinstance(context.space_data, bpy.types.SpaceNodeEditor)
assert context.active_node is not None
assert context.active_node.node_tree is not None # ty:ignore[unresolved-attribute]

bpy.ops.scene.tree_clipper_export_prepare( # ty:ignore[unresolved-attribute]
"INVOKE_DEFAULT",
is_material=False,
name=context.active_node.node_tree.name, # ty:ignore[unresolved-attribute]
)
return {"FINISHED"} # ty:ignore[invalid-return-type]
Loading