Console Panel
Real-time logging and interactive command system
🚧
Under Construction
This tutorial is currently being developed and will be available soon.
The Console provides real-time logging and an interactive command system for debugging and controlling your simulation from the frontend.
Logging System
Log Levels
# Info logging
server.console.log("Processing started", source="DataProcessor")
# Warning logging
server.console.warn("Memory usage high", source="Monitor")
# Error logging
server.console.error("Failed to load file", source="FileIO")
# All messages appear in real-time in the Console panelLOG
Informational messages about normal operations
WARN
Warnings about potential issues
ERROR
Error messages for failures
Progress Tracking Example
import time
def process_data_with_logging(server, num_batches=5):
server.console.log(
f"Starting data processing: {num_batches} batches",
source="Processor"
)
for i in range(1, num_batches + 1):
time.sleep(1) # Simulate processing
progress = (i / num_batches) * 100
server.console.log(
f"Batch {i}/{num_batches} completed ({progress:.0f}%)",
source="Processor"
)
if i == 3:
server.console.warn(
"Batch 3 took longer than expected",
source="Processor"
)
server.console.log(
"✓ Data processing complete!",
source="Processor"
)
process_data_with_logging(server)Command System
Register custom Python functions as console commands that can be executed from the frontend.
Simple Command
# Register a simple command
def cmd_status():
"""Get system status"""
return f"System running. Objects: {len(scene.objects)}"
server.console.register_command(
"status",
cmd_status,
"Get current system status"
)
# Use in frontend: /statusCommand with Arguments
def cmd_add_cube(
name: str,
x: float = 0,
y: float = 0,
z: float = 0
):
"""Add a cube to the scene"""
cube = ObjectFactory.create_cube(
position=[x, y, z],
name=name
)
scene.add_object(cube)
return f"Added cube '{name}' at ({x}, {y}, {z})"
server.console.register_command(
"addcube",
cmd_add_cube,
"Add a cube: /addcube <name> [x] [y] [z]"
)
# Use in frontend: /addcube TestCube 5 0 0Async Command
import asyncio
async def cmd_long_task(duration: float = 2.0):
"""Simulate a long-running task"""
server.console.log(
"Task started",
source="AsyncTask"
)
await asyncio.sleep(duration)
server.console.log(
"Task complete",
source="AsyncTask"
)
return f"Completed after {duration} seconds"
server.console.register_command(
"longtask",
cmd_long_task,
"Run async task: /longtask [duration]"
)
# Use in frontend: /longtask 3Built-in Commands
- •
/help- Show all available commands - •
/clear- Clear all console messages - •
/list- Show recent messages with details - •
/echo <text>- Echo back the provided text
Complete Example
# Simulation control commands
simulation_state = {
"running": False,
"speed": 1.0,
"mode": "normal"
}
def cmd_sim_start():
"""Start the simulation"""
simulation_state["running"] = True
server.console.log("Simulation started", source="Sim")
return "Simulation is now running"
def cmd_sim_stop():
"""Stop the simulation"""
simulation_state["running"] = False
server.console.log("Simulation stopped", source="Sim")
return "Simulation has been stopped"
def cmd_sim_speed(speed: float = 1.0):
"""Set simulation speed"""
if speed <= 0:
return "Speed must be greater than 0"
simulation_state["speed"] = speed
server.console.log(f"Speed set to {speed}x", source="Sim")
return f"Speed set to {speed}x"
def cmd_sim_status():
"""Get simulation status"""
status = [
"Simulation Status:",
f" Running: {simulation_state['running']}",
f" Speed: {simulation_state['speed']}x",
f" Mode: {simulation_state['mode']}"
]
return "\n".join(status)
# Register all commands
server.console.register_command("sim_start", cmd_sim_start, "Start simulation")
server.console.register_command("sim_stop", cmd_sim_stop, "Stop simulation")
server.console.register_command("sim_speed", cmd_sim_speed, "Set speed")
server.console.register_command("sim_status", cmd_sim_status, "Get status")
# Use in frontend:
# /sim_status
# /sim_start
# /sim_speed 2.5
# /sim_stop