# /// script # requires-python = ">=3.12" # # [tool.orcaslicer.plugin] # name = "Dock Panel Demo" # description = "Opens a dockable panel beside the 3D view that lists the objects on the plate." # author = "OrcaSlicer" # version = "0.0.1" # /// """Dock Panel Demo -- orca.host.ui.create_dock_panel(). Run it from the Plugins dialog. It opens an HTML panel docked on the right of the 3D view, in the same dock area as the sidebar. Drag its caption to dock it on another side (or float it, where the platform allows), hide it from the page and run the plugin again to bring it back, or close it with its close button or from the page. page --orca.postMessage({command: 'refresh'})--> plugin.on_message() page --orca.postMessage({command: 'hide'})--> plugin.on_message() -> panel.hide() page --orca.close()--> panel closes, plugin.on_close() plugin --panel.post({command: 'objects', ...})--> page (orca.onMessage) """ import orca PAGE = """
Docked beside the 3D view. Drag the caption to move it.
| Name | Parts | Copies |
|---|
Waiting for the plugin...
""" def plate_objects(): try: model = orca.host.model() except RuntimeError as error: return {"command": "objects", "error": str(error)} return { "command": "objects", "objects": [ {"name": obj.name or "(unnamed)", "volumes": obj.volume_count(), "instances": obj.instance_count()} for obj in model.objects() ], } class DockPanelDemo(orca.script.ScriptPluginCapabilityBase): panel = None def get_name(self): return "Dock Panel Demo" def execute(self): # The capability instance lives as long as the plugin, so a second run finds the open panel. if self.panel is not None and self.panel.is_open(): self.panel.show() return orca.ExecutionResult.success("Dock Panel Demo is already open.") self.panel = orca.host.ui.create_dock_panel( html=PAGE, title="Dock Panel Demo", width=320, height=480, on_message=self.on_message, on_close=self.on_close, dock="right", ) return orca.ExecutionResult.success("Dock Panel Demo opened.") # Called on the UI thread when the page posts. def on_message(self, message): command = (message or {}).get("command") if command == "refresh": self.panel.post(plate_objects()) elif command == "hide": self.panel.hide() def on_close(self): self.panel = None @orca.plugin class DockPanelDemoPlugin(orca.base): def register_capabilities(self): orca.register_capability(DockPanelDemo)